Sign in to follow this  

volume lighting

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this