Shader problem


I have setup some geometry like this

	PT(GeomVertexArrayFormat) array = new GeomVertexArrayFormat();
	array->add_column(InternalName::make("vertex"), 3, Geom::NT_float32, Geom::C_point);
	array->add_column(InternalName::make("normal"), 3, Geom::NT_float32, Geom::C_point);
	array->add_column(InternalName::make("alphaUV"), 2, Geom::NT_float32, Geom::C_texcoord);
	array->add_column(InternalName::make("colorUV"), 2, Geom::NT_float32, Geom::C_texcoord);

	PT(GeomVertexFormat )unregistered_format = new GeomVertexFormat();

	CPT(GeomVertexFormat) format = GeomVertexFormat::register_format(unregistered_format);

	PT(GeomVertexData) vData = new GeomVertexData("myFormat", format, Geom::UH_dynamic);
	GeomVertexRewriter vertices = GeomVertexRewriter(vData, "vertex");
	GeomVertexRewriter normals = GeomVertexRewriter(vData, "normal");
	GeomVertexRewriter alphaUV = GeomVertexRewriter(vData, "alphaUV");
	GeomVertexRewriter colorUV = GeomVertexRewriter(vData, "colorUV");

I have filled in all the data and I can see the geometry rendering on screen.

I have then loaded a texture like this

	PT(Texture) pDirt = TexturePool::load_texture("");

I load my shader like this

	CPT(Shader) myGeometryShader;

	myGeometryShader = ShaderPool::load_shader("");

here the implementation of my shader


void vshader(
    uniform float4x4 mat_modelproj,
    in float4 vtx_position : POSITION,
    in float3 vtx_normal : NORMAL,
	in float2 vtx_texcoord0: TEXCOORD0,
	in float2 vtx_texcoord1: TEXCOORD1,
	out float2 l_texcoord0: TEXCOORD0,
	out float2 l_texcoord1: TEXCOORD1,
    out float4 l_position : POSITION)
    l_position = mul(mat_modelproj, vtx_position);
    l_texcoord0 = vtx_texcoord0;
    l_texcoord1 = vtx_texcoord1;

void fshader(
	uniform sampler2D tex_0 : TEXUNIT0,
	in float2 l_texcoord0: TEXCOORD0,
	in float2 l_texcoord1: TEXCOORD1,
    out float4 o_color : COLOR)
    float4 c0 = tex2D(tex_0, l_texcoord1);   // dirt
    o_color = c0;

with this my model is rendered but instead of the “dirt” texture I see the whole model in a dark blue color.

Anyone knows what I am doing wrong ?


I think I just found the problem after reading again through the manual

I have changed the input parameters from

   in float2 vtx_texcoord0: TEXCOORD0, 
   in float2 vtx_texcoord1: TEXCOORD1,

to this

	in float2 vtx_alphaUV: TEXCOORD0,
	in float2 vtx_colorUV: TEXCOORD1,

in the vertex shader function.

reason is I believe because have defined my own vertex format and in particular

   array->add_column(InternalName::make("alphaUV"), 2, Geom::NT_float32, Geom::C_texcoord);
    array->add_column(InternalName::make("colorUV"), 2, Geom::NT_float32, Geom::C_texcoord);

this isn’t very clear from the manual explanation to be honest, and the shader tutorials are not really documented at all a part the first 3 tutorials.




I’m not sure whether this is your only problem, but you haven’t chosen a good name for your texture coordinates. Panda uses the column name to identify the semantic meaning of each column, so the name is important.

Instead of InternalName::make(“alphaUV”), use InternalName::get_texcoord_name(“alphaUV”), and similarly for colorUV.

But I’m not sure whether you also might need to associate the texture coordinate names with the TextureStage when you use a shader.



	array->add_column(InternalName::get_texcoord_name("alphaUV"), 2, Geom::NT_float32, Geom::C_texcoord);
	array->add_column(InternalName::get_texcoord_name("colorUV"), 2, Geom::NT_float32, Geom::C_texcoord);

now causes the output console to spam

why are those names not chosen very well ?

and what did you mean with

Your first solution is a better solution than mine. Adapt the shader to follow your own naming convention.

My solution is based on getting the fixed-function rendering to support your texture coordinates, which isn’t necessary if you plan on using the shader. (The error message, though, is because you also have to change the GeomVertexRewriter to use the new column name you have created.)


I’ve managed to achieve what I wanted for the moment with my shader but when I switched to use DirectX instead of OpenGL I got some error messages showing.

any idea what that means ? or how to fix it ?

Our DirectX shader support has historically lagged behind our OpenGL shader support. But another community member, zhao, provided some patches a few months ago that I had failed to integrate until now, which might address this issue. When the next buildbot release is ready (presumably tomorrow morning, unless there’s a build issue) you’re welcome to download the latest and see if it works for you.


Many thankyous! With this patch the majority of my shaders work properly in DX9 now.