Multi shaders

I have 2 shader file on my terrain: one for multi texture with alpha map (, one for shadow(

I have read this article about multi-pass rendering: … _Rendering

But it is useful for different camera.

And my question is : How to apply two shaders above to my terrain nodepath ?

Multi-pass rendering I think is what you are wanting.

Have a look around for ‘full screen quads’.

Basically the idea is to create a quad that overlays your screen and have the output of a seperate camera render to that quad.

I think the cartoon shader example included in Panda is one where a full screen quad is used.

What Maikeru describes is for post-processing filters, which from your description is not what you want. You can only have one shader that describes how to render a terrain. If you need to apply two effects, you need to write a single shader that performs both of these effects. You will therefore have to merge your shader code.

If however you do want post-processing effects, then look in the manual for FilterManager, it makes this easy.

Thanks rdb, it is the best way in this case.

p/s : now, speed of panda3d’s site is very good, thanks to team.

I got some trouble in combine cg file (terrain + shadow). My terrain doen’st show shadow:

and this is my cg file

//Cg profile arbvp1 arbfp1

void vshader( in float4 vtx_position : POSITION,
	      in float3 vtx_normal : NORMAL,
              in float2 vtx_texcoord0 : TEXCOORD0,
              in float2 vtx_texcoord3 : TEXCOORD3,
              in uniform float4x4 mat_modelproj,
              in uniform float4x4 trans_model_to_clip_of_light,
	      in uniform float4x4 trans_model_to_world,
	      in uniform float3 k_lightvec,
	      in uniform float4 k_lightcolor,	      
	      in uniform float4 k_tscale,	      
	      in uniform float4 mspos_light,	      
	      in uniform float4 k_push,
	      in uniform float4 k_scale,
	      out float4 l_diffuse,
	      out float4 l_lightcolor,
	      out float4 l_mpos,
              out float2 l_texcoord0 : TEXCOORD0,
              out float2 l_texcoord3 : TEXCOORD3,
              out float4 l_shadowcoord : TEXCOORD1,              
	     	  out float4 l_lightclip : TEXCOORD2,
              out float4 l_position : POSITION)

  float4 position = vtx_position * k_scale;

  // worldspace position, for clipping in the fragment shader
  l_mpos = mul(trans_model_to_world, vtx_position);

  vtx_normal.z /= k_scale.z;

  // lighting diffuse
  float3 N = normalize( vtx_normal );
  float3 L = normalize( k_lightvec );
  l_diffuse = max( dot( -N, L ), 0.0f )*k_lightcolor;  
  // Calculate light-space clip position.
  float4 pushed = position + float4(vtx_normal * k_push, 0);
  l_lightclip = mul(trans_model_to_clip_of_light, pushed);

  // Calculate shadow-map texture coordinates.
  l_shadowcoord = l_lightclip * float4(0.5,0.5,0.5,1.0) + l_lightclip.w * float4(0.5,0.5,0.5,0.0);


void fshader( in float4 l_position : POSITION,
              in float2 l_texcoord0 : TEXCOORD0,
              in float2 l_texcoord3 : TEXCOORD3,
              in float4 l_shadowcoord : TEXCOORD1,
              in float4 l_lightclip : TEXCOORD2,
	      in float4  l_diffuse,
	      in float4 l_lightcolor,
	      in float4 l_mpos,	      
              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 tex_4 : TEXUNIT4,
              in uniform sampler2D tex_5 : TEXUNIT5,
              in uniform sampler2D k_Ldepthmap : TEXUNIT6,
           in uniform float4 k_ambientlight,
              out float4 o_color : COLOR )

  // alpha splatting and lighting
  float4 tex1=tex2D(tex_0,l_texcoord0);
  float4 tex2=tex2D(tex_1,l_texcoord0);
  float4 tex3=tex2D(tex_2,l_texcoord0);
  float alpha1=tex2D(tex_3,l_texcoord3).z;
  float alpha2=tex2D(tex_4,l_texcoord3).z;
  float alpha3=tex2D(tex_5,l_texcoord3).z;
  o_color =tex1*alpha1;
  // shadow
  //float3 circleoffs = float3(l_lightclip.xy / l_lightclip.w, 0);
  //float falloff = saturate(1.0 - dot(circleoffs, circleoffs));
  float shade = tex2Dproj(k_Ldepthmap,l_shadowcoord);
  o_color=o_color*(l_diffuse * shade + k_ambientlight);  

I would suggest that try to assign o_color to various things to find out which variable is not correct, in order to isolate the issue.

For one, you can try setting o_color to float4(shade, shade, shade, 1.0). If that correctly shows shadows, then you know that the shadow code works correctly, but that the blending doesn’t. If it doesn’t, you know to look further in the code to find out why ‘shade’ is being assigned incorrectly, etc.

Thanks rdb again, it’s my mistake in shader input. :smiley: