Jump to content
  • Advertisement

Archived

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

VuurSnikkel

Possible diffuse lighting problem (visual error) with own raytracer.

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

Hi there ppl... I''m writing a raytracing module for a 3D OpenGL Lego editor that I''m creating (the editor is almost finished and it works quite fine, I''ll post it when the raytracing module is incorporated) and I started out with the basics. I added scene, camera, light and object management, wrote the first intersection routine (ray-sphere) and started to trace some spheres using a couple of colored lights (I''m only calculating diffuse color at the moment; no specular, no ambient) and then I noticed some strange visual artifacts. Here are three single-light shots and a shot in which all three lights are activated (a white/orange light at the left/back, a white/blue light at the right and a white light at the camera position). The first three shots look OK, but the one in which all of the lights are activated has some strange lines going through the spheres. http://www.inforumweb.com/snik/shot001.jpg (white/orange left/back light) http://www.inforumweb.com/snik/shot002.jpg (white/blue right light) http://www.inforumweb.com/snik/shot003.jpg (white camera light) http://www.inforumweb.com/snik/shot004.jpg (all three of them at once acting strange) Here''s a relevant (Delphi) code snippet that determines the light intensities and some accompanying info about the code. ... If ActiveScene.Objects.Lights.Count <> 0 Then Begin //DiffuseCalc. //Reset red, green and blue intensities (doubles). IR:=0; IG:=0; IB:=0; //Returns the intersection point of the current ray with the //current sphere as an X,Y,Z-triple based on previous //calculations, nothing wrong here I think: ISPoint:=VecAdd(ARay.PStart, VecScale(ClosestT, ARay.Vec)); //The normalized object normal at the intersection point: N:=VecNorm(VecSub(ISPoint, Ray3DShape.Pos)); //Use sphere center. //Adding the intensities together for all of the lights: For I:=0 To ActiveScene.Objects.Lights.Count - 1 Do Begin Light:=ActiveScene.Objects.Lights.Items; //The normalized light vector: L:=VecNorm(VecSub(Light.Pos, ISPoint)); //Calculating the dot product: VecDotNL:=VecDot(N, L); If VecDotNL > 0 Then Begin //Light at visible side of surface: //RF, GF, and BF are color values in the range [0..1] (doubles): IR:=IR + Light.Col.RF * RAY3DShape.DifCol.RF * VecDotNL; IG:=IG + Light.Col.GF * RAY3DShape.DifCol.GF * VecDotNL; IB:=IB + Light.Col.BF * RAY3DShape.DifCol.BF * VecDotNL; End; End; //The resulting (clamped) color values: NewR:=Round(Min(IR, 1) * 255); NewG:=Round(Min(IG, 1) * 255); NewB:=Round(Min(IB, 1) * 255); End; ... I don''t know whether or not this is an error, but it looks strange and I''m wondering what causes it. Any ideas? Round-off errors perhaps? I''m using doubles as floating point types everywhere... GRTZ, (Sn)Ik.

Share this post


Link to post
Share on other sites
Advertisement
Hmm, you''re right it does look strange. I don''t think theres anything obvious in your code, although it''s a very naive lighting model.

Share this post


Link to post
Share on other sites
Your code looks fine. What seems to be going on is that the lights don''t entirely overlap on the spheres, so you get bands where only the camera light is hitting the spheres, and the other two lights have already dropped off to 0. It looks strange because in real life we never see objects lit that perfectly; there is always reflection coming from the environment that blurs out the bands.

Try moving the lights a little closer together (i.e. move the one in back closer to the camera, and the one on the right a bit left) and the bands should go away.

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!