volume lighting

Started by
-1 comments, last by supagu 16 years, 10 months ago
i have a volumetric box im trying to add lighting to. Everything i try results in something going wrong. so im gonna explain what i think should be happening: im ray casting through my box, from back to front, doing n samples (lets call these b and f). for each sample i know its position inside the box, will call this p. I then ray cast from where p intersects the box towards the light (lets call this point l), doing m samples. Again for each sample between l and p i knows its position inside the box, will call this q so i do:

out colour = 0
out alpha = 0
blend alpha = 0

loop n times
{
  s = sample volume texture at p

BEGIN LIGHTING
  light density = 0

  loop m times
  {
    t = sample volume texture at q
    light density += t.a
  }

  s.rgb *= (1 - light density) * light colour

END LIGHTING

  out colour += s.rgb * (1 - blend alpha)
  blend alpha += s.a
  out alpha += s.a * (1 - out alpha)
}

final pixel value = (out colour, out alpha)

final pixel gets blended to the screen using standard alpha blending. so im calulating lighting at the point p based on how much light should be able to get to that point by adding all density samples from l to p the light colour is multiplied with colour of the volume at point p

This topic is closed to new replies.

Advertisement