#line 1 "complex-ogre-pssm-in.txt" float shadowPCF(sampler2D shadowMap, float4 shadowMapPos, float2 offset) { shadowMapPos = shadowMapPos / shadowMapPos.w; float2 uv = shadowMapPos.xy; float3 o = float3(offset, -offset.x) * 0.3f; // Note: We using 2x2 PCF. Good enough and is alot faster. float c = (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.xy).r) ? 1 : 0; // top left c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.xy).r) ? 1 : 0; // bottom right c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.zy).r) ? 1 : 0; // bottom left c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.zy).r) ? 1 : 0; // top right //float c = (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.xyyy).r) ? 1 : 0; // top left //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.xyyy).r) ? 1 : 0; // bottom right //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.zyyy).r) ? 1 : 0; // bottom left //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.zyyy).r) ? 1 : 0; // top right return c / 4; } // to put it simply, this does 100% per pixel diffuse lighting void main( float3 uv : TEXCOORD0, float3 OSlightDir : TEXCOORD1, float3 OShalfAngle : TEXCOORD2, float4 LightPosition0 : TEXCOORD3, float4 LightPosition1 : TEXCOORD4, float4 LightPosition2 : TEXCOORD5, float3 normal : TEXCOORD6, out float4 oColour : COLOR, uniform float4 invShadowMapSize0, uniform float4 invShadowMapSize1, uniform float4 invShadowMapSize2, uniform float4 pssmSplitPoints, uniform sampler2D diffuse, uniform sampler2D specular, uniform sampler2D normalMap, uniform sampler2D shadowMap0, uniform sampler2D shadowMap1, uniform sampler2D shadowMap2, uniform float4 lightDiffuse, uniform float4 lightSpecular, uniform float4 ambient ) { // calculate shadow float shadowing = 1.0f; float4 splitColour; if (uv.z <= pssmSplitPoints.y) { splitColour = float4(0.1, 0, 0, 1); shadowing = shadowPCF(shadowMap0, LightPosition0, invShadowMapSize0.xy); } else if (uv.z <= pssmSplitPoints.z) { splitColour = float4(0, 0.1, 0, 1); shadowing = shadowPCF(shadowMap1, LightPosition1, invShadowMapSize1.xy); } else { splitColour = float4(0.1, 0.1, 0, 1); shadowing = shadowPCF(shadowMap2, LightPosition2, invShadowMapSize2.xy); } // retrieve normalised light vector, expand from range-compressed float3 lightVec = normalize(OSlightDir); // retrieve half angle and normalise through cube map float3 halfAngle = normalize(OShalfAngle); // get diffuse colour float4 diffuseColour = tex2D(diffuse, uv.xy); // specular float4 specularColour = tex2D(specular, uv.xy); float shininess = specularColour.w; specularColour.w = 1; // calculate lit value. float4 lighting = lit(dot(normal, lightVec), dot(normal, halfAngle), shininess * 128) * shadowing; // final lighting with diffuse and spec oColour = (diffuseColour * clamp(ambient + lightDiffuse * lighting.y, 0, 1)) + (lightSpecular * specularColour * lighting.z); oColour.w = diffuseColour.w; //oColour += splitColour; }