Jump to content


Strange pixel noise with my raytracing engine


9 replies to this topic

#1 allemensen

    New Member

  • Members
  • Pip
  • 8 posts

Posted 07 June 2007 - 04:10 PM

I'm trying to build a raytracing engine, following a tutorial on flipcode (also on this site). But when I run it now it creates a very strange pixel noise. I have tried almost everything to solve it, but nothing works!

The zip file: http://files-upload....tracer.zip.html

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 07 June 2007 - 04:24 PM

Can't you post a screenshot?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 allemensen

    New Member

  • Members
  • Pip
  • 8 posts

Posted 07 June 2007 - 04:35 PM

Here is a screenshot (scaled down by 50%)
Posted Image

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 07 June 2007 - 04:44 PM

I assume you're not doing Monte Carlo raytracing. If you are, then you might just not be using enough samples.

If not, have you tried looking in a debugger to see what is going on at one of the black pixels?

Also, have you tried varying the shapes and materials in the scene to track down what situations trigger the bug? For instance, does it always occur on spheres? Does it always occur on reflective materials?
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 allemensen

    New Member

  • Members
  • Pip
  • 8 posts

Posted 07 June 2007 - 05:25 PM

What is Monte Carlo raytracing? I just shoot a ray through every pixel in my screen. I haven't looked into one of the rays with the debugger yet but I'll try (since the black pixels fit in the same place every time). And black pixels occur only during reflection. I haven't tested reflection with planes yet (my engine only supports the primitives Sphere and InfinitePlane till now)


EDIT: I tried the debugger with one of the black pixels. I discovered that something went wrong in the function Intersect of the Sphere. t1 = 0.4 something and t2 = 0. My function should return HIT and t1, but it returns INPRIM and t2. This gives the point on the other side of the sphere, explaining the black pixel. See next post

#6 allemensen

    New Member

  • Members
  • Pip
  • 8 posts

Posted 07 June 2007 - 06:02 PM

I just found out that with the black pixels, the determinant of the formula to calculate t, is lower than 0. Could someone please check my formula's in Sphere.cpp

#7 stonemonkey

    New Member

  • Members
  • Pip
  • 3 posts

Posted 07 June 2007 - 06:14 PM

Could possibly be that when you test the reflected ray it's being calculated as intersecting the sphere it's meant to be reflected off, if that's the problem then either don't test that sphere or use some small positive value rather than 0 for the minimum distance from reflection point to new intersection. (sorry I've not looked at your code and probably wrong)

#8 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 07 June 2007 - 07:18 PM

Judging only the images I believe that stonemonkey is right. If you recursively ray-trace, start the ray of the next recursion on `position + normal * small_value' instead of just`position'.

#9 allemensen

    New Member

  • Members
  • Pip
  • 8 posts

Posted 08 June 2007 - 03:15 PM

Thanks! That last tip worked! It now shows this image.
Posted Image

#10 Rhino

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 08 June 2007 - 05:28 PM

amazing that with just 2 spheres you've managed to make a test image which resembles a womans breast, complete with nipple.

I foresee a great future for you and your raytracer! :lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users