Hi again.
I’m currently trying to improve our shadow system once again.
The new shader that I’m working on doesn’t work.
If I load it with:
basic-shaders-only #f
I get:
:gobj(error): /home/jeremie/shader/terrain_shaded2.sha: (135) : fatal error C9999: *** exception during compilation ***
(135 is eof )
if I try with:
basic-shaders-only #t
I get a “Segmentation fault” in the loader.loadShader()
I’m on ubuntu 8.10, panda3D 1.5.4, 8800GT (drivers 177)
Here’s the shader:
//Cg
//Cg profile arbvp1 arbfp1
void vshader( in float4 vtx_position : POSITION,
in float3 vtx_normal : NORMAL,
in float3 vtx_tangent0 : TANGENT,
in float3 vtx_binormal0 : BINORMAL,
in float2 vtx_texcoord0 : TEXCOORD0,
in uniform float4x4 mat_modelproj,
in uniform float4 k_lightvec1,
in uniform float4 k_lightvec2,
in uniform float4 k_lightvec3,
in uniform float4 k_light0,
in uniform float4x4 trans_world_to_model,
in uniform float4 mspos_light1,
in uniform float4 mspos_light2,
in uniform float4 mspos_light3,
in uniform float4x4 trans_model_to_clip_of_light1,
in uniform float4x4 trans_model_to_clip_of_light2,
in uniform float4x4 trans_model_to_clip_of_light3,
out float2 l_texcoord0 : TEXCOORD0,
out float3 l_light1 : TEXCOORD1,
out float3 l_light2 : TEXCOORD2,
out float3 l_light3 : TEXCOORD3,
out float4 l_shade1 : TEXCOORD4,
out float4 l_shade2 : TEXCOORD5,
out float4 l_shade3 : TEXCOORD6,
out float4 l_position : TEXCOORD7,
out float4 l_pos : POSITION)
{
l_position = mul( mat_modelproj, vtx_position );
l_pos = l_position;
l_texcoord0 = vtx_texcoord0;
float3x3 TBN = float3x3(vtx_tangent0, vtx_binormal0, vtx_normal);
l_light1 = normalize(mul(TBN,-normalize(k_lightvec1.xyz)));
l_light2 = normalize(mul(TBN,-normalize(k_lightvec2.xyz)));
l_light3 = normalize(mul(TBN,-normalize(k_lightvec3.xyz)));
// scale matrix
float4x4 scaleBiasMatrix = {
0.5f,0.0f,0.0f, .5+0.0001,
0.0f,0.5f,0.0f, .5+0.0001,
0.0f,0.0f,0.5f, .5,
0.0f,0.0f,0.0f, 1.0f
};
float4x4 textureMat1 = mul(scaleBiasMatrix, trans_model_to_clip_of_light1);
float4x4 textureMat2 = mul(scaleBiasMatrix, trans_model_to_clip_of_light2);
float4x4 textureMat3 = mul(scaleBiasMatrix, trans_model_to_clip_of_light3);
l_shade1 = mul(textureMat1, vtx_position);
l_shade2 = mul(textureMat2, vtx_position);
l_shade3 = mul(textureMat3, vtx_position);
}
void fshader( in float2 l_texcoord0 : TEXCOORD0,
in float3 l_light1 : TEXCOORD1,
in float3 l_light2 : TEXCOORD2,
in float3 l_light3 : TEXCOORD3,
in float4 l_shade1 : TEXCOORD4,
in float4 l_shade2 : TEXCOORD5,
in float4 l_shade3 : TEXCOORD6,
in float4 l_position : TEXCOORD7,
in uniform float4 k_hfsize,
in uniform float4 k_parallele_split,
in uniform sampler2D tex_0 : TEXUNIT0,
in uniform sampler2D tex_1 : TEXUNIT1,
in uniform sampler2D tex_2 : TEXUNIT2,
in uniform sampler2D tex_3 : TEXUNIT3,
in uniform sampler2D k_Ldepthmap1 : TEXUNIT4,
in uniform sampler2D k_Ldepthmap2 : TEXUNIT5,
in uniform sampler2D k_Ldepthmap3 : TEXUNIT6,
out float4 o_color : COLOR )
{
float2 g_texcoord;
float2 loc_texcoord2;
loc_texcoord2 = l_texcoord0;
g_texcoord.x = loc_texcoord2.x / k_hfsize.x;
g_texcoord.y = loc_texcoord2.y / k_hfsize.y;
float4 B = tex2D( tex_3, g_texcoord );
loc_texcoord2 *= 0.01f;
float4 c0 = tex2D( tex_0, loc_texcoord2 );
float4 c1 = tex2D( tex_1, loc_texcoord2 );
float4 c2 = tex2D( tex_2, loc_texcoord2 );
float totalInverse = 1.0f / (B.x + B.y + B.z);
c0 *= B.x * totalInverse;
c1 *= B.y * totalInverse;
c2 *= B.z * totalInverse;
float3 normal = float3(0,0,1) ;
float light1 = max(0,dot(normal,0.7 *normalize(l_light1.xyz)));
float light2 = max(0,dot(normal,0.25*normalize(l_light2.xyz)));
float light3 = max(0,dot(normal,0.25*normalize(l_light3.xyz)));
float ambiant1 = 0.1;
float brightness = saturate(ambiant1 + light1 + light2 + light3);
float4 used_shade = l_shade3 ;
sampler2D depth_map = k_Ldepthmap3 ;
if( l_position.z < k_parallele_split[2])
{
used_shade = l_shade2 ;
depth_map = k_Ldepthmap2 ;
}
if( l_position.z < k_parallele_split[1])
{
used_shade = l_shade1 ;
depth_map = k_Ldepthmap1 ;
}
float3 shadowUV = used_shade.xyz / used_shade.w ;
float2 delta = saturate(shadowUV.xy) - shadowUV.xy ;
float shadowTerm = 1 ;
if (dot(delta, delta) <= 0)
{
shadowTerm = tex2D(depth_map, shadowUV.xy).x ;
if (shadowTerm < (used_shade.z -0.0025) )
shadowTerm = 0 ;
else
shadowTerm = 1 ;
}
float4 fullShade = brightness * max(0.5,shadowTerm) ;
o_color = fullShade * ( c0 + c1 + c2 );
o_color.w = 1.0f;
}
Any idea what’s causing this ? and what can I do to change that ?