Tutorials/Soft raytraced shadows
From PixieWiki
[edit] Soft Raytraced Shadows
In order to have soft raytraced shadows, you can either use the shadow or transmission calls with blur parameter set to something other than 0 (default).
For example, if you change (in shadowdistant.sl)
vis = (1 - shadow(shadowname,Ps));
with
vis = (1 - shadow(shadowname,Ps,"blur",0.1));
you should get the following picture:
A blur value 1 means that the light source is hemispherical. The blur value 0 means the light source is pure directional.
Notice the noisy shadow penumbra because the default number of samples for shadow call is 1.
If we use the following line:
vis = (1 - shadow(shadowname,Ps,"blur",0.1,"samples",50));
we get the following picture which looks much better:
[edit] Soft Transmission Shadows
You can use the transmission function in a shader to get soft shadows without using shadow(). I got the below shader from the sig03.course09.pdf and the rib from the point based occlusion example.
The Shader:
light transmissionspot (
float intensity=1, beamdistribution=2;
color lightcolor = 1;
point from = point "shader" (0,0,0);
point to = point "shader" (0,0,1);
float coneangle=radians(30), conedeltaangle=radians(5);
float samples=1, blur=0, bias = -1;)
{
uniform vector A = (to - from) / length(to - from);
uniform float cosoutside= cos(coneangle), cosinside = cos(coneangle-conedeltaangle);
illuminate( from, A, coneangle ) {
float cosangle = L.A / length(L);
color atten = pow(cosangle, beamdistribution) / (L.L);
atten *= smoothstep( cosoutside, cosinside, cosangle );
atten *= transmission(Ps, from, "samples", samples, "samplecone", blur, "bias", bias);
Cl = atten * intensity * lightcolor;
}
}
The Rib:
FrameBegin 1
Format 400 300 1
PixelSamples 4 4
ShadingInterpolation "smooth"
Display "transmission spot" "framebuffer" "rgba"
Display "+transmission.png" "file" "rgba"
Projection "perspective" "fov" 22
Translate 0 -0.5 8
Rotate -40 1 0 0
Rotate -20 0 1 0
WorldBegin
LightSource "transmissionspot" 1 "intensity" 200.0 "lightcolor" [1.0 1.0 1.0]
"coneangle" 40 "from" [1 10 5] "to" [0 0 0] "samples" 32 "blur" 0.1 "bias" 0.01
Illuminate 1 1
Attribute "visibility" "int transmission" [1] # use this to turn transmission on and off
Surface "plastic"
# Ground plane
AttributeBegin
Color 1 1 1
Polygon "P" [ -5 0 5 5 0 5 5 0 -5 -5 0 -5 ]
AttributeEnd
# Sphere
AttributeBegin
Color 1 1 1
Translate -0.7 0.5 0
Sphere 0.5 -0.5 0.5 360
AttributeEnd
# Box
AttributeBegin
Color 1 1 1
Translate 0.3 0.01 0
Rotate -30 0 1 0
Polygon "P" [ 0 0 0 0 0 1 0 1 1 0 1 0 ] # left side
Polygon "P" [ 1 1 0 1 1 1 1 0 1 1 0 0 ] # right side
Polygon "P" [ 0 1 0 1 1 0 1 0 0 0 0 0 ] # front side
Polygon "P" [ 0 0 1 1 0 1 1 1 1 0 1 1 ] # back side
Polygon "P" [ 0 1 1 1 1 1 1 1 0 0 1 0 ] # top
AttributeEnd
WorldEnd
FrameEnd
[edit] Stained Glass Shadows
Using the same transmissionspot shader from the 'Soft Transmission Shadows' tutorial, and modifing the rib a little, we can use transmission to create the "stained glass" shadow effect. Use the below shader that I got from sig03.course09.pdf.
The Shader:
surface stainedglass ( string texturename = "" )
{
/* a simplistic stainedglass effect,
* note the decoupling of Oi and Ci
*/
color x = color texture(texturename);
Oi = 1 - x;
Ci = x * x; /* pleasantly saturated */
}
Use this image:
Media:Pixie_semi-transparent.tiff
Then use texmake to create the tx file:
texmake Pixie_semi-transparent.tiff Pixie_semi-transparent.tx
If you use your own image, be sure to add an alpha channel and set it to the amount of transparency you want.
The Modified Rib:
FrameBegin 1
Format 400 300 1
PixelSamples 4 4
ShadingInterpolation "smooth"
Display "stained glass" "framebuffer" "rgb"
Display "+stainedglass.jpg" "file" "rgb"
Projection "perspective" "fov" 22
Translate 0 -0.6 8.5
Rotate -35 1 0 0
Rotate 170 0 1 0
WorldBegin
LightSource "transmissionspot" 1 "intensity" 200.0 "lightcolor" [1.0 1.0 1.0]
"coneangle" 40 "from" [1 10 5] "to" [0 0 0] "samples" 64 "blur" 0.02 "bias" 0.01
Illuminate 1 1
Attribute "visibility" "int transmission" [1] # use this to turn transmission on and off
Surface "plastic"
# Ground plane
AttributeBegin
Color 1 1 1
Polygon "P" [ -10 0 10 10 0 10 10 0 -10 -10 0 -10 ]
AttributeEnd
# Sphere
AttributeBegin
Color 1 1 1
Translate -0.7 0.5 0
Sphere 0.5 -0.5 0.5 360
AttributeEnd
# Box
AttributeBegin
Color 1 1 1
Translate 0.3 0.01 0
Rotate -30 0 1 0
Polygon "P" [ 0 0 0 0 0 1 0 1 1 0 1 0 ] # left side
Polygon "P" [ 1 1 0 1 1 1 1 0 1 1 0 0 ] # right side
Polygon "P" [ 0 1 0 1 1 0 1 0 0 0 0 0 ] # front side
Polygon "P" [ 0 0 1 1 0 1 1 1 1 0 1 1 ] # back side
Polygon "P" [ 0 1 1 1 1 1 1 1 0 0 1 0 ] # top
AttributeEnd
# Image Panel
AttributeBegin
# If you use "primitive for the last option on the below command
# it will give you a solid shadow from the geometry.
# Using "shader" will let the light pass through and color the
# objects below
Attribute "shade" "transmissionhitmode" "shader"
Surface "stainedglass" "texturename" "Pixie_semi-transparent.tx"
Translate 0 1.5 0
Rotate -30 0 1 0
Scale 2 1 2
Polygon "P" [ 0 1 1 1 1 1 1 1 0 0 1 0 ] "st" [ 1 0 1 1 0 1 0 0 ]
AttributeEnd
WorldEnd
FrameEnd




