Created
September 18, 2014 15:07
-
-
Save AtkinsSJ/b43ac377696a80a73c91 to your computer and use it in GitHub Desktop.
Problematic shader code
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
#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); | |
} | |
} |
Argh! It was because I used gl_FragCoord
rather than gl_FragCoord.xy
on line 17. Why did this not throw an error when I first wrote it? Argh.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my desktop, this works fine, but on my tablet which uses OpenGL ES 3.0, it doesn't.
The error I'm getting is:
No matching overload for function 'distance' found
but the docs say thatdistance()
is compatible with all versions. I don't think it should be using thegenDType
version, asu_playerPosition
is avec3
.Any ideas?