Shaders

The highest level of a VSL material hierarchy consists of Shaders. A Shader is a VSL object that has only one property: 'Type'. 'Type' has values like 'Surface properties', 'Surface illumination' and 'Volume properties'. These names, quite obviously, reflect the actions that the rendering engine performs.

The order in which the shaders appear in the hierarchy is not significant. For example, the rendering engine needs to know surface properties before it starts computing surface illumination, and therefore the corresponding shaders are executed in this order, although the user may have inserted them in reversed order.

The set of channels, which is available for use in each shader type, varies. This helps to understand when channels become initialized and which channels are sensible to change. For example, in the 'Volume properties' shader, the surface normal channel is not available at all. This is because it does not make sense to deal with a surface attribute inside an object. In this way, the shader structure guides the user and helps to understand the rendering process.

The shader system is expandable. Plugin modules may insert new shader types.

The default shader types are listed below. These shaders describe the steps of the rendering process quite accurately, so rendering can be customized quite thoroughly using the shaders. For example, the default surface lighting model (standard diffuse lighting) can be redefined completely using suitable objects in the 'Surface illumination' shader.

Included is also a list of 'system' channels that are initialized by the rendering system particularly for that shader, or by an object, which is typically evaluated before the shader. In addition to these, other channels may also contain initialized information written by user defined special operations, materials, plugin classes or by other means.

Material Initialization

This is a special shader in that it is executed only once; at the beginning of rendering. Therefore, it is suitable for initializing constant data, which is stored in root level variables.

Initialized channels:

Time

The global 0..1 time

Common Properties

The VSL code included in this shader is always executed with all other shaders of the material. You can place general-purpose operations and preparations that affect all other shaders into this shader. A typical use of this shader is defining the scope of a material - how much the material affects the target object.

Note, that the position of the common properties shader in the VSL hierarchy defines its evaluation time: if it is placed above other shaders, it is evaluated first. If it is at the end of the VSL tree, the code is evaluated as the last action of every other shader.

If the material contains no other shaders as the common properties shader, the evaluation defaults to the surface properties shader.

Initialized channels:

Scope

The channel defining how strongly the material affects the targets.

Map coords

Mapping coordinates is the usual parameter for texture maps, etc.

Time

The global 0..1 time.

Output channels:

Map coords

You can compute a global change of mapping coordinates in this shader.

Scope

Scope defined in this shader affects all other shaders.

Surface Geometry

This shader can be used to modify surface geometry related attributes.

Initialized channels:

Ray

The direction from which the surface point is looked from.

Distance

The distance from the ray source (camera, etc.) to the surface.

Coordinates

The point of the surface being examined.

Time

The global time.

Normal, U direction, V direction.

Local surface orientation

Map coords

Mapping coordinates.

Map x, Map y, Map z

Mapping orientation.

Antialiasing

Also computed by most mapping objects.

Channels used by the rendering system after the shader:

Bump height

Modifying this channel creates bump map effects. The height is expressed as meters. Therefore the values are typically quite small.

Surface Properties

This is probably the most commonly needed shader, because the appearance of most objects is defined by their surface. Normally, properties such as color or transparency are defined in this shader.

Initialized channels:

Ray

The direction from which the surface point is looked from.

Distance

The distance from the ray source (camera, etc.) to the surface.

Coordinates

The point of the surface being examined.

Color

The default diffuse color (white) or object's color.

Time

The global time.

Normal, U direction, V direction

Local surface orientation.

Bump normal

Possibly modified (bumped) surface normal.

UV Coords

Local surface coordinates.

Map coords

Mapping coordinates.

Antialiasing

Information density computed by most mapping objects.

Map x, Map y, Map z

Mapping orientation.

All 'Exterior' sample channels that are initialized in the 'Volume properties' shader.

These channels describe the properties of the volume from which the ray hitting the surface arrives. For example, Optical thickness and user defined channels can be utilized for optical effects. For more information, see 'Volume properties' shader below.

Channels used by the rendering system after the shader:

Color

The value defines diffuse shading.

Bump normal

Modifying this channel creates bump map effects.

Ray

Used in various shading actions.

Reflection

Amount of mirror reflection.

Transparency

Amount of transparency.

Volume sampling

Values greater than or equal to one invoke volume sampling.

