Created
September 18, 2014 15:07
-
-
Save AtkinsSJ/b43ac377696a80a73c91 to your computer and use it in GitHub Desktop.
Problematic shader code
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
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
varying vec4 v_color; | |
varying vec2 v_texCoords; | |
uniform sampler2D u_texture; | |
uniform vec3 u_playerPosition; | |
uniform float u_playerLightRangeScaled; | |
void main() | |
{ | |
vec4 tex = v_color * texture2D(u_texture, v_texCoords); | |
float texLight = (tex.r + tex.g + tex.b) / 3.0; | |
float d = distance(gl_FragCoord, u_playerPosition.xy); | |
// Make things dark and blueish | |
gl_FragColor = vec4(texLight/5.0, texLight/5.0, texLight/3.0, tex.a); | |
// If we're within range of the player, light up a bit, based on distance | |
if (d < u_playerLightRangeScaled) { | |
float fadeAmount = d / u_playerLightRangeScaled; | |
gl_FragColor = (tex * (1.0 - fadeAmount)) + (gl_FragColor * fadeAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Argh! It was because I used
gl_FragCoord
rather thangl_FragCoord.xy
on line 17. Why did this not throw an error when I first wrote it? Argh.