Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

goltrpoat

phong illumination model question

This topic is 6920 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

ok.. having coded a raytracer a long time ago, i decided to do it again and this time write a "proper" raytracer, with surface properties that are slightly more involved than a texture lookup modulated by N dot L. so, while implementing the ubiquitous phong illumination model, i ran into the following problems. the phong illumination model (omitting the color properties) is defined as KaIa+att[KdId*(N dot L)+KsIs*(R dot V)^n], K being the material properties, I being the light properties, N being the surface normal, L being the light vector, R is the ray reflected about the surface and V is the view vector. here''s the first problem: att, the attenuation factor, is computed as att = 1/(d^2), d being the distance from the light to the point. in my little standard "five balls hanging over a floor" scene, the distances between the point light source and any surface are pretty big (around 200 units at least). needless to say, that makes att a really small number, and i end up with surfaces that are only ambient shaded. is this actually supposed to be something like att=attdist/(d^2), attdist being some (large) constant for a particular light? or am i missing something? question #2: lets say i decide to forego the attenuation for testing purposes and set att to 1. that brings on the second problem. V is constant at (0,0,1). therefore, R dot V is the Z component of R. if you picture a sphere, rays hitting it from your eye and reflecting along the surface, you end up with vectors whose Z component approaches 1.0 as the vectors approach the "edge" of the sphere. english: i end up with a big ass black blob in the center of the sphere instead of a nice little specular highlight at Ks=0.5,n=30 that we''ve all come to love and cherish after looking at the cook-torrance and blinn-phong material tables. what gives? -goltrpoat -- Float like a butterfly, bite like a crocodile.

Share this post


Link to post
Share on other sites
Advertisement
nevermind, figured it out.. attenuation is better defined using a quadratic with empiric constants, and V is actually the vector from the viewpoint to the point of intersection..

-goltrpoat


--
Float like a butterfly, bite like a crocodile.

Share this post


Link to post
Share on other sites
While you have the correct attenuation formula (1/d2) it is very common to use a formula like this:

att = 1/(a + b*d + c*d2)

a,b, and c being the attenuation factors. The reason for this formula is that it is easier to get pleasing lighting in your rendering. a keeps the light from saturating near the source. b can be used for sources such as spotlights where the light isn''t spreading in an even sphear. c, well you already know that one.

Both OpenGL and Direct3D use this formula when they compute the light affecting a vertex.



- WitchLord

Share this post


Link to post
Share on other sites
right.. that''s what i meant when i said ''quadratic with empiric constants''

--
Float like a butterfly, bite like a crocodile.

Share this post


Link to post
Share on other sites

  • 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!