Directx9 shadowvolume 的问题 分不多 全给了!
代码出自directx9 自带的例子 shadow volume
以下的代码段是在shadow volume.fx里面的一段shader,求指教
void VertShadowVolume( float4 vPos : POSITION,
float3 vNormal : NORMAL,
out float4 oPos : POSITION )
{
// Compute view space normal
float3 N = mul( vNormal, (float3x3)g_mWorldView );//vNormal是面法线,在前面将面法线当作顶点法线赋值了
//g_mWorldView = g_mWorldScaling * *g_MCamera.GetWorldMatrix() * *g_Camera.GetViewMatrix()
// 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 )//面的法线与点到光源的的夹角大于90,即该面是背光面 需要将其拉伸
{
if( PosView.z > g_vLightView.z )
PosView.xyz += LightVecView * ( g_fFarClip - PosView.z ) / LightVecView.z;
else
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 );
}
hr = D3DXCreateMesh( nNextIndex / 3 + nNumMaps * 7,// nNextIndex / 3表示pdwNewIBData中的面数,即经过退化
( pInputMesh->GetNumFaces() + nNumMaps ) * 3,
D3DXMESH_32BIT,
SHADOWVERT::Decl,
pd3dDevice,
&pPatchMesh );