• Advertisement
Sign in to follow this  

volume lighting

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

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

  light density = 0

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

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


  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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement