Pixel Shaders

Hi all,

I am trying to get pixel shaders working, but am stuck…

I have a cg pixel program
#pragma bind v2f.TexCoord0 = TEX0

#pragma bind main.TexMap = texunit 0

struct v2f_simple : vertex2fragment
{
float4 TexCoord0;
};

fragout main(v2f_simple IN,
uniform sampler2D TexMap)
{
fragout OUT;
float4 texcolor = tex2D(TexMap);
OUT.col = float4(1.0,0.0,0.0,1.0);//texcolor;
// OUT.col = texcolor;

return OUT;
}

and I use the cg compiler to compile it to
dx8ps

then read in the output of the compiler and
do this

char *pscode = readFfromfile(“test.pp”);

UINT idx = glGenLists(1);
glNewList(idx,GL_COMPILE);
nvparse(prog);
glEndList();
for (const char** errors= (const char **) nvparse_get_errors(); *errors; errors++)
printf("NVPARSE ERRORS %s
",*errors);

I get no parse errors - so then I render my stuff doing this…

glDepthFunc(GL_LEQUAL);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);

glCallList(idx);
glEnable(GL_TEXTURE_SHADER_NV);
glEnable(GL_REGISTER_COMBINERS_NV);

glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ZERO);
mesh_st* m = getMyMeshObj();
//Get the texture ID
UINT tid = m->shdr.diff_tex;
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,tid);

glEnableClientState(GL_VERTEX_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex_st), &(m->vlist[0].uv[0]));
glVertexPointer(3, GL_FLOAT, sizeof(vertex_st),&(m->vlist[0].position[0]));
glDrawElements(GL_TRIANGLES, 3*m->numFaces, GL_UNSIGNED_INT, m->flist);

glDisable(GL_REGISTER_COMBINERS_NV);
glDisable(GL_TEXTURE_SHADER_NV);

And Low and behold, it doesn’t work
If I comment out enabling texture shaders
and reg combiners, it draws the mesh
with the current enabled texture as you would assume.

But with the code as above it doesn’t render anything.

I’m guessing I am missing something that I need to initialize. Any help would be appreciated.

Thanks,

-Joe

Cg Pixel shaders are not (yet) implemented in OpenGL. Blame nVidia.

Ummm… Actually if you read the CG faq at cgshaders.org and some posts from nvidia guys, you can compile cg pixel programs with the dx8ps profile and then use them in the latest version of nvparse ( which sets up the appropriate reg combiner and texture shader states)

So that is what I’ve done… but it still doesn’t work. not sure why. That is why I posted here

Why can’t they just implement this intermediate stage in the Cg profile? It’s ridiculous to have to compile to dx ps and then use nvparse to compile these into reg combiner/tex shader states…

Well, i don’t think its that big of a deal. If you are using visual c++ you can easily create a custom build step to do the compilation for ya. So there’s not much difference once that is set up. The thing is there are no examples yet using nvparse to load the pixel shaders…

Since cg generates the pixel shader
mov r0, c0
my guess would be that c0 isn’t being initialised. I don’t know how nvparse is actually configuring the register combiners, but I suspect that it expects c0 to be in GL_CONSTANT_COLOR0_NV.

Try

GLfloat red[4] = { 1, 0, 0, 1 };
glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, red);

I wonder if there’s a way to get cgc to output the constant definition. (nvparse will apparently read them.)

But I still don’t know why it doesn’t work when you use the texture instead of a constant colour.

no,cg pixel shaders = gl texture shaders + gl register combiners. nvparse is supposed to set all that for you…