Shader
A shader is a component that implements a *local illumination model* in GroIMP, defining how light interacts with the surface of an object. The local illumination model is the theoretical framework that describes how incoming light is absorbed, reflected, or transmitted by surfaces at a local point. A shader is the concrete implementation of this model, encoded as an object or class in GroIMP that controls these optical properties for rendering and simulation purposes.
It specifies the optical properties such as absorption, reflection, transmission, and the scattering behavior of light rays on that surface.
Common Shader Types
For implementation and parameter setting see the tutorial Local illumination - Shader.
Lambert Shader
Lambertian reflection (Lambert, 1760) is a widely used model for diffuse reflection. It assumes an ideal diffusely reflecting surface, where the apparent brightness remains constant regardless of the observer’s viewing angle. Consequently, the reflected radiant intensity follows Lambert's cosine law.
Phong Shader
A Phong shader represents a Phong-like reflector. Its bidirectional reflection/transmission distribution functions are as follows:
At a given point x, let cd be the diffuse color (components R, G, B) at that point, α the alpha-component of the diffuse color and ct the transparency color. For each color component, set
cαt = 1 + α (ct - 1)
Let cs be the specular color and n the shininess exponent. Let r be the reflection coefficient as computed by Fresnel equation.
Now if interpolatedTransparency is true, set
- kd = (1 - cαt) cd
- ks = (1 - cαt) cs + r cαt
- kt = (1 - r) cαt
Otherwise, set
- kd = cd
- ks = cs + r cαt
- kt = (1 - r) cαt
The bidirectional reflection distribution function is
BRDF(x, ωi, ωo) = kd / π + ks (n + 2) max(cos β, 0)n / 2π
where β is the angle between ωi and the direction of ideal reflection of ωo. The bidirectional transmission distribution function is
BTDF(x, ωi, ωt) = kt (ηt / ηi)2 δω+ (ωi - T(ωt))
where η stands for the index of refraction, T for the direction of transmission according to Fresnel's formulas, and δω+ is the δ-distribution with respect to projected solid angle ω+.
The Phong shader supports:
- `setDiffuse()` — sets the diffuse (reflected) component
- `setTransparency()` — sets how much light is transmitted
- `setSpecular()` — sets the mirror-like reflection for highlights
- `setShininess()` — controls the size and sharpness of specular highlights
- `setAmbient()` — ambient light scattering in the scene
- `setEmissive()` — defines self-emission of light
- `setInterpolatedTransparency()` — toggles interpolation of transmitted light
Below is an illustration of the effect of specular and shininess:
Note: In modern Phong shader implementations, roughness and glossiness replace specular and shininess.
Switch Shader
This abstract base class defines a shader which switches between a set of actual shaders based on the shading environment and ray direction. This can be used, e.g., to use different shaders for front and back side (SideSwitchShader), or to use different shaders depending on the algorithm (raytracer or light model) (AlgorithmSwitchShader).
Algorithm Switch Shader
The AlgorithmSwitchShader allows the definition of different shaders used for different purposes depending on the actual used algorithm, namely raytracing, visualization, light modelling. The the two defined constructor of the AlgorithmSwitchShader class ether allow to define a different shader for visualization, raytracing, and radiation (light modelling), or just for visualization, and radiation.
- public AlgorithmSwitchShader (Shader guiShader, Shader raytracerShader, Shader radiationShader)
- public AlgorithmSwitchShader (Shader guiShader, Shader radiationShader)
Personal note: I nearly never use the AlgorithmSwitchShader within larger simulations where the model runs several hours. If there are not intermediate rendered images generated, there is no real need to update the visualization, so instead, I only use the radiation shader during the whole simulation and only change the gui shader to generate nice looking images once.
Side Switch Shader
The SideSwitchShader allows to two use different Shades for a planar object as parallelograms or triangulated mash surfaces etc. The SideSwitchShader(Shader frontShader, Shader backShader) expects two input shader, where as the frontShader will define the upper side shader, where as the backShader will be applied to the downside of the object.
References
- Lambert JH, Photometria, sive de mensura et gradibus luminis, colorum et umbrae, Augsburg: Eberhard Klett, 1760.
- Phong BT, Illumination of Computer-Generated Images, Department of Computer Science, University of Utah, UTEC-CSc-73-129, July 1973.