Volume Properties

This shader is used when examining interiors of objects. The shader is needed when creating fog effects, including volumetric light effects (fog glowing in light, shadows casted in fog). Volume sampling slows down rendering, and therefore there is a switch on render settings, 'Volume sampling', which must be enabled in order to let volume properties shaders to operate.

Initialized channels:

Volume:Distance

The distance between samples (=diameter of space area the sample represents).

Volume:Coordinates

The examined point.

Volume:Ray

The direction of the examined ray.

Volume:Time

The global time

Volume:Map coords, Volume:Map x, Map y, Map z, Volume:Antialiasing

The mapping specific information. See 'Surface properties' above.

Ray:Distance

The total distance ray travels in the volume.

Ray:Illumination

The result of ray tracing so far.

Channels used by the rendering system after the shader:

Volume:Color

The diffuse color of fog. This property reacts with lighting.

Volume:Illumination

The 'ambient' or 'self-illumination' color of fog.

Volume:Turbidity

Density of the fog. Defines overall visibility of volume effects as a function of distance.

Ray:Illumination

It is possible to leave the 'Turbidity' channel to zero and compute the volumetric effect directly to this channel.

Light Properties

This shader defines the properties of light emitted from a light source. For example, it is possible to define light falloff rate, color, additional light property channels (a light source casting gamma rays), etc.

Initialized channels (all in Light sample):

Distance

The distance from the light source to the illuminated point.

Coordinates

The illuminated point (NOT the position of a light source!).

Ray

The direction of the light ray (from the light source to the illuminated point).

Illumination

The color of light.

Time

The global time.

Map coords, Map x & y, Antialiasing

Mapping information (see 'Surface properties' above).

Channels used by the rendering system after the shader:

Illumination

The color of light. If black, no illumination is computed.

Distance, Coordinates, Ray

These will be used in shadow computations.

Surface Filtering

This shader controls the shadow creation. A ray tracer executes the shader when a light ray coming from a light source hits an object. The purpose is to find out if the material applied to the object lets the light go through and how the light changes. The decision is made by examining the transparency channel. If the color is white (1.0, 1.0, 1.0), the light continues in an unmodified state, whereas black (0,0,0) stops the light and causes a full shadow. Materials can define custom filter effects by computing suitable filter color values in the filtering shader.

A Ray tracer always executes the 'Surface properties' shader before 'Surface filtering' shader. Therefore, transparency defined in 'Surface properties' is conveniently used as a default value for 'Surface filtering'.

Initialized channels:

All Light sample channels that were initialized in the Light properties shader

See 'Light properties' above.

All channels of the Filter sample that were initialized in the Surface properties shader

See 'Surface properties' above.

Light:Color

Unshadowed, original amount of light.

Light:Illumination

The current amount of light (possibly reduced by other shadows).

Target:Antialiasing, Target:Distance etc.

Target refers to the surface receiving the shadow. Some channels initialized in the Surface properties shader of the shadow Target are available mainly for advanced antialiasing purposes.

Channels used by the rendering system after the shader:

Light:Illumination

The current amount of light. You can change it directly for custom effects.

 

Filter:Transparency

The rendering engine computes the amount of shadow from this channel. White = No shadow.

 

Filter:Fade

Also the fade channel contributes to the shadow transparency. Fully faded objects do not cast a shadow.

 

Volume Filtering

This shader is executed to examine how a volumetric material shadows the light. The sampling density channel defines the accuracy of computation, just like in other volume effects. Furthermore, the 'volume shadows' option in render settings needs to be switched on. The transparency channel defines the amount of shadow. Transparency has the default value defined in the 'Surface properties' shader, which was evaluated when the light ray entered the volume.

Initialized channels:

All Light sample channels initialized in the Light properties shader

See 'light properties' above.

Light:Color

Unshadowed, original amount of light.

Light:Illumination

The current amount of light (possibly reduced by shadows).

VFilter:Coordinates

The examined point.

VFilter:Distance

The distance between samples (=diameter of space area the sample represents).

VFilter:Map coords, VFilter:Map x, Map y, Map z, VFilter:Antialiasing

Mapping specific information.

VFilter:Ray

The direction of the examined ray.

VFilter:Time

The global time.

VFilter:Transparency

Initialized to the value defined by Surface properties.

Channels used by the rendering system after the shader:

Light:Illumination

The color of light. Can also be modified directly.

VFilter:Transparency

The rendering engine computes the amount of shadow from this channel.

Begin Illumination

This shader starts processing surface illumination by light sources. It is executed once, and after that usually multiple Surface illumination evaluations follow. In this shader, you can initialize channels for collecting lighting information.

Initialized channels:

All Surface sample channels that were initialized in the Surface properties shader

See 'Surface properties' above.

Surface Illumination

This shader is executed for examining the influence of a light ray to a surface. This is a suitable shader for defining custom lighting effects. It is possible and also common to define illumination specific information already in the 'surface properties' shader, such as the usual diffuse color. Nevertheless, at this shader, the properties of the light ray are available (intensity, color, direction, etc.), and therefore, more detailed and advanced effects can be defined.

The default actions after the surface illumination is computing the diffuse shading using the color channel and adding the result to the illumination channel, which describes the total result of the shading.

Surface illumination

Initialized channels:

All Light sample channels that were initialized in the Light properties shader

See 'Light properties' above.

All Surface sample channels that were initialized in the Surface properties shader

See 'Surface properties' above.

Light:Color

The original amount of light sent by a light source.

Light:Illumination

The amount of light which reached the surface.

Channels used by the rendering system after the shader:

Light:Illumination

The amount of light.

Surface:Color

Diffuse lighting depends on this channel.

Surface:Illumination

The total result of rendering. Add custom illumination to it.

End Illumination

This shader finishes processing surface illumination by light sources. You can examine and store the total influence of light sources to the surface in this shader. For example:

    Begin illumination /* Store illumination level before light source contribution */
        surface:my_lighting_channel = copy(surface:illumination)
    Surface illumination
        .... /* Lighting actions here */
    End illumination /* Compute how much illumination increased */
        surface:my_lighting_channel = substract(surface:illumination, surface:my_lighting_channel)

Initialized channels:

All Surface sample channels that were initialized in the Surface properties shader and modified by Surface illumination shaders.

 

Surface Finishing

This shader is the very last step of surface shading. In this shader, one can perform actions that control the total surface shading. For example, one can compute all illumination contributions to a buffer channel and then define the actual illumination using this shader.

Initialized channels:

All Surface sample channels that were initialized in other surface shaders

This is the last surface shading step, so most channel values have already been computed.

Channels used by the rendering system after the shader:

Illumination

Illumination channel contains the result of ray tracing.

Volume Illumination

This is similar to the surface illumination, except that this time, illumination of an interior point of a volume is examined. By default, ray tracer does the diffuse shading effect by the given color channel value: light makes the fog glow if the color channel is not black. The diffuse shading depends only on the intensity of the light in the examined point, it does not depend on the lighting direction.

Initialized channels:

All Light sample channels that were initialized in the Light properties shader

See 'Light properties' above.

All Volume sample channels that were initialized in the Volume properties shader

See 'Volume properties' above.

Channels used by the rendering system after the shader:

Light:Illumination

The amount of light.

Volume:Color

Diffuse lighting depends on this.

Volume:Illumination

The result of volume illumination. Add custom illumination to it.

Volume Shading

This shader is executed as the last step of volume processing. At this point, the Volume sample contains the fully illuminated fog in the 'Volume:Illumination' channel. The remaining step is the default shading, which blends the fog illumination with the result of ray tracing using the distance and turbidity. The thicker the turbidity and the longer the distance, the more fog illumination affects the result. VSL code in 'Volume shading' can make the final adjustments before the default shading. It can also compute completely customized fog shading and then set the 'Turbidity' to zero to eliminate default shading.

Initialized channels:

Volume:Distance

The distance between samples (=diameter of space area the sample represents).

Volume:Illumination

The result of fog effects.

Volume:Turbidity

The density of fog.

Ray:Distance

The total distance the ray travels in the volume.

Ray:Illumination

The result of ray tracing before fog effects.

Channels used by the rendering system after the shader:

Ray:Illumination

The result of ray tracing before fog effects. You can compute a custom effect and blend it to this channel.

Volume:Turbidity

The density of fog. Defines the strength of fog effect. Set to zero to eliminate the default fog shading.

