# w=0 problem in shadow volume

## Recommended Posts

in dx sample:Shadow volume, in the shader file: ShadowVolume.fx, on the function which deal with extrde the vertex away, you can get the
    float4 PosView = mul( vPos, g_mWorldView );

// 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);

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


why when it set w=0 when PosView.z <= g_vLightView.z, it works and otherwise it doesn't; what happened in the clipping stage? when I set w=0 on all situations, there is one more strange shadow; sorry I don't know how to paste picture here; you can see it by modify the code; the homogeneous coordinates, the clipping algorithm, puzzle me;

##### Share on other sites
I can't give a real answer, but setting the w component means that you have a vector instead of a point. The gpu knows how to handle this. If you have a triangle where one of the points has w=0, you'll actually get a three sided rectangle where one side can never be seen because it's off at infinity. You can see a cool example from nvidia visualizing this: http://download.developer.nvidia.com/developer/SDK/Individual_Samples/3dgraphics_samples.html

Search for "External Triangles".

As for this specific case, it has to do with fixing problems with general stencil shadows. Using a special shadow mesh, there are cases that can be fixed by sending off some of the faces to crazy town with this method. I'm not an expert on this, but I know how to find one: http://developer.nvidia.com/object/robust_shadow_volumes.html

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Forum Statistics

• Total Topics
628293
• Total Posts
2981870

• 11
• 10
• 10
• 11
• 17