Why I cannot get the specular reflection right with mesh? back
Board:
Home
Board index
Raytracing
General Development
(L) [2012/06/06] [ost
by shiqiu1105] [Why I cannot get the specular reflection right with mesh?] Wayback!Hi all,
I am having troubling rendering correct specular reflection and refraction with triangle meshes.
I can render the correct reflection and refraction with other implicit surface like spheres though.
The reflected color would appear as if they are not continuous surfaces, but rather seperated triangle faces.
At first I thought it's because I used the surface normal rather than vertex normal. But things are not improved even after I calculated the normals with 3dsmax.
I have doubled checked the normals interpolation within a triangle face, and it's correct.
So I am really beaten this time... Any idea why this is happening?
The wrong result is in the attachment. (a cup mesh with mirror like material)
[IMG #1 cup.jpg]
[IMG #1]:Not scraped:
/web/20201130141532im_/http://ompf2.com/download/file.php?id=20&sid=870b2931610469ab0ff39cdfb6f6e0eb
(L) [2012/06/07] [ost
by spectral] [Why I cannot get the specular reflection right with mesh?] Wayback!I don't see any reflection ?
Maybe add textures/color to some faces before to have a better understanding of the scene.
Are you sure that your normals are :
- normalized ?
- face forward ?
If it works with the sphere, it seems that the problem is not related with your reflection shader !
So, maybe try to "hardcode" some normals, by example add a plan (with mirror) and switch between your code and hardcoded one ?
(L) [2012/06/07] [ost
by dr_eck] [Why I cannot get the specular reflection right with mesh?] Wayback!It looks as if the problem is that you are not correctly interpolating the surface normal.  Look at a triangle in the debugger and make sure that the surface normals at the three vertices are different.  (With the orientation of triangles in your picture, two of the three should be identical and the other one different.)  If you don't have correct surface normals at the vertices, you have three options.
1. Use so many triangles that the surface looks smooth.  This is simple, but will always fail when you zoom in too close.
2. Correct your surface normal interpolation.  This involves storing the surface normal with each vertex and doing a linear interpolation of the three normals where the ray intersects the surface.  Even with surface normal interpolation you still have to have enough triangles; you obviously can't get an accurate model of you reflective cup with six triangles.
3. Use additional primatives.  There are lots of options out there like spline patches.  Unfortunately, this can really slow down your ray tracer.
I would write some unit tests for your triangle class for the following cases:
1. Get the normal at each vertex and make sure that they are correct
2. Get the normal in the middle of the triangle and make sure that it is orthogonal to the z-axis (assuming the cup is a cylinder with the z-axis as its axis of symmetry) and halfway between the vertex normals in the x-y plane.
Then I would write a unit test for your triangle mesh class to make sure that the normal varies continuously across a triangle boundary in the x-y plane.
(L) [2012/06/07] [ost
by spectral] [Why I cannot get the specular reflection right with mesh?] Wayback!Try this:
You can generate "a" normal easily (for test). Use the 3 vertices of the triangle and a cross product to generate the normal
N = faceforward(normalize((v1-v2) x (v3-v2)));
If this work with this new normal ... then your normals are incorrects [SMILEY ;-)]
(L) [2012/06/07] [ost
by Geri] [Why I cannot get the specular reflection right with mesh?] Wayback!seems like the teapot also have the white dots (judging from its top door, left side) so
-there is maybe some floating point calculation issue with the normals
-you should incrase with a bigger displacement based on the normal vector after colliding a surface to avoid self-collision in the next recursion
(L) [2012/06/18] [ost
by cignox1] [Why I cannot get the specular reflection right with mesh?] Wayback!For the white dots: I had similar issues and then I discovered a lot of NaN and INF in the calculations (caused by the mesh imported I was using a the time).
back