Archived

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

Todd Casey

Cube Vertex Normals

Recommended Posts

Todd Casey    122
When rendering a cube using vertex indices for an 8 vertex cube what is the proper way to compute the vertex normals? Should the normals be pointing away from the corners (out and away at a 45 degree anble from one of the edges). I guess to do that you would take the average of the 3 vertices that connect to that corner and that would be the normal? Thanks for any info. Todd

Share this post


Link to post
Share on other sites
Todd Casey    122
I don''t know what I was thinking earlier but I now know I should just use the actual vertex as the normal (of course normalize it). This looks correct in my tests but if I am still wrong please let me know.

Todd

Share this post


Link to post
Share on other sites
Todd Casey    122
Well, I am using gouraud shading which uses vertex normals for lighting calculations if I am not mistaken whereas flat shading uses face normals. I have tried it both ways and man the vertex normal vs. face normal way is no comparison. The vertex normal way looks much better with lighting and such. Please correct me if I am wrong though.

Todd

Share this post


Link to post
Share on other sites
rowbot    122
well, as far as I understand, gouraud shading is used for approximating curved surfaces. Instead of calcutating the light intensity for every pixel of the surface you just calculate it at the vertices and interpolate between them. Thats where the vertex normals come in. You use them if you want to pretend that the normal to the surface is not constant at all points on the surface. Since youre just dealing with a flat sided cube, your face normals should be the same everywhere. But if it looks cooler thats all that matters

ro

Edited by - rowbot on July 21, 2000 11:44:29 AM

Share this post


Link to post
Share on other sites
ByteMe95    122
Can you actually use the normalized vertex itself rather than computing the vertex normal??

I havent heard of that approach before

Todd: Just out of curiosity, what are you using to code this (DX, GL, or doing it yourself?) and what mode, 8bit, 16, 24, or 32?



ByteMe95::~ByteMe95()

Share this post


Link to post
Share on other sites
Gladiator    127
Hey Rob, could you try and look into my thread named "Vectors!!" and see if you can help me out with this one? I''m kinda stuck at the moment... hmm...

----------------------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
bishop_pass    109
quote:
Original post by ByteMe95

Can you actually use the normalized vertex itself rather than computing the vertex normal??




That only works with spheres that are centered on the origin.



Share this post


Link to post
Share on other sites
Todd Casey    122
ByteMe95:
You said above: "Can you actually use the normalized vertex itself rather than computing the vertex normal??". What is the difference between the normalized vertex and computing the vertex normal. Are those not the same thing (if not what is the difference)? Would both ways not involve normalizing the vector to get the vector normal?

Todd

Share this post


Link to post
Share on other sites
zerwit    122
Using the vertex normal usually does not look good unless your angles are greater than 90 degrees. Wierd artifacts appear on a cube if you use vertex normals. You should create more vertices so you can have a surface normal for each face.

*** Triality ***

Share this post


Link to post
Share on other sites
rowbot    122
quote:
Original post by Todd Casey

What is the difference between the normalized vertex and computing the vertex normal. Are those not the same thing (if not what is the difference)? Would both ways not involve normalizing the vector to get the vector normal?




No, they are not the same thing. Normalizing a vector means to make it into a unit vector i.e. a vector of length 1. A vertex normal is an extra bit of information carried in the vertex structure that tells the rasterizer how to compute the lighting for that point.

ro

Share this post


Link to post
Share on other sites
Todd Casey    122
Well that makes a lot more sense. I''ve seen for awhile the D3DVERTEX structure setup with the normal member set to something like (0, 0, 1). I have been putting the actual normal for that vertex in that field. So the correct way to setup the normal member in the D3DVERTEX structure is to give it the direction that the untransformed vertex is facing?

Todd

Share this post


Link to post
Share on other sites
rowbot    122
quote:
Original post by Todd Casey

So the correct way to setup the normal member in the D3DVERTEX structure is to give it the direction that the untransformed vertex is facing?



if you mean the direction the coresponding face of the cube is facing (i.e. the surface normal) then yes. But if youre not going to use gouraud shading then you can use D3Ds flexible vertex format so that you dont have a normal in the vertex structure at all. I think D3D should calculate the surface normal by itself from the vertices you give it. I''m pretty sure of this. Do some research on the flexible vertex format.

Have fun,
ro

Share this post


Link to post
Share on other sites
Todd Casey    122
Here is a screen shot to a little test application I made:

http://www.jack-bilt.com/todd/lighting.jpg

The cube on the left is using the normalized vertex whereas the cube on the right is using the vertex normal (the one on the left is using DrawIndexedPrimative() and the right is using DrawPrimative()). Which one is the proper one (for Gouraud shading mode)? The one on the right seems to be flat shaded am I correct? If you want to run the actual program you can grab it here:

http://www.jack-bilt.com/todd/Lighting.exe

It requires DirectX 7.0 and a 3D accelerator.

From what I have gotten from this thread I believe that the proper way everyone is saying it should be done is the way the cube on the right is done. I''m really confused if this is true because the right cube is simply flat shaded whereas the left cube is using vertex blending is it not? I guess what I have found is Gouraud shading mode can have filled triangles and then blended triangles is this correct? If this is true then which type to 3D games ususally use? Thanks again for everyone helping me through this!

Todd

Share this post


Link to post
Share on other sites
Todd Casey    122
I see how D3D is shading the two cubes. If all of the normals (of a triangle) are pointing in the same direction is uses flat shading but if the vertices are not pointing it interpolates between the vertices and creates the gouraud shading (assuming gouraud shading is enabled). Thanks again.

Todd

Share this post


Link to post
Share on other sites