Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualMedo3337

Posted 08 November 2013 - 02:41 AM

I have created a shadow map

 

As I understand, I need to compare the current pixel depth with the shadow map, if the shadow map depth is LESS than the current pixel depth then I add shadow to the current pixel.

 

Now, I see half of the scene is darker (which is unexpected)

 

Shader

 

VS:

float4 oPosition = mul(float4(IN.Position, 1.0f), shadowWorldViewProj);
oPosition.x      = ((oPosition.x + oPosition.w) * ScreenParams.x + oPosition.w) * ScreenParams.z;
oPosition.y      = ((oPosition.w - oPosition.y) * ScreenParams.y + oPosition.w) * ScreenParams.w;
Out.screenPos    = oPosition;
Out.Z = mul(float4(IN.Position, 1.0f), shadowWorldView).z;

PS:

shadow = 0.0;
float scene_z = tex2Dproj(shadowMap, In.screenPos).x;
if (scene_z > 0)
{
    if (In.Z > scene_z)
        shadow = 1.0f;
}

#1Medo3337

Posted 08 November 2013 - 02:38 AM

I have created a shadow map

 

As I understand, I need to compare the current pixel depth with the shadow map, if the shadow map depth is LESS than the current pixel depth then I add shadow to the current pixel.

 

Now, I see half of the scene is darker (which is unexpected)

 

Shader

 

VS:

float4 oPosition = mul(float4(IN.Position, 1.0f), shadowWorldViewProj);
oPosition.x      = ((oPosition.x + oPosition.w) * ScreenParams.x + oPosition.w) * ScreenParams.z;
oPosition.y      = ((oPosition.w - oPosition.y) * ScreenParams.y + oPosition.w) * ScreenParams.w;
Out.screenPos    = oPosition;
Out.ShadowZ = mul(float4(IN.Position, 1.0f), shadowWorldView).z;

PS:

shadow = 0.0;
float scene_z = tex2Dproj(shadowMap, In.screenPos).x;
if (scene_z > 0)
{
    if (In.ShadowZ > scene_z)
        shadow = 1.0f;
}

PARTNERS