From 3132b761d0b6525313735e45ad2728b2cd94752c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20de=20l=27Hamaide?= Date: Thu, 23 Jan 2014 17:22:26 +0100 Subject: [PATCH] Improve runway reflection shader by Emilian H. --- Shaders/runway-gbuffer.frag | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Shaders/runway-gbuffer.frag b/Shaders/runway-gbuffer.frag index 42def8f40..2906ad3a0 100644 --- a/Shaders/runway-gbuffer.frag +++ b/Shaders/runway-gbuffer.frag @@ -50,16 +50,17 @@ void main (void) if (normalmap_dds > 0) N = -N; - float nFactor = 1.0 - N.z; - float lightness = dot(texel.rgb, vec3( 0.3, 0.59, 0.11 )); + float nFactor = 1.0 - N.z; + float lightness = dot(texel.rgb, vec3( 0.3, 0.59, 0.11 )); + // calculate the specular light float refl_correction = spec_adjust * 2.5 - 1.0; float shininess = max (0.35, refl_correction) * nmap.a * nFactor; - float specular = dot(vec3(1.0) * lightness , vec3( 0.3, 0.59, 0.11 )) * nFactor; + float specular = dot(vec3(1.0) * lightness , vec3( 0.3, 0.59, 0.11 )) * nFactor; - vec4 color = vec4(1.0); + vec4 color = vec4(1.0); color.a = texel.a * alpha; color = clamp(color, 0.0, 1.0); @@ -67,7 +68,7 @@ void main (void) vec3 viewVec = normalize(vViewVec); // Map a rainbowish color - float v = abs(dot(viewVec, normalize(VNormal))); + float v = abs(dot(viewVec, normalize(VNormal))); vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0)); // Map a fresnel effect @@ -81,9 +82,9 @@ void main (void) float transparency_offset = clamp(refl_correction, -1.0, 1.0); float reflFactor = 0.0; - float MixFactor = specNoise.r * specNoise.g * specNoise.b * 350.0; + float MixFactor = specNoise.r * specNoise.g * specNoise.b * 350.0; - MixFactor = 0.75 * smoothstep(0.0, 1.0, MixFactor); + MixFactor = 0.75 * smoothstep(0.0, 1.0, MixFactor); reflFactor = max(map.a * (texel.r + texel.g), 1.0 - MixFactor) * nFactor + transparency_offset ; reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor); @@ -98,12 +99,14 @@ void main (void) vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v); vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness); - vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0) * nFactor; - - vec4 mixedcolor = mix(texel, raincolor * (1.0 - refl_correction * (1.0 - lightness)), reflFactor); + vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0) * nFactor; + vec4 mixedcolor = mix(texel, raincolor * (1.0 - refl_correction * (1.0 - lightness)), reflFactor); // the final reflection - vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction * nFactor, color.a); + vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction * nFactor, color.a); + float doWater = step(0.1, reflFactor); + int matIndex = int(doWater) * 253 + 1; + shininess += doWater * reflFactor * 240.0; - encode_gbuffer(N, fragColor.rgb, 1, specular, shininess, emission, gl_FragCoord.z); -} \ No newline at end of file + encode_gbuffer(N, fragColor.rgb, matIndex, specular, shininess, emission, gl_FragCoord.z); +}