Per-vertex lighting???!!??

Started by
8 comments, last by Lurking 22 years, 6 months ago
hey, i was wondering if any one here could point me in the direction of a tutorial about setting up a per-vertex light system. That would be great if you could...! - Lurking
- Lurking
Advertisement
Go here: http://www.ronfrazier.net/apparition/index.html?appmain=research/index.html Not sure if you know about this site or not but what the heck. Also the nvidia''s developer''s site; I think www.nvidia.com/developer , has some useful presentations and articles on register combiners. As for setting it up I wouldn''t know (I''m dx guy) but www.opengl.org forums might turn something up.
Oops, seeing "vertex lighting" and thinking "per pixels lighting" sorry If you''re doing per vertex lighting then are you doing gouraud or flat shading? If flat you don''t need vertex normals as the color comes from the first vertex, I think. If doing gouraud then you need to assign each vertex a normal so it has (x, y, z, nx, ny, nz) elements. Then you need to enable lighting in the api with gl_ligthing(enable) or some such Also you need to give a position of the light and possibly a direction depending on light type(point, directional, etc.) You can enable ambient light and use flat shading without enabling lighting calculations on normals. This way the poly will emit light. You can also do texture mapping lights or darkmapping where you combine a texture with a lightmap. You do this if you don''t want to tesselate you geometry to small triangles so that the lighting(enabled now) looks good. Sorry if you knew this already. If not the red book has more info and specifics on this.
Per-polygon shading: flat
Per-vertex shading: gouraud
Per-pixel shading: phong

Personally, I don''t know why you want to do research on per-vertex lighting... OpenGL''s hardware accelerated lights are based on per-vertex lighting as it is. Now, per-pixel lighting on the other hand is an extremely hot topic!

------------------------------
Trent (ShiningKnight)
E-mail me
ShiningKnight Games
really i am in a group right now of newbie developers and we split resposibilities on the new engine. I got per pixel lighting but i dont know how to do it. I went to the nvidia developer site and it told me that i should learn per vertex lighting first so i came here to find tutorials from forum. Thanx for the help but if you have anymore please send it to me or post here...

- Lurking
- Lurking
per vertex lighting is pish

as long as u specify a normal for every vertex OpenGL does the rest
void DrawCylinder(float radius, float height, int slices, int top, bool lighting, int draw_type)
{
float DEGTORAD = 0.0174532925199432f;
float angle_c = 360.0f/(float)slices;
glBegin(draw_type);
for (float ix = 0; ix < 360; ix += angle_c)
{
if (lighting)
glNormal3f(cosf(DEGTORAD * (ix + angle_c/2.0f)), 0.0f, sinf(DEGTORAD * (ix + angle_c/2.0f)));

glTexCoord2f(ix/360, 0);
glVertex3f(cosf(DEGTORAD * ix) * radius, height/2, -sinf(DEGTORAD * ix));

glTexCoord2f(ix/360, 1);
glVertex3f(cosf(DEGTORAD * ix) * radius, -height/2, -sinf(DEGTORAD * ix));

glTexCoord2f((ix + angle_c)/360, 1);
glVertex3f(cosf(DEGTORAD * (ix + angle_c)) * radius, -height/2,
-sinf(DEGTORAD * (ix + angle_c)) * radius);

glTexCoord2f((ix + angle_c)/360, 0);
glVertex3f(cosf(DEGTORAD * (ix + angle_c)) * radius, height/2,
-sinf(DEGTORAD * (ix + angle_c)) * radius);
}
glEnd();

if (top)
{
glPushMatrix();
// draw top side
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, height/2);
DrawDisc(0.0f, radius, slices, draw_type);

// draw bottom side
glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, height);
DrawDisc(0.0f, radius, slices, draw_type);
glPopMatrix();
}
}

How could I give each vertex a normal? Right now it''s a normal per 4 vertices
quote:Original post by Lurking
really i am in a group right now of newbie developers and we split resposibilities on the new engine. I got per pixel lighting but i dont know how to do it. I went to the nvidia developer site and it told me that i should learn per vertex lighting first so i came here to find tutorials from forum. Thanx for the help but if you have anymore please send it to me or post here...

- Lurking


Obviosuly, he meant per-pixel lighting.

In that case, Lurking, the first post by JD should have what you want. However, it sounds to me like trying to do per-pixel lighting is way over your head. "Newbie" and "per pixel lighting" (or anything else cutting edge) generally don''t mix too well!!!

I''m a decent coder, I think, but I haven''t even attempted using nVidia or ATI''s crazy vertex and pixel shader extensions.

Maybe that''s because I have a TNT2!!!!

Speaking of my TNT2... be warned that by using per-pixel lighting you are limiting your audience to GeForce3 and Radeon2 users, unless you use an alternate method for lower end cards (like my TNT2) like using gaurad shading or lightmaps.
You are in a way somewhat right when you talk of the Newbie status but not completely. I dont think of myself as total newbie cause i can do alot on my own but i have only been coding opengl for about 1/2 a year. I am developing a light class for a project i am working on and my team thought it nice to atleast attempt to look at what it takes to make it (per pixel lighting). Well i do have a geforce3 and have all the sdk and looking at all the source they can spit out of their company. Any tips or places to read about it would be great. I might not understand it completely but i gives me a direction in where and what to learn to understand it. So if you can help me i am at much thanx to you.

- Lurking
- Lurking
unless you particularly want to learn how to write pixel shaders, i suggest that you look at lightmaps instead. Nate Miller (http://nate.scuzzy.net) has got a couple of tutorials on them. Also, lightmaps are supported by all hardware (because your essentially drawing a polygon over another polygon)

Hope it helps


MENTAL

This topic is closed to new replies.

Advertisement