//float4 main_fp(float2 texCoord: TEXCOORD0, float2 texCoordNormalized: TEXCOORD1) : COLOR //{ // // DirectX // return float4((tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0); //} /* normal = normalize(normal); // Radial distance float depth = length(lightVec); // Normalizes light vector lightVec /= depth; // Standard lighting float odiffuse = saturate(dot(lightVec, normal)); float ospecular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16); // The depth of the fragment closest to the light float shadowMap = tex2Dproj(shadowMap, shadowCrd); // A spot image of the spotlight 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; shadow = (depth < shadowMap + shadowBias); // 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); // Modulate with spotlight image shadow *= spotLight; // Shadow any light contribution except ambient //float4 tempcolor = (tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0; tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0) : 0.0; // green test //tempcolor.xyz = float3(0.0,0.5,0.2); // Look the different leaves orientations used... //float4 tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? float4(tex2D(orderFrontBack, texCoord).zw,1.0,1.0) : 0.0; tempcolor = float4(lattenuation * (Ka*(gambient.xyz)) + (Kd*(odiffuse * tempcolor.xyz * ldiffuse)) + (Ks * (ospecular * lspecular)),tempcolor.w * 0.5); //return float4((tex2D(orderFrontBack, texCoord).w > 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + float2(0.0,0.0)) * 4.0) : 0.0); //else //{ // tempcolor = float4(0.0,1.0,0.0,1.0); //} */ float4x4 worldmatrix; float tex_atlas_size; float scale_factor; float3 ldiffuse; float3 lspecular; float3 lattenuation; float4 gambient; float Ka; float Kd; float Ks; sampler orderFrontBack: register(s0); sampler leaf: register(s1); sampler shadowMap: register(s2); sampler spotLight: register(s3); float shadowBias = 45.57; float backProjectionCut = 0.0; float4 main_fp(float reg: VFACE, float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float3 viewVec: TEXCOORD2, float4 shadowCrd: TEXCOORD3, float4 texCoord: TEXCOORD4, float4 texCoordNormalized: TEXCOORD5) : COLOR { float4 tempcolor; float4 ocolor; normal = normalize(normal); // Front and Back faces lighted normal = (reg > 0.0) ? normal : -normal; // Radial distance float depth = length(lightVec); // Normalizes light vector lightVec /= depth; // Standard lighting float odiffuse = saturate(dot(lightVec, normal)); float ospecular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16); // The depth of the fragment closest to the light float shadowMap = tex2Dproj(shadowMap, shadowCrd); // A spot image of the spotlight 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; shadow = (depth < shadowMap + shadowBias); // 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); // Modulate with spotlight image //shadow *= spotLight; // Shadow any light contribution except ambient tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? tex2D(leaf,((texCoordNormalized - tex2D(orderFrontBack, texCoord).xy) + tex2D(orderFrontBack, texCoord).zw) * 4.0) : 0.0; // green test //tempcolor.xyz = float3(0.0,0.5,0.2); tempcolor = float4((Ka*(gambient.xyz)) + (Kd*(odiffuse * tempcolor.xyz * ldiffuse)) + (Ks * (ospecular * lspecular)),tempcolor.w); // Look the different leaves orientations used... //tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? float4(tex2D(orderFrontBack, texCoord).zw,1.0,1.0) : 0.0; // Check the AATexQuads of the leaves... //tempcolor = (tex2D(orderFrontBack, texCoord).x >= 0.0) ? float4(tex2D(orderFrontBack, texCoord).xy,1.0,1.0) : 0.0; // Shows each side the front and the back side... //tempcolor = (reg > 0.0) ? float4(1.0,0.0,0.0,tempcolor.w) : float4(0.0,1.0,0.0,tempcolor.w); ocolor = tempcolor; return ocolor; }