Ray Tracing in Shading Language
For an object to be raytraced, it must be marked as raytraceable by setting
the visibility attribute.
The following new shading language constructs and functions are available:
gather( |
string category, |
|
point P, |
|
vector dir, |
|
float angle, |
|
...) |
statement |
[else statement] |
This construct is very similar to PrMan 11's gather construct. It will shoot
numSamples rays rooted at P distributed in a cone centered at
dir making angle angles. For each ray that hits something, the first
statement will be executed. Otherwise else statement will be executed.
The following optional parameters can be provided:
uniform float bias |
The self intersection bias. |
uniform float maxdist |
The maximum intersection distance |
uniform float label |
The ray label |
varying type shadertype:variablename |
The query value (output) |
varying float ray:length |
Length of the ray (output) |
varying vector ray:direction |
The ray direction (output) |
For example:
color totalColor = 0;
color hitColor;
float numHits = 0;
gather("irradiance",P,N,PI/2,256,"surface:Ci",hitColor) {
totalColor += hitColor;
numHits++;
}
totalColor /= numHits;
is equivalent to
totalColor = indirectdiffuse(P,N,256);
color transmission(point P1,point P2,...);
This function gives the transmission between the two points. This function
can be used to get raytraced shadows in light source shaders:
illuminate (from) {
Cl = transmission(Ps,from) * intensity * lightcolor / (L .
L);
}
color indirectdiffuse(point P,vector N,float
numSamples ...);
This function gives the average irradiance as seen be a hemisphere centered
at P N. The irradiance is computed by raytracing. numSamples
gives the number of rays to shoot. Depending on the irradiance attributes
of the current primitive, this value can be cached. The following optional
parameters can be provided:
uniform float minR |
The closest distance between samples. |
uniform float maxR |
The maximum distance between samples. |
uniform float bias |
Raytracing bias |
varying float occlusion |
The occlusion amount (output) |
uniform float
maxdist |
The maximum intersection distance |
uniform vector
backgroundColor |
This color will be used for rays that don't hit anything |
uniform float
maxBrightness |
The ray brightness will be clamped by this number to avoid
splotchy results |
float occlusion(point P,vector N,float numSamples
...);
This function computes the fraction of the hemisphere that is not occluded by
another geometry. The interpretation of the parameters is the same with indirectdiffuse. The following parameters can be passed:
uniform float minR |
The closest distance between samples. |
uniform float maxR |
The maximum distance between samples. |
uniform float bias |
Raytracing bias |
varying color irradiance |
The irradiance amount (output) |
uniform float
maxdist |
The maximum intersection distance |
uniform float raydepth();
This function returns the depth of the current shading point. It returns 0
for the camera rays.
uniform string raylabel();
This function returns the label of ray that caused the shading. You can
assign labels to rays that are generated by the gather statement.
|