Gouraud vs Phong shading

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

Gouraud vs Phong shading

Post by LordNaikon »

Hi

I was a long time absent from irrlicht and in general 3D stuff. currently im back and try to better understand 3D in general.

so i decided to write a software renderer/rasterizer to get an idea of lots of basic important stuff.

my basic software renderer/rasterizer is working and now i try to implement some shading/lightning.

i implemented both, gouraud and phong shading. let the specular part aside poth look the same?! is this right? i thought these blocky steps between the poly edges are also removed with phong shading, not only the better locking with specular light reflection.

whats the problem my understanding of how phong should look like .. or my implementation?!

Phong
Image
Gouraud
Image
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

With phong, the normal is interpolated across the triangle per pixel. It seems like your phong lighting is still doing per-vertex.
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

Post by LordNaikon »

you'r the same opinion ...

actually i DO interpolate the normals per pixel!

besides i implemented specular lightning, and this seems to behave like i exspected. (in comparison to gouraud shading)
in phong you can see this specular reflects from the light as little highlighted dots, which is impossible in gouraud shading, where only the vertexes can be "white colored". in phong, these dots can simply cross over the polygon cuz of the interpolated normal in every pixel. beside this the "shadowedges" looks much smoother with phong, my problem is the appearance of visible vertexes and poly edges .. :(

Phong
Image
Image

Gouraud
Image
Image


i think this is a proof of existing (maybe wrong) interpolated normals per pixel. the question is, how to do the right interpolation?! Am I right that in phong you should not see the vertexes and edges from the polys, what could be the mistake?

what i did is(like i did in gouraud), take a vertex, get all connected polys and its normals and get the averange normal for that vertex from all poly normals.
to interpolate for every pixel i walk on 2 edges from A to B and from A to C and interpolate the normals between. then i interpolate from point AB to AC to get all pixel normals.
Image

is that the right procedure? to be honest, i didn't read much of implementations of this before cuz i wanted my mind to be free and think on my own .. how can i do this ..
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

You interpolation does seem correct, yes, but I'm not exactly and expert :lol: . The visible vertices and edges leads me to believe that your method is correct and the model's normals are incorrect. Have you tried another model?
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

Post by LordNaikon »

yes i have used other models .. same here

i calculate the model normals my self
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

I know the problem
in the pixel shader you get an interpolated normal, the thing about normals is that their length must == 1

visualize this 2D situation vertex A and B, A has a normal of -0.707,0.707 and B has a normal of 0.707,0.707 and you are currently shading a spot right in the middle of this line with an interpolated normal of 0.0,0.707.... oops, the normal is short! even though you can do dot products per pixel, you need to normalize your normal every pixel.

The artifacts on your model are a classic example of that
LordNaikon
Posts: 164
Joined: Wed May 05, 2004 5:34 pm
Location: Germany Berlin
Contact:

Post by LordNaikon »

@devsh:
yeah, you are totally right. i dont normalize that interpolated normal after its "interpolation".

when i have time to go on (like tomorrow or so) i will do that! big thanks for that hint! i think thats the problem, too ... without really implemented that!

if i had spend only a few moments for reading ... like wiki ... i could have saved yours and my time :roll: :
...The surface normal is interpolated and normalized at each pixel and then used in the Phong reflection model to obtain the final pixel color. ...
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
Post Reply