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
Gouraud
Gouraud vs Phong shading
-
- Posts: 164
- Joined: Wed May 05, 2004 5:34 pm
- Location: Germany Berlin
- Contact:
Gouraud vs Phong shading
q|^.^|p beeing every time friendly to everyone
sys: 2500+Barton 512MB 6600GT WinXP
sys: 2500+Barton 512MB 6600GT WinXP
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
-
- Posts: 164
- Joined: Wed May 05, 2004 5:34 pm
- Location: Germany Berlin
- Contact:
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
Gouraud
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.
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 ..
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
Gouraud
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.
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
sys: 2500+Barton 512MB 6600GT WinXP
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
-
- Posts: 164
- Joined: Wed May 05, 2004 5:34 pm
- Location: Germany Berlin
- Contact:
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
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
-
- Posts: 164
- Joined: Wed May 05, 2004 5:34 pm
- Location: Germany Berlin
- Contact:
@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 :
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 :
...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
sys: 2500+Barton 512MB 6600GT WinXP