[SOLVED] Shader problem

hello,

I’m hoping to get an answer from some of you shader gurus :slight_smile:

here the error message

and here my test shader that comes up with this error

struct appdata
{
    float3 vtx_position : POSITION;
    float4 vtx_color : COLOR;
};

 void main() 
 {  
     gl_Position = ftransform();
 }

ignore the fact that “appdata” isn’t used in this example.

Is declaring a struct with the “input” data for this vertex shader wrong ?

chrys

That looks like a combination between Cg and GLSL. “float3” does not exist in GLSL. It’s “vec3” there. Furthermore, GLSL doesn’t allow binding to an attribute using a semantic string.

You should use gl_Normal, gl_Color and gl_Vertex etc., which you don’t need to declare. This is a normal thing to do in GLSL shaders. I would advise following some GLSL tutorials if you are having trouble with using GLSL.

In 1.8.0 and above, you’ll also be able to declare custom attribs like “varying vec4 normal” and Panda will bind them automatically to a vertex column of the same name.

thanks rdb,

I’ll stick with Cg and experiment with it a bit.

Hello,
I thought I re-open this thread instead of starting a new one.

:gobj(error): Shaders/fpWaterDM.sha: varying in vec4 IN.HPOS: parameter should b
e declared 'uniform'
:gobj(error): Shaders/fpWaterDM.sha: varying in vec4 IN.COL0: parameter should b
e declared 'uniform'
:gobj(error): Shader encountered an error.

here my pixel shader

struct vertexOut
{
    float4 HPOS : POSITION;
    float4 COL0 : COLOR0;    
};

half4 fshader(vertexOut IN) : COLOR
{
  	half4 Out = half4(1,1,1,1);
	return Out;
}

all the CG examples that I have seen do not declare the “vertexOut” members as uniform. Any idea why I get this error ?

chrys

Your shader doesn’t make any sense. “POSITION” is an output semantic for the vertex shader. I’m not sure what that shader’s supposed to do. It’s a fragment shader, yet it has a vertex input? Why do you name your vertexOut parameter “IN”; which one is it, in or out?

I also recommend against using keywords like HPOS as variable names, it’s confusing.

I see why that can be confusing.

I try again :

here the vertex shader

//Cg

struct vertexData
{
    float4 vtx_position : POSITION;
    float4 vtx_color : COLOR;
};

struct vertexOut
{
    float4 HPOS : POSITION;
    float4 COL0 : COLOR0; 
};

vertexOut vshader(vertexData IN, 
            uniform float4x4 mat_modelproj
           )            
 {
	vertexOut Out;

	Out.HPOS = mul(mat_modelproj, IN.vtx_position);  
	Out.COL0 = IN.vtx_color;

	return(Out);
 }

and here my pixel shader

//Cg

struct vertexOut
{
    float4 HPOS : POSITION;
    float4 COL0 : COLOR0; 
};

half4 fshader( vertexOut IN ) : COLOR
{
	half4 Out; 

	Out = IN.COL0;
 
	return Out;
}

the reason why I called it “vertexOut” is because it is what the vertex shader gives as an output result.

How come HPOS is not a good variable name ? I’ve seen other tutorials calling the same variable HPOS - not saying it is therefore a good name.

[EDIT]
I see what you mean - the vertexOut shouldn’t contain the HPOS at all - just the color.
[/EDIT]

Alright I figured it out. I hadn’t considered that panda has got some predefined shader variables.

this now works as intended

//Cg

struct vertexData
{
    float4 vtx_position : POSITION;
    float4 vtx_color : COLOR;
};

struct vertexOut
{
    float4 l_position : POSITION;
    float4 l_color0 : COLOR0; 
};

vertexOut vshader(vertexData IN, 
            uniform float4x4 mat_modelproj
           )            
 {
	vertexOut Out;

	Out.l_position = mul(mat_modelproj, IN.vtx_position);  
	Out.l_color0 = IN.vtx_color;

	return(Out);
 }

and the pixel shader

//Cg

struct vertexOut
{
    float4 l_color0: COLOR0;
};

half4 fshader( vertexOut IN ) : COLOR
{
	half4 Out; 

	Out = IN.l_color0;
 
	return Out;
}

the vertex position could be passed in via the l_position paramter.

I think I’ll have a looong learning curve ahead of me :stuck_out_tongue: