Advertisement Jump to content
Sign in to follow this  

Anyone can explain Shadow Volume DX example for me plz

This topic is 4895 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

Im newb in Shadow volumes render. I ve read example code about shadow volume in DirectX SDK 9.0c They create quard between edge. and extrude away from light if not facng to light - dot(normal,LightVec) is less than 0. This is HLSL-vertex shader code for render and extude shadow volumes.

void VertShadowVolume( float4 vPos : POSITION,
                       float3 vNormal : NORMAL,
                       out float4 oPos : POSITION )
    // Compute view space normal
    float3 N = mul( vNormal, (float3x3)g_mWorldView );

    // Obtain view space position
    float4 PosView = mul( vPos, g_mWorldView );

    // NOTE : g_vLightView is View space light position.
    // Light-to-vertex vector in view space
    float3 LightVecView = PosView - g_vLightView;

    // Perform reverse vertex extrusion
    // Extrude the vertex away from light if it's facing away from the light.
    if( dot( N, -LightVecView ) < 0.0f )
        if( PosView.z > g_vLightView.z )
   += LightVecView * ( g_fFarClip - PosView.z ) / LightVecView.z;
            PosView = float4( LightVecView, 0.0f ); // <----- This line *****

        // Transform the position from view space to homogeneous projection space
        oPos = mul( PosView, g_mProj );
    } else
        oPos = mul( vPos, g_mWorldViewProjection );

All is ok, except one line. if( PosView.z > g_vLightView.z ) ....... < extude vertex away from light > else PosView = float4( LightVecView, 0.0f ); <----- ??? Why ? output to be vector from vertex to light, if vertex positon depth(.z) less than light position. thx a lot :) ps. sorry for bad english.

Share this post

Link to post
Share on other sites
Hah! I went through that sample, saw that line, and had the exact same thought!

I haven't a clue!

What I ended up doing was not adding it to my code (I use directional lighting so that might be why it made no difference).

My best advice is to remove it and see what happens. I'm betting on nothing :).

Anywho, if you're interested, this is my final VS for directional lit volume shadows:

vertexOutput OUT;

float3 N = mul( IN.normal, world );
float dir = dot(-lightDir, N);
float3 p = mul( float4( , 1.0), world);
if (dir >= 0.0f)
p += (-lightDir * 50);
OUT.hPosition = mul( float4( , 1.0) , viewProjection);
OUT.hPosition = mul( float4( , 1.0) , worldViewProj);

return OUT;

note I'm using -lightDir in both cases, so you can ignore the - sign, it's just there to fit with my terrain lighting direction.

Good luck.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!