vshader1/fshader1

Ok, so according to the manual (http://www.panda3d.org/manual/index.php/Shader_Basics) you can have fallback shaders - so you define vshader/fshader then vshader1/fshader1 and so on, and if the first pair doesn’t work it then tries the second pair and so on. Problem is I can’t get it to work - I have the shader given below (I didn’t write this, just added the fallback.) and it fails with the usual ‘Cg program too complex’, but if I swap them around so that the fallback pair become the primary pair it does work, albeit with the non-functionality of the fallback. Any ideas what I’m doing wrong?

//Cg
//
//Cg profile arbvp1 arbfp1

void vshader(float4 vtx_position : POSITION,
             float2 vtx_texcoord0 : TEXCOORD0,
             out float4 l_position : POSITION,
             out float2 l_texcoord0 : TEXCOORD0,
             uniform float4x4 mat_modelproj)
{
  l_position=mul(mat_modelproj, vtx_position);
  l_texcoord0=vtx_texcoord0;
}


void fshader(float2 l_texcoord0 : TEXCOORD0,
             uniform float4 k_casterpos,
             uniform float4 k_vlparams,
             uniform float4 k_vlcolor,
             uniform sampler2D k_src : TEXUNIT0,
             out float4 o_color : COLOR)
{
  float decay = 1.0f;
  float2 curcoord = l_texcoord0;
  float2 lightdir = curcoord - k_casterpos.xy;
  lightdir *= k_vlparams.y;
  half3 sample = tex2D(k_src, curcoord);
  float3 vlcolor = sample;
  for (int i = 0; i < k_vlparams.x; i++) {
    curcoord -= lightdir;
    sample = tex2D(k_src, curcoord);
    sample *= decay;
    vlcolor += sample;
    decay *= k_vlparams.z;
  }
  o_color.rgb = min(vlcolor * k_vlcolor.www * k_vlcolor.rgb, k_vlparams.www) * 2.0f;
  o_color.a = 0.0f;
}



void vshader1(float4 vtx_position : POSITION,
             float2 vtx_texcoord0 : TEXCOORD0,
             out float4 l_position : POSITION,
             out float2 l_texcoord0 : TEXCOORD0,
             uniform float4x4 mat_modelproj)
{
  l_position=mul(mat_modelproj, vtx_position);
  l_texcoord0=vtx_texcoord0;
}


void fshader1(float2 l_texcoord0 : TEXCOORD0,
             uniform sampler2D k_src : TEXUNIT0,
             out float4 o_color : COLOR)
{
  o_color.rgb = tex2D(k_src, l_texcoord0);
  o_color.a = 0.0f;
}

Ok, just had a look at Pandas source, specifically the method Shader::
cg_compile_shader - it doesn’t seem to perform the logic suggested by the manual, and only respects vshader/fshader. Could someone who knows the source confirm this? If it is the case the manual needs changing, or, preferably, the feature needs adding - its hardly a complex one compared to the related code! (I’ll do it myself if someone is willing to merge the patch - its only a single method.)

Hmm, this is the first I’ve heard of such a feature. It sure does sound like a swell idea. It looks like the manual change in question was added by Xidram, not too long ago; perhaps he’s working on adding this feature now?

What about it, Xidram?

David

As part of my efforts to renovate the Manual, I reorganised that page to be neater and more open for GLSL expansion; and then I added a little bit of information about bringing GLSL into Panda3D. I have barely any experience with shaders, and my focus is on GLSL; not Cg. To be honest, the only Cg I’d want to learn is that which would allow me to convert others’ Cg shaders to GLSL. I plan to fill in the gaps about GLSL as I learn more about it, but that might not be so soon as I have more pressing matters taking precedence in my life at the moment.

The feature in question regarding fall-back on auxiliary shaders was actually documented in there from ages ago. I merely put the information found on that page into nicer sections.

For the record, this functionality doesn’t exist for a long time anymore. It was removed when Josh overhauled the shader system, I think.

Such a feature would be nice, although GLSL users won’t be able to benefit from it, as GLSL doesn’t allow custom entry point names.

Well, I’ll knock up a patch then if nobody else wants to - its sufficiently easy that testing will take an order of magnitude longer than implementation!