Jump to content
  • Advertisement
Sign in to follow this  
Josh Klint

Coding Gouraud or Phong shading on a polygon

This topic is 2039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm implementing smooth groups for our lightmapper.  This means each face's normal needs to be interpolated across a face for the lighting equation, instead of just using the flat polygon normal.

 

Our lightmapper works on BSP-style, where each side is coplanar and can have any number of sides.

 

So my question is, is there a simple way to do Gouraud or Phong shading on a coplanar polygon?  Is there any other routine that can calculate this?  I tried messing around with a vertex distance method, but I don't think that will work.

Share this post


Link to post
Share on other sites
Advertisement

So my question is, is there a simple way to do Gouraud or Phong shading on a coplanar polygon?

I had to re-read that a few times.

 

Coplanar polygons are flat by definition.  Any automatic processing will produce flat shading ... because it is flat.

 

Artists can include vertex normals for you to use at every corner. Maya and other 3D tools can generate vertex normals for you.

 

If you go that route you might as well use SH lighting shader and modern lighting techniques, rather than those two techniques pioneered in the 1970's.  I mean, they are great when you don't have 3D hardware available, but the reason for programmable shaders was so we could advance past those techniques.

Edited by frob

Share this post


Link to post
Share on other sites

I have to calculate this on the CPU because it's for calculating lightmapping on a curved surface.

 

To make matters worse, the pixels are not guaranteed to be inside the polygon.  There's a bit of a bleed border where lighting is calculated beyond the bounds of the polygon.

Edited by Josh Klint

Share this post


Link to post
Share on other sites

In that case you are breaking up the polygon in code. You will need to calculate the new normal at each vertex and store that for use with your shader.  

 

But what do you calculate for that normal?

 

There is no easy solution to that problem.  Something may be broken up along a smooth curve, or along a hard edge. That's why artists usually specify vertex normals, rather than code.

Share this post


Link to post
Share on other sites

Well, I did have to write a full Gouraud implementation.  It took about 100 lines of code.

 

I still have problems with luxels that aren't within any single triangle.  To fix that, I think I will have to find the closest triangle, and use the closest point on that triangle for the normals calculation.

Share this post


Link to post
Share on other sites

I have been waiting years to use smoothing groups with CSG. :D

 

Will post a full blog about what I did.

 

[attachment=15724:lightmap7.png]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!