Hello. I’m new to panda. As I have been able to pick up quite a bit on my own, some things still confuse me. I am attempting to translate a directX VSM tutorial (I’m still studying the math) application for use in panda3D, and my best guess of whats wrong is that I have messed up on calling some of the transform matrices, as its drawing random blobs of black. If one of you kind souls could help me understand what I did wrong, it would be greatly appreciated.
Shadowcaster.cg
//Cg
//Cg profile arbvp1 arbfp1
//rendered from light viewpoint
void vshader(
in float4 vtx_position : POSITION,
in uniform float4 wspos_light,
in uniform float4x4 mat_modelproj,
in uniform float4x4 trans_model_to_world,
out float4 l_position : POSITION,
out float l_lightDist : TEXCOORD0)
{
//world position
float4 worldPos = mul( vtx_position, trans_model_to_world );
//position * view proj
l_position = mul ( vtx_position , mat_modelproj );
//depth of light
l_lightDist = length( wspos_light.xyz - worldPos.xyz);
}
void fshader(in float4 l_position : POSITION,
in float l_lightDist : TEXCOORD0,
out float4 o_color : COLOR)
{
//depth, depth*depth
o_color = float4( l_lightDist, l_lightDist * l_lightDist, 0.0f, 1.0f );
}
shadow.sha
//Cg
//Cg profile arbvp1 arbfp1
//rendered from main camera
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord0: TEXCOORD0,
float3 vtx_normal: NORMAL,
in uniform float4x4 trans_model_to_world,
in uniform float4x4 mat_modelproj,
in uniform float4x4 trans_model_to_view_of_light,
in uniform float4x4 trans_model_to_clip_of_light,
in uniform float4x4 trans_view_of_light_to_clip_of_light,
in uniform float4x4 trans_model_to_clip,
in uniform float4 wspos_light,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float3 l_norm : TEXCOORD1,
out float4 l_lightViewPos : TEXCOORD2,
out float3 l_wLight : TEXCOORD3,
out float l_fDepth : TEXCOORD4)
{
l_texcoord0=vtx_texcoord0;
//world pos
float4 worldPos = mul( vtx_position, trans_model_to_world );
//view of light pos
float4 lightViewPos = mul( vtx_position, trans_model_to_view_of_light );
float3 l_lightVec = wspos_light.xyz - worldPos.xyz;
//position mat proj
l_position = mul( vtx_position, mat_modelproj );
//shadow projection
l_lightViewPos = mul( lightViewPos, trans_view_of_light_to_clip_of_light );
//normal
l_norm = normalize( mul( float4( vtx_normal, 1.0f ), trans_model_to_world ) );
//light direction
l_wLight = normalize( l_lightVec );
//light length
l_fDepth = length( l_lightVec );
}
void fshader(
in float4 l_position : POSITION,
in float2 l_texcoord0 : TEXCOORD0,
in float3 l_norm : TEXCOORD1,
in float4 l_lightViewPos : TEXCOORD2,
in float3 l_wLight : TEXCOORD3,
in float l_fDepth : TEXCOORD4,
in uniform float4 k_diffuse_color,
in uniform sampler2D k_Ldepthmap : TEXUNIT1,
out float4 o_color :COLOR)
{
//texture coord
l_lightViewPos.xy /= l_lightViewPos.w;
float2 tex = l_lightViewPos.xy * float2( 0.5f, -0.5f ) + 0.5f;
//Lighting
float lit = (float)0.0f;
float4 moments = tex2D(k_Ldepthmap, tex);
//chebyshevUpperBound
float E_x2 = moments.y;
float Ex_2 = moments.x * moments.x;
float variance = E_x2 - Ex_2;
float mD = (moments.x - l_fDepth );
float mD_2 = mD * mD;
float p = variance / (variance + mD_2 );
lit = max( p, l_fDepth <= moments.x );
//renormalize
float3 wLight = normalize( l_wLight );
float3 wNormal = normalize( l_norm );
//light diffuse color
float3 diffuse = k_diffuse_color.xyz;
diffuse *= dot( normalize( wNormal ), wLight );
o_color = float4( diffuse, 1.0f ) * lit;
}
Thanks in advance.