Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

ShadowVolume

Started by xujiezhige Feb 22, 2012 at 8:39 AM 3 replies 1k views
Original Post
xujiezhige
xujiezhige

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

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

oPos = mul( vPos, g_mWorldViewProjection );
}


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.mellow.png
What is the meaning of the red line?
xujiezhige
xujiezhige
The red line doesn't present.

It's [color="#880000"]PosView = float4( LightVecView, 0.0f );[color="#000000"].
Hodgman
Hodgman
"If the light is between the camera and the vertex, then the vertex is moved off into the distance, else [color=#b22222]the vertex is moved behind the camera by "LightVecView" (PosView.z - g_vLightView.z[color=#B22222]) units.".
xujiezhige
xujiezhige

"If the light is between the camera and the vertex, then the vertex is moved off into the distance, else [color=#b22222]the vertex is moved behind the camera by "LightVecView" (PosView.z - g_vLightView.z[color=#b22222]) units.".


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.
xujiezhige
xujiezhige
And why does it make float4( [color="#880000"]LightVecView, 0 ), not float4( [color="#880000"]LightVecView, 1 );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.