Volume:Illumination

The result of fog effects.

Initialize Ray

This shader is called when tracing of a new ray (reflection, GI ray etc.) starts. It is not called for rays originating from the camera. In this shader, you can move data from the originating surface into the traced ray.

Initialized channels:

Traced ray:Coordinates, Traced ray:Ray

The origin and unit direction of the traced ray.

Surface sample channels initialized by the surface properties and surface illumination shaders

 
[Note] Note
If the ray is generated by a user defined raytrace object, the set of initialized channels depends on the location of the raytrace object in the VSL shader tree.

Channels used by the rendering system after the shader:

Traced ray:Coordinates, Traced ray:Ray

The origin and direction of the ray to be traced.

Secondary Ray

This shader is executed when tracing of a ray is finished and the remaining step left is to add the new information to the overall result of shading. For example, fading of reflection by distance can be done in this shader.

Initialized channels:

All Traced ray channels that were initialized by other shaders encountered while tracing the ray.

See the shaders above.

Surface sample channels initialized by surface properties and surface illumination shaders.

See 'Surface properties' and 'Surface illumination' above.

Channels used by the rendering system after the shader:

Surface:Illumination

The result of rendering so far.

Traced ray:Illumination

The result of 'child' ray tracing.

The default shading operation, which combines the two generations of rays, is simply

Surface:Illumination += Traced ray:Illumination*Signalcolor

Here 'Signalcolor' is the channel that created the new ray, such as transparency or reflection.

Ray Hit

This shader is quite a special one. The ray tracer executes it when computing distances to a surface. By modifying the distance, one can distort the surface. If the distance is set to a negative value, the surface disappears and so-called clip mapping effect is achieved.

Initialized channels:

Coordinates

The hit position.

Distance

The distance from the ray source to the hit position.

Map coords

Mapping coordinates.

UV coords

Surface coordinates.

Channels used by the rendering system after the shader:

Distance

Defines visibility of the surface.

Ray Termination

This shader can be used for some fine detail effects for transparent objects. The ray tracer executes it when the tracing of a ray is stopped because of finite recursion depth. Usually, one could add the average of the color of the overall scene to the illumination channel.

Initialized channels:

All surface sample channels that were initialized by the Surface properties and surface illumination shaders.

See 'Surface properties' and 'Surface illumination' above.

Channels used by the rendering system after the shader:

Illumination

Defines the result of tracing the current ray.

Scanline

This shader allows rendertime displacement of scanline objects using materials. The density of points which are passed for this shader depend on the particle type. For example, a particle curve evaluates point displacement densely along the curve, and this shader can be applied to make it curly. Particles may also support other control channels (diameter channel etc.)

Initialized channels:

Coordinates

The position of a geometry point on a particle.

Map coords

Mapping coordinates for displacement parametrization.

UV coords

UV coords run along the surface of each particle, describing its geometry.

Channels used by the rendering system after the shader:

Coordinates

Change this to achieve displacement.

[Note] Note
Use 'Transform to material space' option when computing the displacement vector. Rendering space relative displacement will not behave consistently in animations.

Post Particles

This shader is executed when rendering particles in the post-processing module. For example, it is possible to define the color of particles in this shader. The purpose of this shader is similar to that of the 'surface properties' shader, but as the particle rendering in post processing is a much simpler operation than surface rendering in the ray tracer, less channels are available.

Control channels:

Color

The default diffuse color (white) or particle's color.

Fade

Controls transparency for most effects. Fade 1.0 makes particles totally invisible.

Coordinates

The position of the particle, all particles compute this. Change it to displace the particle.

Map coords, Map x, Map y, Map z

Mapping coordinates and orientation.

U direction, V direction, Normal

Additional information of particle geometry. See the particle specific documentation for details.

Time

The global time.

Image Processing

This special shader is plugged in by one post processing effect, 'material effect'. The purpose is to let the user manipulate pixels of the rendered image by a shader system. As described before, the material editor of the program includes a powerful programming language, and this shader allows the user to define custom image processing effects with the language. All the channels are available in this shader.

Input channels

All channels.

Output channels

All channels.

Rendering Diagram

The picture below shows how the rendering system moves data between the samples. Thick orange arrows represent internal default shading operations between samples, filling the gaps in the data flow.