- cpp Code: Select all
uniform sampler2D ColorTex; //guess what :P
uniform sampler2D NormalTex; //view space normal.xy
uniform sampler2D DepthTex; //view space depth
uniform vec3 Direction;
uniform vec3 Color;
vec4 vNormal= texture2D(NormalTex, gl_TexCoord.xy);
vNormal.z= -sqrt( -(vNormal.x*vNormal.x) - (vNormal.y*vNormal.y) + 1.0 );
//calculate the light
vec4 lightDir= vec4(normalize(Direction), 0.0);
float NdotL = max(dot(normalize(vNormal), lightDir), 0.0);
// Temp fix of the bug of the dot product at angle 90degree.
// This is useful for Phong shade and 1/2 vector calculation.
float rim = pow(1.0 - NdotL, 4.0); //Use the power constant 2,3... //Smaller power for softer light shadow.
vec4 Diffuse = vec4(Color,0.0)*texture2D(ColorTex, gl_TexCoord.xy);
Ambient light shader seems to have same calculation as directional.
Why don't we merge ambient with directional? Or can we access Ambient light data inside directional light?