Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMedo3337

Posted 08 November 2013 - 01:08 PM

@Tispe: I think I'm doing the same idea in my code

 

Comparing the depth in the shadow map with the current pixel depth to determine if the pixel should be darker or not

 

And it's still not working...

 

Here is my shader code:

...
...
VS_OUTPUT VS( VERTEX IN )
{
     VS_OUTPUT OUT;
     OUT = (VS_OUTPUT)0;
     OUT.Position  = mul(float4(IN.Position, 1.0f), WorldViewProjection);
     OUT.UV        = IN.UV;
     OUT.Normal    = mul(float4(IN.Normal, 0.0f), World).xyz;
     float4 oPosition = mul(float4(IN.Position, 1.0f), lightWorldViewProj);
     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), lightWorldView).z;
     return OUT;
}

float4 PS(VS_OUTPUT IN) : COLOR
{
    float scene_z = tex2Dproj(shadowMap, IN.screenPos).x;
    if (IN.Z > scene_z)
        // Pixel in shadow
        shadow = float4(0.4f, 0.4f, 0.4f);
    else
        shadow = float4(1.0f, 1.0f, 1.0f)
    return tex2D( colorTex, IN.UV ) * shadow;
}

#1Medo3337

Posted 08 November 2013 - 12:05 PM

@Tispe: I think I'm doing the same idea in my code

 

Comparing the depth in the shadow map with the current pixel depth to determine if the pixel should be darker or not

 

And it's still not working...

 

Here is my shader code:

VS_OUTPUT VS( VERTEX IN )
{
     VS_OUTPUT OUT;
     OUT = (VS_OUTPUT)0;
     OUT.Position  = mul(float4(IN.Position, 1.0f), WorldViewProjection);
     OUT.UV        = IN.UV;
     OUT.Normal    = mul(float4(IN.Normal, 0.0f), World).xyz;
     float4 oPosition = mul(float4(IN.Position, 1.0f), lightWorldViewProj);
     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), lightWorldView).z;
     return OUT;
}

float4 PS(VS_OUTPUT IN) : COLOR
{
    float scene_z = tex2Dproj(shadowMap, IN.screenPos).x;
    if (IN.Z > scene_z)
        // Pixel in shadow
        shadow = float4(0.4f, 0.4f, 0.4f);
    else
        shadow = float4(1.0f, 1.0f, 1.0f)
    return tex2D( colorTex, IN.UV ) * shadow;
}

PARTNERS