Sign in to follow this  
xujiezhige

ShadowVolume

Recommended Posts

[CODE]
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 );

// 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
[color=#ff0000]PosView = float4( LightVecView, 0.0f );[/color]

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

oPos = mul( vPos, g_mWorldViewProjection );
}
[/CODE]

I can't understand the red line.

When the vertex is closer to viewer than light, we can also add PosView with some LightVecView.
But it just changes the position to a vector.[img]http://public.gamedev.net//public/style_emoticons/default/mellow.png[/img]
What is the meaning of the red line?

Share this post


Link to post
Share on other sites
"[b]If [/b]the light is between the camera and the vertex, [b]then [/b]the vertex is moved off into the distance, [b]else [/b][color=#b22222]the vertex is moved behind the camera by "LightVecView" (PosView.z - g_vLightView.z[/color][color=#B22222]) units[/color].".

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1329917887' post='4915481']
"[b]If [/b]the light is between the camera and the vertex, [b]then [/b]the vertex is moved off into the distance, [b]else [/b][color=#b22222]the vertex is moved behind the camera by "LightVecView" (PosView.z - g_vLightView.z[/color][color=#b22222]) units[/color].".
[/quote]

Thank you, Hodgman.

If you are right, then the vertex doesn't move along the line between light and vertex, but the line between light and camera when the vertex is closer to camera than light.
But we should move along the line between light and vertex.

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this