1
0
Fork 0

Improve runway reflection shader by Emilian H.

This commit is contained in:
Clément de l'Hamaide 2014-01-23 17:22:26 +01:00
parent aae72d7266
commit 3132b761d0

View file

@ -50,16 +50,17 @@ void main (void)
if (normalmap_dds > 0) if (normalmap_dds > 0)
N = -N; N = -N;
float nFactor = 1.0 - N.z; float nFactor = 1.0 - N.z;
float lightness = dot(texel.rgb, vec3( 0.3, 0.59, 0.11 )); float lightness = dot(texel.rgb, vec3( 0.3, 0.59, 0.11 ));
// calculate the specular light // calculate the specular light
float refl_correction = spec_adjust * 2.5 - 1.0; float refl_correction = spec_adjust * 2.5 - 1.0;
float shininess = max (0.35, refl_correction) * nmap.a * nFactor; 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.a = texel.a * alpha;
color = clamp(color, 0.0, 1.0); color = clamp(color, 0.0, 1.0);
@ -67,7 +68,7 @@ void main (void)
vec3 viewVec = normalize(vViewVec); vec3 viewVec = normalize(vViewVec);
// Map a rainbowish color // 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)); vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0));
// Map a fresnel effect // Map a fresnel effect
@ -81,9 +82,9 @@ void main (void)
float transparency_offset = clamp(refl_correction, -1.0, 1.0); float transparency_offset = clamp(refl_correction, -1.0, 1.0);
float reflFactor = 0.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 = max(map.a * (texel.r + texel.g), 1.0 - MixFactor) * nFactor + transparency_offset ;
reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor); reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor);
@ -98,12 +99,14 @@ void main (void)
vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v); vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness); vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0) * nFactor; vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0) * nFactor;
vec4 mixedcolor = mix(texel, raincolor * (1.0 - refl_correction * (1.0 - lightness)), reflFactor);
vec4 mixedcolor = mix(texel, raincolor * (1.0 - refl_correction * (1.0 - lightness)), reflFactor);
// the final reflection // 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); encode_gbuffer(N, fragColor.rgb, matIndex, specular, shininess, emission, gl_FragCoord.z);
} }