Jump to content


Raytracer: Get Smooth rather than flat shading?


6 replies to this topic

#1 appleGuy

    New Member

  • Members
  • PipPip
  • 25 posts

Posted 11 August 2007 - 04:23 PM

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

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 11 August 2007 - 04:49 PM

that is correct.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 812 posts

Posted 11 August 2007 - 09:11 PM

Just remember to normalize.

#4 dave_

    Senior Member

  • Members
  • PipPipPipPip
  • 584 posts

Posted 11 August 2007 - 11: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.

#5 Jare

    Valued Member

  • Members
  • PipPipPip
  • 247 posts

Posted 12 August 2007 - 06:42 AM

I guess he asks because he knows the old adage: "Just because it works, doesn't mean it's right."

#6 wintermute

    New Member

  • Members
  • Pip
  • 4 posts

Posted 21 August 2007 - 07: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.

#7 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 21 August 2007 - 08: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).
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users