Jump to content
  • Advertisement
Sign in to follow this  
Blain

Cg Problem with params

This topic is 4487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!