The
RealSoft3D ray-tracing process - Part 3:
First Examples
By David Coombes
d.g.coombes@btopenworld.com
Foreword to Part 3
All this theory is all very well, but what
does it actually do? In Part 3 I'll provide
some example VSL materials and show how
the different samples work together to affect
the rendered scene. This is going to be
fairly basic stuff, some of which will have
been covered in the user manual so you may
know some of it already; but Part 3 will
concentrate on the particulars of execution
to help reinforce the course of events as
mentioned in Parts 1 and 2. Also, don't
worry about understanding the VSL code yet.
VSL will be covered in another article explaining
the principles involved in material creation.
For now, just trust it does what I say it
does!
First Experiments
Here's that example scene
from Part 1. We'll experiment on the sphere
and see what we can do to it...
|
|
The
scene, showing the camera's view
as dotted lines |
The
scene as rendered |
The sphere is red because
in its properties window the value for Color
is given (1,0,0). At the beginning of rendering
the ray, this value is copied into the Surface:Color
channel. A straight forward change of colour
would be achieved by replacing this value
with another.
Render
process evaluating sphere |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised to surface
properties defined in scene
construction
-
Surface
Properties: Surface:Color
changed from (1,0,0) to (0,0,1)
-
Surface
Illumination: Lighting
calculations add illumination
(Light:Illumination * angle * Surface:Color)
to Surface:Illumination
|
|
|
The VSL material codes Surface:Color to have a new value, blue. When the camera
ray is traced and intersects with the surface,
the value of the Surface:Color channel is Red (1,0,0). Then the surface
properties shader is executed
which sets Surface:Color to (0,0,1). The subsequent surface
illumination shader then calculates
lighting to produce a blue sphere.
If we can change the colour
by simply assigning a value to the colour
channel, is the same possible with illumination?
Remembering that it is the Surface:Illumination
channel that is copied to Image:Color, if we set Surface:Illumination to a uniform green colour do we produce
a green circle?
Render
process evaluating sphere |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised to surface
properties defined in scene
construction
-
Surface
Properties: Surface:Illumination
changed from default (0,0,0)
to (0,1,0)
-
Surface
Illumination: Lighting
calculations add illumination
(Light:Illumination * angle * Surface:Color)
to Surface:Illumination
|
|
|
Obviously it doesn't work
as intended because after adding green light
to the surface, lighting calculations add
red illumination, from the light source
acting upon the red surface. The red and
green components combine to give yellow.
If we want to create a green
dot, we need to remove the lighting caused
by the illumination shader. The simplest
solution is to turn the surface colour black.
This way whatever light reaches the surface,
no illumination takes place.
Render
process evaluating sphere |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised
-
Surface
Properties: Surface:Color
changed from (1,0,0) to (0,0,0).
Surface:Illumination changed from (0,0,0)
to (0,1,0)
-
Surface
Illumination: Lighting
calculations (Light:Illumination * angle * Surface:Color)
results in (0,0,0) being added
to Surface:Illumination
|
|
|
And voila! A green dot.
Bumps
Perhaps the simplest shader is surface
geometry for its purpose requires
only modifications to Surface:Bump Height and you won't use it for anything else.
By modifying the value of Surface:Bump Height the impression of variations are created
in the surface.
Render
process evaluating sphere |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised
-
Surface
Geometry: Surface:Bump
Height changed according
to a cellular object.
-
Surface
Illumination: Default
lighting calculations
|
|
|
Custom Lighting
One of the main activities of surface
illumination is to create custom
lighting. Rather then using the default
calculations where Surface:Illumination
is directly proportional to the angle of
light on the surface, a material can produce
a Surface:Illumination value
based on a non-proportional transformation.
The following material performs the same
task as the RealSoft3D
default illumination calculations.
Render
process evaluating sphere |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised
-
Surface
Illumination: Custom
lighting calculations determine
light angle and add to Surface:Illumination
relative to this angle.
Light:Illumination is set to (0,0,0) to
nullify default lighting
|
|
|
Note the setting of Light:Illumination (intensity
of light illuminating surface) to black
to deactivate default lighting. This has
the same result as setting Surface:Color to black but preserves the surface colour
which will be useful later. Also note that
in the VSL code I have extended annotation
by including the names of the samples to
which the channels belong, as in this example
I'm referencing more then just the Surface
sample.
The above results are the same as without
the custom illumination calculations. Unlike
the original calculations though, this method
controls the intensity of illumination by
a curve object linked to the angle of light.
The default linear progression (output =
input) of the curve object produces normal
shading as above. By changing this curve
the output is changed accordingly.
Exaggerated
Lighting |
|
Contracted
Lighting |
|
|
|
|
|
Other effects possible in surface
illumination include changing
the Surface:Color
based on the light angle, and changing illumination
based on the angle of light relative to
the viewing position.
Custom Filtering
Now let's look at what's happening with
the floor. Firstly, it has a chequered pattern.
The material that achieves this performs
a colour change in surface
properties. When a cast camera
ray hits the floor, Surface:Color is initialised to the object's colour property
as defined in the editor, (1,1,1). Surface
properties then goes on to make
use of Surface:Map
coords to determine what value
to change Surface:Color to. Surface illumination
calculates how much light is received from
the light source and this gives an intensity
value to Surface:Illumination.
Because the light source is a 'distant'
type, the angle of light remains constant
so the floor is uniformly lit.
If we look more closely at this step of
the scene's illumination, we see the involvement
of the surface filtering
shader. During the tracing of the light
rays reaching the floor, there are instances
of when there is an object (the sphere)
between light source and the floor target.
As such, when surface
illumination is invoked it executes
first surface filtering
before any other calculations. Surface
filtering simply transforms the
intensity of light by the transparency of
the interim surface with the calculation
where Filter:Transparency
is initialised at the beginning of surface
filtering to the value of the
Surface:Transparency
channel of the interim surface. If you look
at the rendering diagram in Part 2 you will
see the values of Surface
Properties are copied to the Surface
Filter sample. In this scene the
transparency of the sphere is uniformly
the default (0,0,0). So when surface illumination is returned to, the original
value of Light:Illumination
has been changed by
Light:Illumination=Light:Illumination
* Filter:Transparency
=
Light:Illumination=Light:Illumination
* (0,0,0)
The result; Light:Illumination
is (0,0,0) and so surface
illumination adds nothing to
Surface:Illumination.
What we can do in the surface
filtering shader of the shadow-casting
object is change the value of Filter:Transparency to change the appearance of the shadow.
Let's try a simple constant value change
with our original scene.
Render
process evaluating floor |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised
-
Surface
Properties: Surface:Color
set to either white or blue
according to Surface:Map coords
-
Surface
Filtering: When the
light ray passes through the
sphere, this shader is executed
for the interim surfaces. Filter:Transparency is set to (0.5,0.8,0.8),
transforming Light:Illumination
-
Surface
Illumination: Default
lighting calculations Surface:Illumination=
(Light:Illumination
* angle * Surface:Color)
|
|
|
With this change to Filter:Transparency
some light gets through to illuminate the
floor. Note that the light passes through
two surfaces either side of the sphere,
as it enters and exits the volume of the
sphere. This means the actual shadowing
might not be as expected. A Filter:Transparency
value of 50% (0.5,0.5,0.5) results in a
quarter of the light reaching the
final surface in this instance. For
the first surface, Light:Illumination is multilied by (0.5,0.5,0.5) to be
halved, and then again at the second surface.
Just as we could change the illumination
by the light angle, we can change the shadowing
by angle. The following works with a calculation
of the angle of the surface relative to
the light source, and a transformation of
Filter:Transparency relative to this angle. The transformation
curve used modifies red, green and blue
components separately to produce a colour
separation in the shadow
Curve
defining filter:transparency |
VSL
code for sphere |
Results |
|
|
|
Finishing Off
The last shader of this part is surface
finishing. This versatile shader
is a very welcome addition to version 4.5
of RealSoft3D.
It allows processing of the shading results
(the value of Surface:Illumination) after illumination calculations executed
in surface illumination.
A good example of an effect possible through
surface finishing
is a "cartoon" or binary shader.
We can determine the amount of illumination
acting upon the surface by dividing the
resulting pixel's illumination by the colour
of the surface lit. Using this we can "reverse
engineer" illumination, changing the
coefficient by which the surface is lit
with a boolean curve and multiplying colour
by this new value to generate a new Surface:Illumination
value. All channels used are
from the Surface
sample
Render
process evaluating sphere |
VSL
code for sphere |
Results |
-
Ray Hits: Surface
sample initialised
-
Surface
Illumination: Default
lighting calculations
-
Surface
Finishing: Calculates
the degree of surface illumination,
transforms this value with a
boolean curve into either (0.5,0.5,0.5)
or (1,1,1), and then multiplies
Surface:Color by intensity placing the result
into Surface:Illumination
|
|
|
Creating a Material
What we've got so far is a collection of
examples of the application of different
shaders. Each shader handles a different
side of the image creation process. A material
may consist of custom VSL code in one or
more shaders. Where in the examples so far
we've only used one shader at a time, we
can combine the above different shaders
to produce a more complex material. This
is the sphere rendering process in the order
the shaders are executed...
|
1. Surface
geometry
Add some bumps |
|
|
2. Surface
properties
Change its colour |
|
3. Surface
illumination
Use custom lighting to condense
illumination area |
|
|
4. Surface
filtering
(not executed unless
invoked by another illumination
shader)
Change the filtering of light through
the sphere's surface affecting the
shadows it casts |
|
5. Surface
finishing
Evaluate Surface:Illumination
and process the data
to produce a two-tone shading |
|
|
|
At the end of that, what we have to show
isn't too pretty but the choice effects
show obvious results. Quite often VSL materials
apply more subtle, realistic effects, or
a value change in one shader is used to
affect the results of another shader. With
these extreme changes I can now offer one
last look at the RealSoft3D
rendering pipeline as so far covered with
a walkthrough of the value changes of two
points in the final image. The following
table records the values of the channels
of the points A and B marked in the final
image, showing data changes as a result
of custom VSL code and default RealSoft3D
operations. Red data signifies a value change.
A dash in a column shows no instance of
that sample at that point in the render
process. Also, some values are approxmate
(leave the 64-bit precision floating-point
maths to the computers!)
Table
of channel data at point 'a' |
|
|
|
|
|
|
|
|
Surface:
Bump Height |
Surface:
Color |
Surface:
Illumination |
Surface:
Transparency |
Filter:
Transparency |
Light:
Illumination |
Ray hits |
|
|
|
|
|
|
Surface
sample data initialised. |
0 |
(1,0,0) |
(0,0,0) |
(0,0,0) |
- |
- |
|
|
|
|
|
|
|
Surface
geometry |
|
|
|
|
|
|
change bumps. |
-0.0002 |
(1,0,0) |
(0,0,0) |
(0,0,0) |
- |
- |
|
|
|
|
|
|
|
Surface
properties |
|
|
|
|
|
|
change colour. |
-0.0002 |
(0,0,1) |
(0,0,0) |
(0,0,0) |
- |
- |
|
|
|
|
|
|
|
Surface
Illumination |
|
|
|
|
|
(1,1,1) |
custom lighting. |
-0.0002 |
(0,0,1) |
(0,0,0.831) |
(0,0,0) |
- |
(0,0,0) |
default lighting. |
-0.0002 |
(0,0,1) |
(0,0,0.831) |
(0,0,0) |
- |
(0,0,0) |
|
|
|
|
|
|
|
Surface
finishing |
|
|
|
|
|
|
custom shading. |
-0.0002 |
(0,0,1) |
(0,0,1) |
(0,0,0) |
- |
- |
Table
of channel data at point 'b' |
|
|
|
|
|
|
|
|
Surface:
Bump Height |
Surface:
Color |
Surface:
Illumination |
Surface:
Transparency |
Filter:
Transparency |
Light:
Illumination |
Ray hits |
|
|
|
|
|
|
Surface
sample data initialised. |
0 |
(1,1,1) |
(0,0,0) |
(0,0,0) |
- |
- |
|
|
|
|
|
|
|
Surface
properties |
|
|
|
|
|
|
change colour. |
0 |
(0,0,1) |
(0,0,0) |
(0,0,0) |
- |
- |
|
|
|
|
|
|
|
Surface
filtering |
|
|
|
|
(0,0,0) |
(1,1,1) |
change shadow. |
0 |
(0,0,1) |
(0,0,0) |
(0,0,0) |
(0.48,0.49,0.26) |
(1,1,1) |
default filter calculations. |
0 |
(0,0,1) |
(0,0,0) |
(0,0,0) |
(0.48,0.49,0.26) |
(0.48,0.49,0.26) |
|
|
|
|
|
|
|
Surface
Illumination |
|
|
|
|
|
|
default lighting. |
0 |
(0,0,1) |
(0,0,0.26) |
(0,0,0) |
- |
(0.48,0.49,0.26) |
|
|
|
|
|
|
|
Summary
You should now understand the practical
role of the different shaders. If you want
to affect an object's colouring, how it
filters light, or how to modify it's appearance
after lighting has taken place, you now
know where your VSL code needs to be placed
and when in the order of rendering events
that code will be executed. If this is the
case, you understand RealSoft3D!
Still to come
The first three parts of this article have
taken you through the basic rendering pipeline
of RealSoft3D. You should now understand
that rays are cast, these access
collections of data as channels,
with different groups of data being collected
together as samples. Different shaders
are executed to fill in different aspects
of a scene's construction, such as defining
surface properties or lighting effects.
At the end of the process, whatever is in
Surface:Illumination
is copied to Image:Color
and determines the final pixel
colour.
In Part 4 the rest of the shaders are included
to give a full picture of the steps contributing
to an image's creation. The later Parts
will introduce recursion which should provide
a breakthrough in understanding the full
RealSoft3D
process, as this is such a key concept to
RealSoft3D.
Still lots to come, all of it worthwhile!
|