Houston I have a simple shadow map problem

I have a simple shadow map shader with minimal problem on my shadow implementation : - D I know there’s something missing that it draw on polygon not facing the light while it should not, since my shader knowledge on available functions is limited I cannot spot the problem T _ T. any hint is appreciated and welcome ^_^y

IMAGE:

SHADOW MAP COLOR DRAW SHADER CODE :

    // Shadow color applying
    //------------------------------------------------------------------------------------------------------------------    

        
    //*>> Pixel position in light space
    //
    float4 m_LightingPos = mul(IN.WorldPos3D, __SM_LightViewProj);    
    
    
    //*>> Shadow texture coordinates
    //
    float2 m_ShadowTexCoord    = 0.5 * m_LightingPos.xy / m_LightingPos.w + float2( 0.5, 0.5 );
           m_ShadowTexCoord.y  = 1.0f - m_ShadowTexCoord.y;


    //*>> Shadow map depth 
    //
    float m_Shadowdepth = tex2D(ShadowMapSampler, m_ShadowTexCoord).r;    
    
    
    //*>> Pixel depth
    //
    float m_PixelDepth = (m_LightingPos.z / m_LightingPos.w) - 0.001f;
              
           
    //*>> Pixel depth in front of the shadow map depth then apply shadow color
    //
    if ( m_PixelDepth > m_Shadowdepth  )
    {                                        
        m_ColorView *= float4(0.5,0.5,0.5,0); 
    }
 
    // Final color
    //------------------------------------------------------------------------------------------------------------------    
        
    return m_ColorView;

Ah… found a simple solution, since all I need to know is if the pixel is facing the light or not, and since the Normal of the Vertex is already defined, I just get the Dot product of Light direction negated and the Vertex normal and use the Saturate shader function to get 0 or 1 though I can use max I choose Saturate function.

    //*>> Pixel facing light : 0 true 1 = false
    //                        
    float  m_IsPixelFacingLight = saturate( dot(-__SM_LightDirection, IN.Normal) );   

    //*>> Pixel depth in front of the shadow map depth and Vertex facing light 
    //
    if ( m_IsPixelFacingLight==0 && m_PixelDepth > m_Shadowdepth  )
    {                                
         m_ColorView *= float4(0.5,0.5,0.5,0); 
    }

FYI, shadow maps are used as attenuation masks - not multipliers. If you use them as a multiplier you’ll get umbra doubling.

1 Like

Isn’t it multiplying the color by 0.5f attenuated the color meaning darkening the pixel color, not sure it this will make umbra doubling since the color is already computed.

This works for me ATM eliminating my previous problem giving me a semi transparent not purely black shadow.

Thanks for the info, no worries man… I will disturb you if I encountered the problem ^_^y