diff options
| author | Ray <raysan5@gmail.com> | 2016-10-11 00:39:07 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2016-10-11 00:39:07 +0200 |
| commit | 97e3277d58060df96cd002b1377a51ca4adcbb9e (patch) | |
| tree | f41675cee02117049edb9c0628865be1b343e1cc | |
| parent | 648676f46b01327f0fbd6f017292a3159ea9ab2f (diff) | |
| download | raylib-97e3277d58060df96cd002b1377a51ca4adcbb9e.tar.gz raylib-97e3277d58060df96cd002b1377a51ca4adcbb9e.zip | |
Updated standard shader
Corrects weird artifacts on web
| -rw-r--r-- | examples/resources/shaders/glsl100/standard.fs | 17 | ||||
| -rw-r--r-- | examples/resources/shaders/glsl330/standard.fs | 8 | ||||
| -rw-r--r-- | src/shader_standard.h | 10 |
3 files changed, 13 insertions, 22 deletions
diff --git a/examples/resources/shaders/glsl100/standard.fs b/examples/resources/shaders/glsl100/standard.fs index 6ce2a186..fe604e2a 100644 --- a/examples/resources/shaders/glsl100/standard.fs +++ b/examples/resources/shaders/glsl100/standard.fs @@ -38,7 +38,6 @@ uniform Light lights[maxLights]; vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s) { -/* vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1.0)); vec3 surfaceToLight = l.position - surfacePos; @@ -51,17 +50,14 @@ vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(-l.direction + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (diff*l.diffuse.rgb + spec*colSpecular.rgb); -*/ - return vec3(0.5); } vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s) { -/* vec3 lightDir = normalize(-l.direction); // Diffuse shading @@ -72,18 +68,15 @@ vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } // Combine results return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb); -*/ - return vec3(0.5); } vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s) { -/* vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1)); vec3 lightToSurface = normalize(surfacePos - l.position); vec3 lightDir = normalize(-l.direction); @@ -108,12 +101,10 @@ vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s) if (diffAttenuation > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb)); -*/ - return vec3(0.5); } void main() @@ -140,7 +131,7 @@ void main() // Calculate specular texture color fetching or set to maximum specular value by default float spec = 1.0; - if (useSpecular == 1) spec *= normalize(texture2D(texture2, fragTexCoord).r); + if (useSpecular == 1) spec = texture2D(texture2, fragTexCoord).r; for (int i = 0; i < maxLights; i++) { diff --git a/examples/resources/shaders/glsl330/standard.fs b/examples/resources/shaders/glsl330/standard.fs index 14497839..0d461484 100644 --- a/examples/resources/shaders/glsl330/standard.fs +++ b/examples/resources/shaders/glsl330/standard.fs @@ -50,7 +50,7 @@ vec3 ComputeLightPoint(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(-l.direction + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (diff*l.diffuse.rgb + spec*colSpecular.rgb); @@ -68,7 +68,7 @@ vec3 ComputeLightDirectional(Light l, vec3 n, vec3 v, float s) if (diff > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } // Combine results @@ -101,7 +101,7 @@ vec3 ComputeLightSpot(Light l, vec3 n, vec3 v, float s) if (diffAttenuation > 0.0) { vec3 h = normalize(lightDir + v); - spec = pow(dot(n, h), 3.0 + glossiness)*s; + spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s; } return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb)); @@ -131,7 +131,7 @@ void main() // Calculate specular texture color fetching or set to maximum specular value by default float spec = 1.0; - if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r); + if (useSpecular == 1) spec = texture(texture2, fragTexCoord).r; for (int i = 0; i < maxLights; i++) { diff --git a/src/shader_standard.h b/src/shader_standard.h index deae7fe1..995c62ea 100644 --- a/src/shader_standard.h +++ b/src/shader_standard.h @@ -90,7 +90,7 @@ static const char fStandardShaderStr[] = " if (diff > 0.0)\n" " {\n" " vec3 h = normalize(-l.direction + v);\n" -" spec = pow(dot(n, h), 3.0 + glossiness)*s;\n" +" spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;\n" " }\n" " return (diff*l.diffuse.rgb + spec*colSpecular.rgb);\n" "}\n" @@ -103,7 +103,7 @@ static const char fStandardShaderStr[] = " if (diff > 0.0)\n" " {\n" " vec3 h = normalize(lightDir + v);\n" -" spec = pow(dot(n, h), 3.0 + glossiness)*s;\n" +" spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;\n" " }\n" " return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);\n" "}\n" @@ -124,7 +124,7 @@ static const char fStandardShaderStr[] = " if (diffAttenuation > 0.0)\n" " {\n" " vec3 h = normalize(lightDir + v);\n" -" spec = pow(dot(n, h), 3.0 + glossiness)*s;\n" +" spec = pow(abs(dot(n, h)), 3.0 + glossiness)*s;\n" " }\n" " return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));\n" "}\n" @@ -152,9 +152,9 @@ static const char fStandardShaderStr[] = " }\n" " float spec = 1.0;\n" #if defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_21) -" if (useSpecular == 1) spec *= normalize(texture2D(texture2, fragTexCoord).r);\n" +" if (useSpecular == 1) spec = texture2D(texture2, fragTexCoord).r;\n" #elif defined(GRAPHICS_API_OPENGL_33) -" if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r);\n" +" if (useSpecular == 1) spec = texture(texture2, fragTexCoord).r;\n" #endif " for (int i = 0; i < maxLights; i++)\n" " {\n" |
