Created
April 9, 2015 21:40
-
-
Save sgraessle/a97a87aa1cfe58ac909e to your computer and use it in GitHub Desktop.
Dumb 5-point gradient OpenGL shader.
This file contains 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
void main() { | |
// Set the output color to red. | |
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); | |
vec2 texCoord = cc_FragTexCoord1; | |
float l0 = 0.2, l1 = 0.1, l2 = 0.0, l3 = 0.1, l4 = 0.2; | |
float y0 = 1.0, y1 = 0.85, y2 = 0.5, y3 = 0.15, y4 = 0.0; | |
float level = 0.2; | |
if (texCoord.y > y1) { | |
level = (texCoord.y - y1) * (l0 - l1)/(y0 - y1) + l1; | |
} else if (texCoord.y > y2) { | |
level = (texCoord.y - y2) * (l1 - l2)/(y1 - y2) + l2; | |
} else if (texCoord.y > y3) { | |
level = (texCoord.y - y3) * (l2 - l3)/(y2 - y3) + l3; | |
} else if (texCoord.y > y4) { | |
level = (texCoord.y - y4) * (l3 - l4)/(y3 - y4) + l4; | |
} | |
gl_FragColor = vec4(level, level, level, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment