Jump to content
  • Advertisement
Sign in to follow this  
ThiEF_Jr

Anyone can explain Shadow Volume DX example for me plz

This topic is 4709 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 )
            PosView.xyz += LightVecView * ( g_fFarClip - PosView.z ) / LightVecView.z;
        else
            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
Advertisement
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(IN.position.xyz , 1.0), world);
if (dir >= 0.0f)
{
p += (-lightDir * 50);
OUT.hPosition = mul( float4(p.xyz , 1.0) , viewProjection);
}
else
{
OUT.hPosition = mul( float4(IN.position.xyz , 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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!