Last active
March 30, 2017 18:07
-
-
Save JBlackCat/2f9e4604e9ccd9ee7853ef91fda19c30 to your computer and use it in GitHub Desktop.
Fragment Shader start template from https://www.shadertoy.com/view/Md23DV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define PI 3.14159265359 | |
| //Anti-aliased coordinate system grid | |
| float coordinateGrid(vec2 coords) { | |
| vec3 axesColor = vec3(0.0, 0.0, 1.0); | |
| float axesThickness = 0.015; | |
| vec3 gridColor = vec3(0.5); | |
| float gridThickness = 0.008; | |
| float retrn = 0.0; // What is this returning? | |
| //Draw grid lines | |
| const float tickWidth = 0.1; | |
| for(float i=-2.0; i<2.0; i+=tickWidth) { | |
| // "i" is the line coordinate. | |
| retrn += 1.0 - smoothstep(0.0, gridThickness, abs(coords.x - i)); | |
| retrn += 1.0 - smoothstep(0.0, gridThickness, abs(coords.y - i)); | |
| } | |
| //Draw the axes | |
| retrn += 1.0 - smoothstep(0.001, 0.015, abs(coords.x)); | |
| retrn += 1.0 - smoothstep(0.001, 0.015, abs(coords.y)); | |
| return retrn; | |
| } | |
| //returns 1.0 if inside circle | |
| float circle(vec2 coords, vec2 center, float radius) { | |
| float antiAliasTolerance = 0.005; | |
| return 1.0 - smoothstep(radius - antiAliasTolerance, radius + antiAliasTolerance, length(coords - center)); | |
| } | |
| //returns 1.0 if inside rectangle | |
| float rectangle(vec2 r, vec2 topLeft, vec2 bottomRight) { | |
| float ret; | |
| float d = 0.005; | |
| ret = smoothstep(topLeft.x-d, topLeft.x+d, r.x); | |
| ret *= smoothstep(topLeft.y-d, topLeft.y+d, r.y); | |
| ret *= 1.0 - smoothstep(bottomRight.y-d, bottomRight.y+d, r.y); | |
| ret *= 1.0 - smoothstep(bottomRight.x-d, bottomRight.x+d, r.x); | |
| return ret; | |
| } | |
| void main(){ | |
| vec2 p = vec2(gl_FragCoord.xy / resolution.xy); | |
| vec2 r = (vec2(gl_FragCoord.xy - 0.5*resolution.xy)*2.0)/resolution.y; | |
| float xMax = resolution.x / resolution.y; | |
| vec3 bgCol = vec3(1.0); | |
| vec3 col1 = vec3(0.216, 0.471, 0.698); //blue | |
| vec3 col2 = vec3(1.00, 0.329, 0.298); //yellow | |
| vec3 col3 = vec3(0.867, 0.910, 0.247); //red | |
| vec3 retrn = bgCol; | |
| // -------------------------------- | |
| // -------------------------------- | |
| // -------------------------------- | |
| // -------------------------------- | |
| vec3 pixel = retrn; | |
| gl_FragColor = vec4(pixel, 1.0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: clean up and needs some polishing.