Archived

This topic is now archived and is closed to further replies.

steli

OpenGL Vertex and Pixel Shaders in OpenGL

Recommended Posts

see the nvidia + ati websites also check www.opengl.org
btw theyre called PROGRAMS in opengl not shaders (just in case u have trouble finding the word shaders )

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
Use ARB extensions.
ARB_vertex_program
ARB_fragement_program

BTW those are the correct names for the functionalities, just stop using the lame M$ marketing names, please.


SGI OpenGL Extensions Registry:
http://oss.sgi.com/projects/ogl-sample/registry/

-* So many things to do, so little time to spend. *-

Share this post


Link to post
Share on other sites
I''ve been using ARB_vertex_program, but from my searches of ATI and NVIDIA didn''t have much on ARB_VERTEX_PROGRAM....they have lots on their own: ATI_fragment_shader, EXT_vertex_shader, but i I have herd that these ones are depricated... You can get infomration on ARB_Vertex_PROGRAM here: http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt

but it doesnt give any concret examples. I''m looking for some tutorials myself, so if you find some, please post. Here''s a sample of a simple vertex_program (for a diffuse light) i got working (note that it''s far from correct or optimized).



Sorry the code below is really sloppy, it was just a rough protype to try to get vertex programs to work. If anybody knows how to query a bunch of lights that change position every frame, please let me know. Also i did this on a Mac with OS X, so the vertex_program where included, i think on windows u got to get them through extension.


void glEnableGLVertexProgramARB(unsigned char *string)
{
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(string), string);
glEnable(GL_VERTEX_PROGRAM_ARB);
}

void draw() {
//myVertexProgram --> is of type char * and contains the vertex program,
//I send the program to the card each time so i can change the location of the light, but there is a better way to do this (i havent figured it out yet)
glEnableGLVertexProgramARB(myVertexProgram);
// Draw geometry here
glDisalbe(GL_VERTEX_PROGRAM_ARB);
}


char myVertexProgram[1024];

sprintf(myVertexProgram, "!!ARBvp1.0\nATTRIB vertexPosition = vertex.position;\nTEMP transformedPosition, temp, test, lightVector, dot, length, oneOverLength;\nPARAM lightColor = { 0.0, 0.0, 1.0, 1.0 };\nPARAM lightBrightness = { 0.5, 100.0, 100.0, 100.0 };\nPARAM lightLocation = { %lf, %lf, %lf, 0.0};\nDP4 transformedPosition.x, state.matrix.mvp.row[0], vertexPosition;\nDP4 transformedPosition.y, state.matrix.mvp.row[1], vertexPosition;\nDP4 transformedPosition.z, state.matrix.mvp.row[2], vertexPosition;\nDP4 transformedPosition.w, state.matrix.mvp.row[3], vertexPosition;\nMOV result.position, transformedPosition;\n#MOV temp, vertex.color; # Marker #2\nSWZ temp, vertex.normal, x,y,z,1; # Marker #1\nADD lightVector, vertexPosition, -lightLocation;\nDP3 length, lightVector, lightVector;\nRSQ oneOverLength, length.x;\nMUL lightVector, lightVector, oneOverLength;\nDP3 dot, vertex.normal, lightVector;\nMUL dot, dot, lightColor;\nMUL dot, dot, lightBrightness.x;\nSWZ result.color, dot, x,y,z,1;\nEND",
-location->x, -location->y, -location->z);

Share this post


Link to post
Share on other sites
Also a document on the difference between DX8 And OpenGL vertex Shader/Program

http://developer.nvidia.com/view.asp?IO=vertex_shader_api_diffs

Share this post


Link to post
Share on other sites
try
www.delphi3d.net
www.nutty.org etc perhaps they have examples?

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites