Jump to content
  • Advertisement
Sign in to follow this  
abdellah

shadow map artifact with point transformations

This topic is 1323 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello

i have setup correctly my HLSL for shadow mapping, but the result is incorrect for some value & it si correct for others, please help me to resolve this issue, there is my HLSL :

 

 
//------- Constants --------
 
float4x4 wvp  : WORLDVIEWPROJECTION;
float4x4 lightWVP;
float xMaxDepth = 100.0f;
 
//------- Texture Samplers --------
 
 
 Texture xColoredTexture;
 
sampler ColoredTextureSampler = sampler_state { texture = <xColoredTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};
 
Texture xShadowMap;
 
sampler ShadowMapSampler = sampler_state { texture = <xShadowMap> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = clamp; AddressV = clamp;};
 
 
 
 
struct SMapVertexToPixel
{
    float4 Position     : POSITION;    
    float3 Position2D    : TEXCOORD0;
};
 
struct SMapPixelToFrame
{
    float4 Color : COLOR0;
};
 
struct SSceneVertexToPixel
{
    float4 Position             : POSITION;
    float4 ShadowMapSamplingPos : TEXCOORD0;    
 
     float4 RealDistance            : TEXCOORD1;
     float2 TexCoords            : TEXCOORD2;
     float3 Position3D            : TEXCOORD4;
 
};
 
struct SScenePixelToFrame
{
    float4 Color : COLOR0;
};
 
//------- Vertex Shaders --------
 
SMapVertexToPixel ShadowMapVertexShader( float4 inPos : POSITION)
{
    SMapVertexToPixel Output = (SMapVertexToPixel)0;
 
    Output.Position = mul(inPos, lightWVP);
    Output.Position2D = Output.Position;
    
    return Output;    
}
 
 
 SSceneVertexToPixel ShadowedSceneVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float3 inNormal : NORMAL)
 
{
    SSceneVertexToPixel Output = (SSceneVertexToPixel)0;
 
 
    Output.Position = mul(inPos, wvp);
    Output.ShadowMapSamplingPos = mul(inPos, lightWVP);
 
     Output.RealDistance = Output.ShadowMapSamplingPos.z/xMaxDepth ;
     Output.TexCoords = inTexCoords;
     Output.Position3D = inPos;
 
    
    return Output;    
}
 
//------- Pixel Shaders --------
 
 
 
 
 
SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
{
    SMapPixelToFrame Output = (SMapPixelToFrame)0;
 
    Output.Color = PSIn.Position2D.z/xMaxDepth;
 
    return Output;
}
 
SScenePixelToFrame ShadowedScenePixelShader(SSceneVertexToPixel PSIn)
{
    SScenePixelToFrame Output = (SScenePixelToFrame)0;
 
    float2 ProjectedTexCoords;
    ProjectedTexCoords[0] = PSIn.ShadowMapSamplingPos.x/PSIn.ShadowMapSamplingPos.w/2.0f +0.5f;
    ProjectedTexCoords[1] = -PSIn.ShadowMapSamplingPos.y/PSIn.ShadowMapSamplingPos.w/2.0f +0.5f;
 
 
   
         float StoredDepthInShadowMap = tex2D(ShadowMapSampler, ProjectedTexCoords ).x;    
         if ((PSIn.RealDistance.x - 1.0f/100.0f) <= StoredDepthInShadowMap)    
         {
       
             float4 ColorComponent = tex2D(ColoredTextureSampler, PSIn.TexCoords);
             Output.Color = ColorComponent ;      
         }
   
 
 
    return Output;
}
 
//------- Techniques --------
 
technique ShadowMap
{
    pass Pass0
    {
        VertexShader = compile vs_2_0 ShadowMapVertexShader();
        PixelShader = compile ps_2_0 ShadowMapPixelShader();
    }
}
 
technique ShadowedScene
{
    pass Pass0
    {
        VertexShader = compile vs_2_0 ShadowedSceneVertexShader();
        PixelShader = compile ps_2_0 ShadowedScenePixelShader();
    }
}
 
 
the value of wvp = WORLD * VIEW * PROJECTION
i have setup the light position on the top of the sphere (0,10,0) (look image) & the sphere has position as (0,3,0), the camera direction is (0,-1,0) & the camera UP DIRECTION is (0,1,0), where are the problem?
the screenshot N°=1 with no translation :
the screen shot N°=2 with translation in positive X-Axis :
 
 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!