Skip to main content
gamedev.net
🔒 Locked

simulating FFP with NV_vertex_program

Started by remdul Oct 25, 2005 at 10:18 AM 3 replies 600+ views
Original Post
remdul
remdul
To my surprise I've been unable to find, after 2 days of Googling, any vertex program source/demos etc that do the same thing as the fixed function pipeline. Basicly I want my engine to render exactly the same thing when I enable NV_vertex_program (single light source + scene ambient light + texture0 + specular + fog). No fancy bump mapping or anything, just the basic stuff. I'm still struggeling with this a bit (lighting in particular), think its a good thing understanding the basics before I move on to new shader versions and the more advanced effects, but I'm getting nowhere without a solid example that explains just the basics. Links, code is welcome.
paic
paic
Hi,

You won't find shader codes that explicitly reproduce the FFP. But you'll find a lot of tutorials that deal about lighting in vertex shaders. And the FFP's lighting is nothing more than simple per-vertex lighting.

For example, you will find the equation :

diffuse = max(0, dot(lightDirection, -transformedVertexNormal));

in a lot of shaders. And it's exactly what the FFP do for the diffuse lighting.
Find tutorials about specular lighting, about ambient lighting, and simply code that in a VERTEX shader, and you'll have the same lighting as the FFP ^^
remdul
remdul
Well, yes, thats exactly what I've been trying today, but I didn't get much further than this:

!!VP1.0# modelview matrix c[0] ... c[3]# projection matrix c[4] ... c[7]# light position c[8]# transform vertsDP4 o[HPOS].x, c[0], v[OPOS];DP4 o[HPOS].y, c[1], v[OPOS];DP4 o[HPOS].z, c[2], v[OPOS];DP4 o[HPOS].w, c[3], v[OPOS];# normalsDP3 R1.x, c[0], v[NRML];DP3 R1.y, c[1], v[NRML];DP3 R1.z, c[2], v[NRML];# light directionDP3 R1.w, c[8], R1;# multiply with colorMUL o[COL0].xyzw, R1.wwww, v[COL0].xyzw;# textureMOV o[TEX0], v[TEX0];END


Texturing works, and I can probably figure out fog and ambient myself, but I have a hard time transforming the vert normals properly. The above code does 'light' my objects, but the light position moves along with the camera, so I figured I'll have to do something with the projection matrix. Also, the resulting vertex colors are either black or white, not much in between. I guess I have to normalize something?

Oh, and specular. I want it to be 'on top' of the texture (like the seperate_specular extension). How do I do that?
paic
paic
I don't read asm as easily as C / C++ like language, so, sorry, but I can't help you on this ^^

For specular, there are really tons of tutorials about that on the web, you shouldn't have any difficulty to find one.
Basically, compute the vector going from the eye to the vertex. Compute the reflection of this vector on the vertex, and do a dot product with the light Direction. add a pow(result, X) to increase the sharpness of the specularity.

For the transformation of the normals, you should juste multiply the vertex normal with the model matrix and the beginning of the vertex shader, that's all.
Dybbuk
Dybbuk
Is this what you need:


http://developer.nvidia.com/object/cg_fixed_function.html

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.