Commit 765e6a04 authored by Jan Möbius's avatar Jan Möbius

Updated lighting shader to include two sided lighting

parent 9e6eb660
......@@ -28,7 +28,11 @@ vec3 LitPointLight(vec3 vPosition,
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
#ifdef TWO_SIDED_LIGHTING
float ldotn = abs(clamp(dot(vLightDir, vNormal),-1.0,1.0));
#else
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
#endif
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
......@@ -55,7 +59,11 @@ vec3 LitDirLight(vec3 vPosition,
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
#ifdef TWO_SIDED_LIGHTING
float ldotn = abs(clamp(dot(vLightDir, vNormal),-1.0,1.0));
#else
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
#endif
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
......@@ -88,15 +96,17 @@ vec3 LitSpotLight(vec3 vPosition,
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
#ifdef TWO_SIDED_LIGHTING
float ldotn = abs(clamp(dot(vLightDir, vNormal),-1.0,1.0));
#else
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
#endif
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.001); // small epsilon to avoid undefined pow(0, 0) if shininess is also 0
cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
// attenuate
float fAtten = vLightAtten.x + vLightAtten.y * fLen + vLightAtten.z * fLen2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment