Sign in to follow this  
Blain

Cg Problem with params

Recommended Posts

//Cg Vertex Shader void main(in float4 Pos : POSITION, uniform float4x4 ModelViewProj, out float4 oPos : POSITION, out float3 Tex : TEXCOORD0) { oPos = mul(ModelViewProj, Pos); Tex = oPos.xyz; } //Cg Pixel shader void main(in float3 Pos : TEXCOORD0, in sampler1D ColourTable, out float4 Col : COLOR) { Col = tex1D(ColourTable,PerlinNoise(Pos)); } //The problem is I'm not getting any values for "Pos" //fed into the pixel shader and I dont know why. //What is the correct way to do it?

Share this post


Link to post
Share on other sites
Which Cg profile are you compiling against?
Also, did the Cg runtime return any error(/warning) listing after compiling the shaders? Are you using plain Cg or CgFX?

The first thing that bothers my mind is your vertex shader parameter order. The uniform parameters have to go first, then input and lastly the output params(this is especially true when you're using CgFX). As far as I know it is not recommended to read from output parameters, so you should probably go by storing the computed homogenous coordinate in a temp variable and the assign this to oPos and Tex.

Your pixel shader params don't seem good as well. The texture should be an uniform parameter and in the same time the first.

Share this post


Link to post
Share on other sites
//Vertex Shader
void main(in float4 Pos : POSITION,
out float2 TexCoords : TEXCOORD0,
out float4 oPos : POSITION,
uniform float4x4 ModelViewProj)
{
oPos = mul(ModelViewProj, Pos);
}

//Pixel Shader
void main(in float2 Tex : TEXCOORD0,
in sampler1D ColourTable,
out float4 Col : COLOR)
{
Col = tex1D(ColourTable,PerlinNoise(Tex * 256.0));
}


void RenderPlanet(int Level)
{
CGparameter ModelView = cgGetNamedParameter(vertexProgram, "ModelViewProj");
cgGLSetStateMatrixParameter(ModelView, CG_GL_MODELVIEW_PROJECTION_MATRIX,
CG_GL_MATRIX_IDENTITY);

CGparameter Vertices = cgGetNamedParameter(vertexProgram, "Pos");
cgGLSetParameterPointer(Vertices, 3, GL_FLOAT, 0, GLVectors);
cgGLEnableClientState(Vertices);

CGparameter TexUVs = cgGetNamedParameter(vertexProgram, "TexCoords");
cgGLSetParameterPointer(TexUVs, 2, GL_FLOAT, 0, PlanetTexCoords);
cgGLEnableClientState(TexUVs);

CGparameter ColTable = cgGetNamedParameter(fragmentProgram, "ColourTable");
cgGLSetTextureParameter(ColTable, ColourRampTable);

cgGLBindProgram(vertexProgram);
cgGLBindProgram(fragmentProgram);

cgGLEnableProfile(vertexProfile);
cgGLEnableProfile(fragmentProfile);

if (Level==0)
glDrawElements(GL_TRIANGLES, NumData*3, GL_UNSIGNED_INT, GLDrawList[0]);
else
for (int n=0; n<FoundNodeList.size(); ++n)
glDrawElements(GL_TRIANGLES, NumData*3, GL_UNSIGNED_INT, GLDrawList[n]);

cgGLDisableProfile(vertexProfile);
cgGLDisableProfile(fragmentProfile);

cgGLDisableClientState(Vertices);
cgGLDisableClientState(TexUVs);
cgGLDisableTextureParameter(ColTable);
}


// CG ERROR : The parameter used is invalid.
//The problem line is setting the texture uv pointer parameter to "TexCoords"
//What's the problem with it?


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Blain
//Vertex Shader
void main(in float4 Pos : POSITION,
out float2 TexCoords : TEXCOORD0,
out float4 oPos : POSITION,
uniform float4x4 ModelViewProj)
{
oPos = mul(ModelViewProj, Pos);
}

CGparameter TexUVs = cgGetNamedParameter(vertexProgram, "TexCoords");
cgGLSetParameterPointer(TexUVs, 2, GL_FLOAT, 0, PlanetTexCoords);
cgGLEnableClientState(TexUVs);


// CG ERROR : The parameter used is invalid.
//The problem line is setting the texture uv pointer parameter to "TexCoords"
//What's the problem with it?


TexCoords is an *output* value from the vertex shader. You cannot "set" it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this