Jump to content


raytracing: light intensity at point


  • You cannot reply to this topic
8 replies to this topic

#1 wintermute

    New Member

  • Members
  • Pip
  • 4 posts

Posted 24 July 2007 - 02:17 PM

hi
I have written a recursive raytracer and I am currently experimenting with global illumination.

So far, I used the following formula to compute the light intensity at a certain point:
intensity at point = light emitted by light source / (distance to light source^2)

If, however, light source was hit directly by a ray, then simply the light source's intensity was returned.

This seemed logic to me and it worked well for recursive raytracing.

Then I tried to work on global illumination. Since I do not fully understand the rendering equation due to a lack of knowledge of calculus I more or less "guessed" an algorithm which I hope is similar to path tracing^^:

If a ray hits a diffuse surface, a random ray in the hemisphere over the intersection point is traced through the scene until the max recursion depth is reached OR until it hits a light source. If this happens, then simply the light source's intensity is returned.
The returned light is multiplied with the dot product of the surface normal and the ray direction.

Given enough rays per pixel my little experiment yields quite nice results. (which I belive aren't quite correct though^^)
Although I have to reduce the intensity of the light sources by several powers of 10 to get an image which is not too bright!

I also tried to abandon the formula mentioned above completely and always return the unchanged the light intensity. This also works quite well (I can use the same light source both for recursive raytracing and the global illumination experiment) although images rendered with recursive raytracing are much brighter than those with "global illumination" which should acutally be the other way round.

sort of global illumination:
Posted Image

Currently I am totally confused with the light intensity issue.
It would be cool if anyone could help me :)

PS:I'm sorry if I made too many spelling or grammar mistakes. English is not my native language.

#2 flux00

    Valued Member

  • Members
  • PipPipPip
  • 108 posts

Posted 24 July 2007 - 03:19 PM

It looks like you've implemented path tracing, and it looks quite nice. Usually when tracing a randomly reflected ray off a diffuse surface you focus your rays more toward the normal than parallel to the surface, I don't know if you've done that. Sometimes path tracers use the formula

light at surface = direct light + light from randomly reflected ray

In which case you would scale the light contribution from direct light by 1/r^2. You can either use that or simply stop when you hit a light or your depth goes too high. Either way the light contribution should be scaled by the material of the surface.

#3 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 24 July 2007 - 04:27 PM

And to deal with the brightness problem you may want to implement this.
reedbeta.com - developer blog, OpenGL demos, and other projects

#4 wintermute

    New Member

  • Members
  • Pip
  • 4 posts

Posted 24 July 2007 - 05:29 PM

flux00 said:

It looks like you've implemented path tracing, and it looks quite nice. Usually when tracing a randomly reflected ray off a diffuse surface you focus your rays more toward the normal than parallel to the surface, I don't know if you've done that. Sometimes path tracers use the formula

light at surface = direct light + light from randomly reflected ray

In which case you would scale the light contribution from direct light by 1/r^2. You can either use that or simply stop when you hit a light or your depth goes too high. Either way the light contribution should be scaled by the material of the surface.

The rays are all evenly distributed over the hemisphere. How much should the rays be focused towards the normal?

I was simply wondering which light calculation approach is most physically accurate. 1/dist^2 yields completely different results than simply using the light source's unmodified light intensity.

Also I didn't know that path tracers use shadow rays. I thought that rays simply bounce around in the scene until they hit a light source.

#5 flux00

    Valued Member

  • Members
  • PipPipPip
  • 108 posts

Posted 24 July 2007 - 05:55 PM

Some do, some don't. The 1/r^2 is only used if shadow rays are traced. Tracing until you hit a light works well for area lights, but point and directional lights can't be intersected. Not using shadow rays is more physically based, but the noise would be higher.

I use Jensen's formula to calculate diffusely reflected rays:

phi = acos(sqrt(E0))
theta = 2*pi*E1

Where E0 and E1 and uniformly distributed random numbers in [0,1), theta is the rotation around the normal and phi is the angle with the normal. I believe you need to define a tangent coordinate system to convert the hemispherical coordinates to Cartesian, but Reedbeta knows better.

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 24 July 2007 - 10:01 PM

The reason lots of people cast rays using the cosine-weighted hemispherical distribution (which focuses the rays more to the normal) is that virtually all BRDFs include a factor of cos(N . L), i.e. they weight incoming light according to the cosine of the angle of incidence. You can shoot rays using a uniform distribution on the hemisphere and then weight their results by this factor, or you can shoot rays using the cosine-weighted distribution and leave out the cosine factor in the BRDF. The latter approach reduces the variance, i.e. it results in a slightly less noisy image (for a given number of samples). But both approaches are equally correct.

As for the 1/r^2 factor, that should only be used for point-lights. If you're using area lights, the distance attenuation will occur "naturally" due to fewer rays hitting the area light when it is far away. (However, if you sample area lights explicitly using shadow rays rather than letting them be hit by your random hemisphere-rays, you'll need to include 1/r^2 again, since it's part of the conversion factor between the projected area of the light surface and the solid angle subtended by the light around the illuminated point.)

Quote

I believe you need to define a tangent coordinate system to convert the hemispherical coordinates to Cartesian
Yep, but it's not too important which tangent space you use, it doesn't have to be aligned with the texture axes or anything like that.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 wintermute

    New Member

  • Members
  • Pip
  • 4 posts

Posted 25 July 2007 - 02:44 PM

Thanks for your answers.

The cosine-weighted hemispherical distribution thing sounds interesting.
I'll try it out.

#8 anubis

    Senior Member

  • Members
  • PipPipPipPip
  • 2225 posts

Posted 25 July 2007 - 04:27 PM

Also check out russian roulette path termination. This way you can bring down rendering time substantially.
If Prolog is the answer, what is the question ?

#9 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 25 July 2007 - 06:11 PM

And thumbs up for your nick :yes:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users