currently i am trying to do shadow mapping. i am rendering to a texture the depth data of the scene and then in shadow shader i am using it but as you can see the image i am not getting currect shadows actually no shadows at all… i cant seem to pinpoint the exact problem … what could be this???
depth shader
float4 main(PixelInputType input) : SV_TARGET
{
float depthValue;
float4 color;
depthValue = (input.depthPosition.z / input.depthPosition.w );
color = float4(depthValue, depthValue, depthValue, 1.0f);
return color;
}
shadow shader
float4 main(PixelInputType input) : SV_TARGET
{
float2 projectTexCoord;
float3 lightDir;
float lightIntensity;
float4 textureColor;
float4 color = ambientColor;
float3 reflection;
float4 specular = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 normalMap;
float3 bumpNormal;
float bias = 0.001f;
projectTexCoord.x = input.lightViewPosition.x / input.lightViewPosition.w * 0.5f + 0.5f;
projectTexCoord.y = -input.lightViewPosition.y / input.lightViewPosition.w * 0.5f + 0.5f;
input.lightViewPosition /= input.lightViewPosition.w;
textureColor = shaderTexture[0].Sample(sampleType, input.tex );
normalMap = shaderTexture[1].Sample(sampleType, input.tex );
normalMap = (normalMap * 2.0f) - 1.0f;
bumpNormal = (normalMap.x * input.tangent) + (normalMap.y * input.binormal) + (normalMap.z * input.normal);
bumpNormal = normalize(bumpNormal);
float4 shadowColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
if (input.lightViewPosition.x >= -1.0f &amp;amp;amp;&amp;amp;amp; input.lightViewPosition.x <= 1.0f &amp;amp;amp;&amp;amp;amp;
input.lightViewPosition.y >= -1.0f &amp;amp;amp;&amp;amp;amp; input.lightViewPosition.y <= 1.0f &amp;amp;amp;&amp;amp;amp;
input.lightViewPosition.z >= 0.0f /*&amp;amp;amp;&amp;amp;amp; input.lightViewPosition.z <= 1.0f*/)
{
float depthValue = depthMapTexture.Sample(SampleTypeClamp, projectTexCoord).r;
float lightDepthValue = input.lightViewPosition.z - bias;
if (lightDepthValue < depthValue)
{
lightIntensity = 1.0f;
if (lightIntensity > 0.0f)
{
color += (diffuseColor);
color = saturate(color);
}
}
else
{
shadowColor = float4(1.0f, 0.0f, 0.0f, 1.0f);
}
}
reflection = normalize(2 * lightIntensity * bumpNormal - input.lightPos);
specular = pow(saturate(dot(reflection, input.viewDirection)), specularPower);
color *= textureColor * shadowColor;
color = saturate(color + specular);
return color;
}
// Setup field of view and screen aspect for a square light source.
float fieldOfView = XM_PI/2.0f;
float screenAspect = 1.0f;
// Create the projection matrix for the light.
m_projectionMatrix = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, screenNear, screenDepth);
lightPositioncntr += 1.f * deltaTime;
Vector3 lpos = Vector3(
-15.f * sin(lightPositioncntr),
8.0f,
-15.f * cos(lightPositioncntr)) * (1 + 0.5f * sin(lightPositioncntr));
m_Light->SetPosition(lpos.x, lpos.y, lpos.z);
Vector3 up;
// Setup the vector that points upwards.
up.x = 0.0f;
up.y = 1.0f;
up.z = 0.0f;
// Create the view matrix from the three vectors.
m_viewMatrix = XMMatrixLookAtLH( m_position, m_lookAt, up);