3 // © Emilian Huminiuc and Vivian Meazza 2011
\r
8 varying vec3 VNormal;
\r
9 varying vec3 VTangent;
\r
10 varying vec3 VBinormal;
\r
11 varying vec3 vViewVec;
\r
12 varying vec3 reflVec;
\r
14 varying vec4 Diffuse;
\r
15 varying float alpha;
\r
16 //varying float fogCoord;
\r
18 uniform samplerCube Environment;
\r
19 uniform sampler2D Rainbow;
\r
20 uniform sampler2D BaseTex;
\r
21 uniform sampler2D Fresnel;
\r
22 uniform sampler2D Map;
\r
23 uniform sampler2D NormalTex;
\r
24 uniform sampler3D Noise;
\r
26 uniform float spec_adjust;
\r
27 uniform float rainbowiness;
\r
28 uniform float fresneliness;
\r
29 uniform float noisiness;
\r
30 uniform float ambient_correction;
\r
31 uniform float normalmap_dds;
\r
33 void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth);
\r
38 vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
\r
39 vec4 nmap = texture2D(NormalTex, gl_TexCoord[0].st * 8.0);
\r
40 vec4 map = texture2D(Map, gl_TexCoord[0].st * 8.0);
\r
41 vec4 specNoise = texture3D(Noise, rawpos.xyz * 0.0045);
\r
42 vec4 noisevec = texture3D(Noise, rawpos.xyz);
\r
43 vec3 ambient = vec3(0.85,0.85,0.9);//placeholder for sun ambient
\r
45 float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb,
\r
46 vec3( 0.3, 0.59, 0.11 ) );
\r
48 N = nmap.rgb * 2.0 - 1.0;
\r
49 N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
\r
50 if (normalmap_dds > 0)
\r
53 float nFactor = 1.0 - N.z;
\r
54 float lightness = dot(texel.rgb, vec3( 0.3, 0.59, 0.11 ));
\r
55 // calculate the specular light
\r
56 float refl_correction = spec_adjust * 2.5 - 1.0;
\r
57 float shininess = max (0.35, refl_correction) * nmap.a * nFactor;
\r
60 float specular = dot(vec3(1.0) * lightness , vec3( 0.3, 0.59, 0.11 )) * nFactor;
\r
62 vec4 color = vec4(1.0);
\r
64 color.a = texel.a * alpha;
\r
65 color = clamp(color, 0.0, 1.0);
\r
67 vec3 viewVec = normalize(vViewVec);
\r
69 // Map a rainbowish color
\r
70 float v = abs(dot(viewVec, normalize(VNormal)));
\r
71 vec4 rainbow = texture2D(Rainbow, vec2(v, 0.0));
\r
73 // Map a fresnel effect
\r
74 vec4 fresnel = texture2D(Fresnel, vec2(v, 0.0));
\r
76 // map the refection of the environment
\r
77 vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
\r
80 // set the user shininess offset
\r
81 float transparency_offset = clamp(refl_correction, -1.0, 1.0);
\r
82 float reflFactor = 0.0;
\r
84 float MixFactor = specNoise.r * specNoise.g * specNoise.b * 350.0;
\r
86 MixFactor = 0.75 * smoothstep(0.0, 1.0, MixFactor);
\r
88 reflFactor = max(map.a * (texel.r + texel.g), 1.0 - MixFactor) * nFactor + transparency_offset ;
\r
89 reflFactor =0.75 * smoothstep(0.05, 1.0, reflFactor);
\r
91 // set ambient adjustment to remove bluiness with user input
\r
92 float ambient_offset = clamp(ambient_correction, -1.0, 1.0);
\r
93 vec3 ambient_Correction = vec3(ambient.rg, ambient.b * 0.6) * ambient_offset;
\r
94 ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
\r
96 // add fringing fresnel and rainbow effects and modulate by reflection
\r
97 vec4 reflcolor = mix(reflection, rainbow, rainbowiness * v);
\r
99 vec4 reflfrescolor = mix(reflcolor, fresnel, fresneliness * v);
\r
100 vec4 noisecolor = mix(reflfrescolor, noisevec, noisiness);
\r
101 vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0) * nFactor;
\r
103 vec4 mixedcolor = mix(texel, raincolor * (1.0 - refl_correction * (1.0 - lightness)), reflFactor);
\r
105 // the final reflection
\r
106 vec4 fragColor = vec4(color.rgb * mixedcolor.rgb + ambient_Correction * nFactor, color.a);
\r
108 encode_gbuffer(N, fragColor.rgb, 1, specular, shininess, emission, gl_FragCoord.z);
\r