Why I cannot get the specular reflection right with mesh?

Practical and theoretical implementation discussion.
Post Reply
shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Why I cannot get the specular reflection right with mesh?

Post by shiqiu1105 » Wed Jun 06, 2012 5:18 pm

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)
cup.jpg
cup.jpg (13.46 KiB) Viewed 6928 times

spectral
Posts: 382
Joined: Wed Nov 30, 2011 2:27 pm
Contact:

Re: Why I cannot get the specular reflection right with mesh

Post by spectral » Thu Jun 07, 2012 11:12 am

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 ?
Spectral
OMPF 2 global moderator

dr_eck
Posts: 46
Joined: Mon Dec 05, 2011 7:35 pm

Re: Why I cannot get the specular reflection right with mesh

Post by dr_eck » Thu Jun 07, 2012 2:35 pm

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.

spectral
Posts: 382
Joined: Wed Nov 30, 2011 2:27 pm
Contact:

Re: Why I cannot get the specular reflection right with mesh

Post by spectral » Thu Jun 07, 2012 3:01 pm

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 ;-)
Spectral
OMPF 2 global moderator

shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Re: Why I cannot get the specular reflection right with mesh

Post by shiqiu1105 » Thu Jun 07, 2012 5:39 pm

Thanks guys, for your kind help!

I have found the problem, well, to some extent.

I miscalculated the surface tangent vectors, which lead to false transformation to BRDF space, where I perform vector reflection and refraction.

I now seem to get the correct reflection, as here
glas2.jpg
glas2.jpg (47.42 KiB) Viewed 6856 times
But as to the refraction, I am not sure it's correct:(
It looks mostly okay from the image above, but when I get a closer look, there's just so many chaos and bright dots..
glas.jpg
glas.jpg (64.1 KiB) Viewed 6856 times
Any clues what's causing this guys...?

Geri
Posts: 146
Joined: Fri Mar 02, 2012 7:01 pm

Re: Why I cannot get the specular reflection right with mesh

Post by Geri » Thu Jun 07, 2012 11:39 pm

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
Csontos kezünkbe a nyomor
Ezer év rúnáit véste

shiqiu1105
Posts: 138
Joined: Sun May 27, 2012 4:42 pm

Re: Why I cannot get the specular reflection right with mesh

Post by shiqiu1105 » Fri Jun 08, 2012 5:34 am

I still don't know what's the cause.
However, when I use path tracing with over 1000 spp, the result seems right. @_@
glossy.jpg
glossy.jpg (89.22 KiB) Viewed 6818 times

cignox1
Posts: 15
Joined: Mon Jan 30, 2012 10:11 am

Re: Why I cannot get the specular reflection right with mesh

Post by cignox1 » Mon Jun 18, 2012 9:31 am

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).

Post Reply