PDA

View Full Version : Raytracer: Get Smooth rather than flat shading?


appleGuy
08-11-2007, 09:23 AM
Hi,

Im developing a raytracer, ive got my phong and lambert shading code down and working, however when im rendering polygons, the appearance is flat, I can see the individual polygons rather than smooth.

Now im currently using the face normal in the shading calculations, which i know is why im getting this flat appearance.

Now im guessing that to get a smooth shade im going to have to interpolate between the vertex normals...is this correct?

Cheers
-Alex

Reedbeta
08-11-2007, 09:49 AM
that is correct.

geon
08-11-2007, 02:11 PM
Just remember to normalize.

dave_
08-11-2007, 04:00 PM
Out of curiousity, why did you ask that question, you really already knew the answer? Why didn't you just try it out? Is there something else that you've not figured out?
It would of probably been only marginally more difficult to implement it than writing that post.

Jare
08-11-2007, 11:42 PM
I guess he asks because he knows the old adage: "Just because it works, doesn't mean it's right."

wintermute
08-21-2007, 12:44 PM
hi
I've some problems with vertex normal interpolation in raytracing:

Every ressource on polygon interpolation you find on the web is on how to do it with scanline algorithms. I quite understand how it works this way but I have difficulties with it in terms of raytracing.

Maybe I found a solution but I have don't know if it is correct:

Given a ray-polygon intersection point "p" and a vertex "v1" of the polygon do the following:

Create a line "l" (v1 - p) and intersect it with each edge of the polygon. Determine the normal at the intersection point "i" by lineally interpolating between the corresponding vertices of the intersected edge.

Now the normal at p can be computed by interpolationg between "i" and "v1"

(the polygon must first be projected onto one of the three coordinate planes of course.)

I have some doubts that this is correct because the other vertex
normals of the polygon (need not be a triangle!) aren't taken into account.

I would be glad if anyone could help me.

Reedbeta
08-21-2007, 01:36 PM
Look up barycentric coordinates with Google. It's really simple; you just need to calculate the barycentric coordinates of the intersection point, then you can use those to interpolate the vertex normals (as well as anything else that needs interpolating between vertices).