|
|
On 9 Sep 1999 04:20:51 -0400, Nieminen Juha <war### [at] cctutfi> wrote:
Warp,
with time I was able to come up with en empiric formula for the
calculation of the color of a media sample. Here it goes in
pseudocode:
D = GetDensityColor(Density, SamplePosition);
For emission:
E = EmissionColor * D;
The final ray color is the average of all sample colors. This adds up
with whatever color the ray gets after passing through the media
container. Therefore a yellow emititon media on a blue background will
look white.
For absorption:
A = AbsorptionColor * D;
The contributions of all samples are averaged ans substracted from the
color the ray gets after it leaves the media container object.
Therefore a blue absorbing media on a blue background will look black,
clear on a yellow background and yellow on a white background.
For scattering:
CameraVec = SamplePosition - CameraLocation;
LightVec = SamplePosition - LightPosition;
S = ShadowRayColor * ScatteringColor * ScatteringFunction ( Type,
CameraVec, LightVec);
ShadowRayColor is the color of the ray sent to the light source. It
might hit the light source directly, or not hit it at all (i.e. a
shadow) or it might get filtered through a semitransparent object.
After calculating S, the color of the sampling ray is attenuated
according to:
SampleRayColor = SampleRayColor - Extinction * S;
Then the calculations are performed for the next sample along the ray.
Finally all sample contributions are averaged.
Check out this scene:
sphere
{ 0, 1
pigment { rgbf 1 }
hollow
interior
{ media
{ intervals 10 samples 1, 10 confidence 0.9999 variance 0.0001
scattering { 1, red 2 }
// absorption Cyan
}
}
}
camera
{ location <0.0 , 2.0 ,-5.0>
angle 30
look_at <0.0 , 0.0 , 0.0>
}
light_source { <100,100,0> color rgb 1 }
plane { y, -1 pigment { checker color rgb 0 color rgb 1 } }
Note that the media looks red upon a black background and cyan upon a
white background. That's because when you substract red from black,
the result is still black, while if you attenuate the red off a white
background, you get white.
Because as the the ray passes through the media, its color is
attenuated by the amount of scatering multiplied by the extinction
value on a sample-by-sample basis, setting an overkill value for
either scattering or density will attenuate the light a lot and the
scene will look black. A setting for scatering which is too low will
make the beam too faint. You have to find the value which works for
your case. Or, you could turn down extinction which, though not
realistic, may suit your needs. A value of 0.1 is what I used four
your scene with a scattering type of 3 and and amount of 0.1.
I hope I cleared up the fog (err, media) in your head at least a
little :)
Peter Popov
ICQ: 15002700
Post a reply to this message
|
|