float3 cameraDirection; float shininess; float nearDistance; float farDistance; float tex_atlas_size; float scale_factor; float3 lDiffuseColor; float3 lSpecularColor; float3 lattenuation; float4 gambient; float Ka; float Kd; float Ks; sampler orderFrontBack: register(s0); sampler leaf: register(s1); sampler shadowMap: register(s6); sampler spotLight: register(s2); sampler normalMap: register(s3); sampler ob_front_face: register(s4); sampler ob_back_face: register(s5); float shadowBias = 0.0; float backProjectionCut = 0.01; float exposure; float4x4 worldmatrix; float4 main_fp(float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float3 viewVec: TEXCOORD2, float4 shadowCrd: TEXCOORD3, float4 texCoord: TEXCOORD4, float4 texCoordNormalized: TEXCOORD5) : COLOR { float4 leafColor; float4 ocolor; float2 coords = ((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0; normal = normalize(normal); float4 obsColor; float depth = length(lightVec.xyz); lightVec = normalize(lightVec); viewVec = normalize(viewVec); cameraDirection = normalize(-cameraDirection); if (dot(normal.xyz,cameraDirection.xyz) < 0.0) //if (reg < 0.0) { obsColor = float4(tex2D(ob_front_face,texCoord).xxxw); //obsColor.xyz = obsColor.xyz / obsColor.w; //if (tex2D(ob_front_face,texCoord).x == tex2D(ob_front_face,texCoord).y) //{ // obsColor = float4(1.0,0.0,0.0,1.0); //} //else //{ // obsColor = float4(0.0,0.0,1.0,1.0); //} } else { obsColor = float4(tex2D(ob_front_face,texCoord).yyyw); //obsColor.xyz = obsColor.xyz / obsColor.w; //if (tex2D(ob_front_face,texCoord).x == tex2D(ob_front_face,texCoord).y) //{ // obsColor = float4(1.0,1.0,0.0,1.0); //} //else //{ // obsColor = float4(0.0,1.0,1.0,1.0); //} } if (dot(normal.xyz,cameraDirection.xyz) < 0.0) //if (reg < 0.0) { normal = -normal; } float lDiffuseAttenuation = max(dot(lightVec,normal),0.0); float lSpecularAttenuation = pow(max(dot(reflect(-normalize(viewVec),normal),lightVec),0.0),shininess); float4 shadowMapValue = tex2Dproj(shadowMap,shadowCrd).xyzw; float spotLight = tex2Dproj(spotLight,shadowCrd); // If the depth is larger than the stored depth, this fragment // is not the closest to the light, that is we are in shadow. // Otherwise, we're lit. Add a bias to avoid precision issues. float shadow = tex2Dproj(shadowMap, shadowCrd).w - 500 < (depth - 0.0) ? 0.1f : 1.0f; // Cut back-projection, that is, make sure we don't lit // anything behind the light. Theoretically, you should just // cut at w = 0, but in practice you'll have to cut at a // fairly high positive number to avoid precision issue when // coordinates approaches zero. shadow *= (shadowCrd.w > backProjectionCut); //shadow *= spotLight; // Leaf lookup leafColor = (tex2D(orderFrontBack,texCoord).w > 0.0) ? tex2D(leaf,coords + float2(-0.025,0.025)) : 0.0; //leafColor = (tex2D(ob_front_face,texCoord*512).y > 0.0) ? tex2D(leaf,coords + float2(-0.025,0.025)) : 0.0; leafColor = float4(0.0,0.0,0.0,leafColor.w) + float4(Ka * gambient.xyz * leafColor.xyz,0.0) ////+ float4(Kd * lDiffuseAttenuation * leafColor.xyz * lDiffuseColor,0.0); + float4(Kd * lDiffuseAttenuation * leafColor.xyz * lDiffuseColor,0.0) //+ float4(Ks * lSpecularAttenuation * lSpecularColor,0.0); + float4(Ks * lSpecularAttenuation * leafColor.xyz * lSpecularColor,0.0); // LIGHT DIRECTION DEBUG... //if (lightVec.z > 0.5) //{ // leafColor = float4(1.0,0.0,0.0,leafColor.w); //} //else //{ // leafColor = float4(0.0,0.0,1.0,leafColor.w); //} // CAMERA DIRECTION DEBUG... //leafColor = float4(lightVecNormalMapping.xyz,leafColor.w); // AMBIENT DEGUB.... //leafColor = float4(Ka * gambient.xyz * leafColor.xyz,leafColor.w); // DIFFUSE COLOUR DEBUG... //leafColor = float4(lDiffuseColor.xyz,leafColor.w); // DIFFUSE COLOUR DEBUG... //leafColor = float4(Kd.xxx,leafColor.w); // DIFFUSE //leafColor = float4(Kd * (lDiffuseAttenuation) * leafColor.xyz * lDiffuseColor,leafColor.w); // SPECULAR //leafColor = float4(Ks * (lSpecularAttenuation) * leafColor.xyz * lSpecularColor,leafColor.w); // SHADOW //leafColor = float4(shadow.xxx,leafColor.w); leafColor = float4((1.0 - exp(exposure * obsColor.xyz)),leafColor.w); ocolor = leafColor; return ocolor; }