PDA

View Full Version : Vertex shader billboard



hif
11-24-2002, 09:08 PM
Hi,
I am trying to create an NVidia vertex shader to render a series of billboards. I am tracking the ModelView matrix and the projection matrix. I am passing in an array of floats that represent the centers of each billboard (x, y, z * 6 vertices for each billboard (each is made of 2 triangles)). The billboarding ran fine in a test application. When I imported it into our game engine it broke. It is not rendering billboards anymore, just different shaped polygons and texturing is not working. Why might this be the case? My rendering code is as follows:
render()
{
GLenum error;
while(error = glGetError());
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_SMOOTH);

glEnable(GL_TEXTURE_2D);

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_DEPTH_TEST);

glDepthMask(1);

glEnable(GL_VERTEX_PROGRAM_NV);

glBindProgramNV(GL_VERTEX_PROGRAM_NV, g_vertex_program);


glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV, g_vertex_state_program, (float*)NullData);
//glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 30, m_FrameNumber, 0, 0, 0 );
glEnable(GL_VERTEX_PROGRAM_NV);

drawAllBillboards(pMesh);
glDepthMask(1);
glDisable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
}

drawAllBillboards()
{
while(glGetError());
GLfloat* v = (float*)pMesh->m_AGPMem->buffer;
glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glVertexPointer(3, GL_FLOAT, 0, v);
glVertexAttribPointerNV(1, 2, GL_FLOAT, sizeof(Vertex4), m_ParticleMultipliers);
glVertexAttribPointerNV(2, 1, GL_FLOAT, sizeof(float), m_CharacterTextures);
pMesh->pTexture->Bind();
glDrawElements(GL_TRIANGLES, pMesh->m_iIndices, GL_UNSIGNED_INT, pMesh->m_Index);
}

My vertex shader programs are as follows:
const unsigned char State1[] =
{
"!!VSP1.0"

// Move RIGHT and UP into R0, and R1. Mask w, so w remains 0.
"MOV R0,c[0];\
MOV R1,c[1];"

// Multiply right, by multiplier.
"MUL R3,R0,c[38].x;\
MAD c[44],R1,c[38].y,R3;"

"MUL R3,R0,c[39].x;\
MAD c[45],R1,c[39].y,R3;"

"MUL R3,R0,c[40].x;\
MAD c[46],R1,c[40].y,R3;"

"MUL R3,R0,c[41].x;\
MAD c[47],R1,c[41].y,R3;"

"MUL R3,R0,c[42].x;\
MAD c[48],R1,c[42].y,R3;"

"MUL R3,R0,c[43].x;\
MAD c[49],R1,c[43].y,R3;"

"END"
};

const unsigned char AlignedBillboards[]=
{
"!!VP1.0"

"ARL A0.x,v[1].x;" // copies index

"MUL R0,c[A0.x+44],v[1].y;"
"ADD R1,R0,v[0];"
//"MOV R1, v[0];"

//Convert new position into clip space, with concatenation of modelview and projection matrix.
"DP4 o[HPOS].x,R1,c[4];\
DP4 o[HPOS].y,R1,c[5];\
DP4 o[HPOS].z,R1,c[6];\
DP4 o[HPOS].w,R1,c[7];"

//Pass input color straight out.
"MOV o[COL0],v[COL0];"

//Calculate texture coords.
//R0 = The starting texture coordinates
//Inc R0 by the offset vector for this vertex and store this as the
// output texture coordinates

"MOV R0, c[30];"

//R1 = Current frame

"MUL R1, c[29], R0;"

// R0 = top of texture at start of correct frame

"MOV R2, v[2].xxxx;"

"MUL R3, R2, c[37];"

"MOV R1.y, -R3;"

// R1.y = Character texture * frame height
// R1 = texture coordinate of top left corner of frame

"ADD R4, R1, c[A0.x + 31];"

// R1 = texture coordinate for this vertex

"MOV o[TEX0].xy,R4;"

"END"
};

Thanks for any help,
Hamish