Shaded Lightmaps

Started by
7 comments, last by Facehat 21 years, 2 months ago
I'm having a bit of trouble finding out how to do this, so I'll post this question and hope that it hasn't been asked too many times before. Right now I've got a lightmapper set up to create a lightmap for each triangle. Everything is working fine, except right now I'm just using the overall polygon normal to calculate influence that the light has on a surface -- in other words, its just flat shaded. What i'd much rather do is interpolate the vertex normals across the surface for each point so that I get a much smoother result. The problem is, I haven't got the foggiest idea how to actually do that. So my question essentially is, given a point in worldspace (L) on a triangle, how can I find the interpolated normal vector for it given three triangle vertices (V1-V3) and their 3 normals (N1-N3)? ---------------------------------------- "Before criticizing someone, walk a mile in their shoes. Then, when you do criticize them, you will be a mile away and have their shoes." -- Deep Thoughts "If you have any trouble sounding condescending, find a Unix user to show you how it's done." - Scott Adams FaceHat Software -- Wear the hat. [edited by - The Senshi on February 2, 2003 6:25:22 PM]
Advertisement
I''m not quite sure what your asking. Mainly because the lingo is different than how I did my lightmapping.

a good tutorial here goes over how to shade your lightmapping correctly. It''s all done in texel space.

ehhh.. hope that helps.

~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave
==Colt "MainRoach" McAnlisGraphics Engineer - http://mainroach.blogspot.com
Thanks for the link, although thats not quite what I was asking for .

I'll try to explain a bit better: right now my lightmaps are generating OK. However, on curved surfaces I get a sort of "banding" effect because I'm only doing flat shading right now -- no gourad or phong shading, so something like a sphere ends up looking like this:

What I'm trying to do is use phong shading instead, so that the light will fall smoothly across it and it'll look like an actual curved surface. However, I don't know the math needed to interpolate the 3 normals from the vertices across the surface. So essentially, what I'm trying to figure out is how to find the interpolated normal for any point inside a triangle.

If you guys still don't have any clue what I'm talking about, I'd appreciate it if you could at least point me to some detailed articles on phong shading . I've been through google, but most the articles I saw didn't cover how to actually find N (the normal), which is exactly what I need to know.

----------------------------------------
"Before criticizing someone, walk a mile in their shoes.
Then, when you do criticize them, you will be a mile away and have their shoes." -- Deep Thoughts
"If you have any trouble sounding condescending, find a Unix user to show you how it's done." - Scott Adams
FaceHat Software -- Wear the hat.

[edited by - The Senshi on February 2, 2003 12:04:02 AM]
Not totally sure about this, but you should be able to get the average of the normals of all the faces surrounding the vertex you are computing for.
senshi,
I''ve never seen that ring effect. Especially when using the link above. Although it doesn''t do directly what you''re asking (interpolating per pixel) it does attenuation based upon spherical distance. If used, it wouldn''t create that banding effect that you''ve got there (i''ve used it on spheres before)

was hopin the link was a different direction you hadn''t thought about.

As per the current question, i''m not quite sure about interpolation per pixel. Only thought i can come up with, is choosing a side (AB out of ABC triangle) which contains all the points along that line. Move the line towards C, and each step, clip the outside values. (that is, the parts of AB that lie beyond BC, and AC)

that''s jut theory though.
~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave
==Colt "MainRoach" McAnlisGraphics Engineer - http://mainroach.blogspot.com
> Especially when using the link above. Although it doesn''t do directly what you''re asking (interpolating per pixel) it does attenuation based upon spherical distance.

Funny, i thought it was doing dot3 lighting with the polygon normal. I wonder what use is the "poly_normal" variable if it doesn''t..

Y.
The effect is typical, if you use the face normal for every lightmap texel, instead of the weighted vertex normals. Thisis analogous to flat Lambert shading versus Gouraud shading.

Check out this page, it summarizes the problem and a possible solution.

It is very important to renormalize the lightmap texel normal, once interpolated. Otherwise, prepare for funky results...


[edited by - Yann L on February 3, 2003 7:30:48 AM]
quote:Original post by Anonymous Poster
Not totally sure about this, but you should be able to get the average of the normals of all the faces surrounding the vertex you are computing for.


Yes, but vertex normals aren''t the problem -- I need per-texel normals.

quote:

I''ve never seen that ring effect. Especially when using the link above. Although it doesn''t do directly what you''re asking (interpolating per pixel) it does attenuation based upon spherical distance. If used, it wouldn''t create that banding effect that you''ve got there (i''ve used it on spheres before)


Right, that''s an extreme example of what happens when you have a light source like the sun -- obviously for nearby light sources the problem is a bit less pronounced, but its still there because I''m currently only using the polygon normal.

quote:
The effect is typical, if you use the face normal for every lightmap texel, instead of the weighted vertex normals. Thisis analogous to flat Lambert shading versus Gouraud shading.

Check out this page, it summarizes the problem and a possible solution.

It is very important to renormalize the lightmap texel normal, once interpolated. Otherwise, prepare for funky results...


Right, I know why the effect is there and what I have to do differently, I just didn''t know how to implement the solution . That link should help though, thanks!

----------------------------------------
"Before criticizing someone, walk a mile in their shoes.
Then, when you do criticize them, you will be a mile away and have their shoes." -- Deep Thoughts
"If you have any trouble sounding condescending, find a Unix user to show you how it''s done." - Scott Adams
FaceHat Software -- Wear the hat.
Is this a software engine? If not, ignore this post

As said above, you need to calculate the weighted normal for each vertex before you can start the work. Do a google-search for "3dica" and download that html tutorial and the sources. It shows you how to do this.

To find the per-pixel normal, you need to interpolate the vertex-normals'' x, y and z values separately, instead of just interpolating color as normal gouraud shading does. That way, you can get the correct light-intensity at any given pixel in your polygon.

Thats how you do it in software. I guess you can do it using pixel-shaders aswell, but i havent tried that. "Basic" Direct3d and opengl does not support phong.

Fake-phong (enviroment-mapping using a texturemap that represents a spotlight) can be done in hardware, and if thats what you use, it''s probably the best way to create phong-lighting on polygons. And it looks just as good, often better, than "real" phong. However, its fairly limited since its a texturemap and not actualy lighting.
- defster

This topic is closed to new replies.

Advertisement