cg compilation error.

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 ?

This is what I get:

:gobj(error): /home/pro-rsoft/test.cg: (126) : error C5208: Sampler needs to be a uniform (global or parameter to main), need to inline function or resolve conditional expression
:gobj(error): /home/pro-rsoft/test.cg: (136) : fatal error C9999: unable to generate code for texture function.

This error comes from the Cg compiler, not panda. It means declaring a sampler inside a function body isn’t valid, at least not in the arbvp1/arbfp1 profile, which is the default profile if basic-shaders-only is set to #t.
If there is a profile which does allow declaring samplers like that, you need to set it at the top of your cg shader, with //Cg profile.

I can’t reproduce the crash here - maybe it’s already been fixed on the CVS trunk. Try this build. (i386 only)
breeze.aff2aw.com/affdata/prorso … y_i386.deb

Oups, something must be wrong, I get

from direct.directbase import DirectStart

DirectStart: Starting the game.
:display(warning): Unable to load: /usr/lib/panda3d/libpandagl.so: undefined symbol: _ZN17glxGraphicsPixmap12_type_handleE
Known pipe types:
(all display modules loaded.)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "linuxroot/usr/share/panda3d/direct/directbase/DirectStart.py", line 4, in <module>
  File "linuxroot/usr/share/panda3d/direct/showbase/ShowBase.py", line 229, in __init__
  File "linuxroot/usr/share/panda3d/direct/showbase/ShowBase.py", line 692, in openDefaultWindow
  File "linuxroot/usr/share/panda3d/direct/showbase/ShowBase.py", line 777, in openMainWindow
  File "linuxroot/usr/share/panda3d/direct/showbase/ShowBase.py", line 534, in openWindow
  File "linuxroot/usr/share/panda3d/direct/showbase/ShowBase.py", line 467, in makeDefaultPipe
  File "linuxroot/usr/share/panda3d/direct/directnotify/Notifier.py", line 130, in error
StandardError: No graphics pipe is available!
Your Config.prc file must name at least one valid panda display
library via load-display or aux-display.

Config.prc:

load-display pandagl

Yeah, I noticed. Give me a few hours/days to fix.

For the record, that bug has been solved for the upcoming 1.6.1.