Shader/c++ code error

I am reading a book about making custom filters, however when I run their code I get an error on lines
4, 5, and 14. I believe their is something wrong with how the float value is entered. I do not know c++ so if someone could could help it would be great.

The error is:
filter.cg: (4) : error C0000: syntax error, unexpected integer constant at token""

filter.cg: (4) : error C0501: type name expected at token""

filter.cg: (5) : error C0000: syntax error, unexpected integer constant at token""

filter.cg: (5) : error C0501: type name expected at token""

filter.cg: (14) : error C0000: syntax error, unexpected integer constant at token""

filter.cg: (14) : error C0501: type name expected at token""

This code is saved as a .cg file.


//Cg

void vshader(float4 vtx_position : POSITION,
        out float4 1_position : POSITION,
        out float2 1_texcoord : TEXCOORD0,
        uniform float4 texpad_color,
        uniform float4x4 mat_modelproj)

{
   l_position = mul(mat_modelproj, vtx_position);
   l_texcoord = (vtx_position.xz * texpad_color.xy) + texpad_color.xy;
}

void fshader(float2 1_texcoord : TEXCOORD0,
        uniform sampler2D k_color : TEXUNIT0,
        out float4 o_color : COLOR)
{
   float4 color = tex2D(k_color, l_texcoord);
   o_color = float4(color.r * 1.8, color.g, color.b, * 0.2, color.a);
} 

After further research I maybe calling the shader wrong in python.

Currently my code is:

def setupPostFx(self):
		self.filterMan = FilterManager(self.win, self.cam)
		
		colorTex = Texture()
		finalQuad = self.filterMan.renderSceneInto(colortex = colorTex)
		
		finalTex = Texture()
		interQuad = self.filterMan.renderQuadInto(colortex = finalTex, div = 8)
		interQuad.setShader(loader.loadShader("filter.cg"))
		interQuad.setShaderInput("color", colorTex)
		
		finalQuad.setShader(loader.loadShader("pass.cg"))
		finalQuad.setShaderInput("color", finalTex)

I currently get the same error in the pass.cg as the filter.cg it looks like the float# is the problem. should I be importing a specific python file at the top of the program to solve this?

I believe you need to put “in” in front of your inputs in the cg shader.
Like:

void vshader(in float4 vtx_position : POSITION,
        out float4 1_position : POSITION,
        out float2 1_texcoord : TEXCOORD0,
        in uniform float4 texpad_color,
        in uniform float4x4 mat_modelproj) 

I believe “in” is implied when omitted.

Hmm, I’m not sure, but they look like GLSL errors. Is //Cg the absolute first line in your .cg file? It looks like it’s the third line.

//Cg is the first line of the cg file. I searched around the book more and apparently in the first chapter they wanted me to build panda directly from source code in order for me to modify the shaders. Is this normal practice? I don’t really see how building the panda directly from source code on my system would change anything.

I am currently building panda from source code atm, and I will let you guys know it solves it. I don’t expect it will since panda should just be calling the shader that I made. I suspect that maybe the python code calling the shader is wrong, but I dont know anything about shaders. The book was simply explaining how to create custom shaders but never really got into detail about how each part of code works.

You have an error on this line

o_color = float4(color.r * 1.8, color.g, color.b, * 0.2, color.a);

you have , *0.2 <- dangler