Friday, December 16, 2011

Volume Rendering

Game Plan -

  • Hit a sphere
  • Have sphere call its shader
    • Shader : "Oh! I'm a Volume Shader..."
    • Shader finds second hit point (behind sphere)
    • Shader marches by some delta for some number of steps across distance between hitpoints (which we know because we found them both) in the direction of the original hit direction
    • Each step applies the over operator (more info found here

You can see the steps in the red ball above.




Added Perlin Noise to the volume by tweaking the alpha value according to PerlinNoise3D function.





Applied Beer's Law (at every delta) to prevent intensity having a dependence on number steps.  Also had ray continue out back. (Forgot negative sign in exponent in above picture.)

Changed to negative exponent.

Next, added lighting -
Process :

  • March through volume
  • At every step, march through ray pointing to light until you exit the volume
  • Calculate the light attenuation at that current position and use that in the "blending operator" so that the total light that accumulates and is sent to the camera includes the correct intensity of light from every point along the originally marched path    

Here is my scene without lighting :



And now WITH light: 

Light color - (.9, .4, .9), 
Noise -


thisTrans.x() = exp( sin(- hr.thingHit->_absorbCoeff.x() * noise_scale * absPert.x()) * delta);
thisTrans.y() = 0 ; //exp( - hr.thingHit->_absorbCoeff.x() * noise_scale * absPert.y() * delta);
thisTrans.z() = ( exp( tan(- hr.thingHit->_absorbCoeff.x() * noise_scale * absPert.z()) * delta));


Trig functions in exponents = awesome. (Discovery attributed to Steven!)

(sin and perlin - alpha)


Not exactly a plasma ball (yet), but not too shabby.

No comments:

Post a Comment