passing light samples to shaders

November 6th, 2005 by Bramz

When the shader is called, it of course need to know what light is reaching its surface. Initially, the shader would call each light for samples and check wether they are obstructed or not. Also, when combined with photonmapping, the shader would have to query the photonmap. All this was a bit too much logic to put on the shader’s burden. So it was decided to move this light sampling to the different ray tracer classes, and to provide the shader a vector of light samples. Each with a direction and radiance. The DirectLight ray tracer would create light samples of direct light only, the PhotonMapper would also query its photonmap to construct these light samples. At the end, the shader must only loop over the light samples which results in a much simpler loop.

When this scheme was applied, a new std::vector was created on the stack for each call for light samples. Unfortunately, this fragmented the heap catastrophically. We had to change it so that it uses one std::vector that is member of the ray tracer, and we give the shader a pair of iterators to a range of light samples that are always stored in this std::vector. Unfortunately, that renders the ray tracer object very much thread unsafe. Thus if we’re going to use threading, we’ll have to find a solution for this

Comments are closed.