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.
For implementation and parameter setting see the tutorial Local illumination - 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.
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
Otherwise, set
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:
Below is an illustration of the effect of specular and shininess:
Note: In modern Phong shader implementations, roughness and glossiness replace specular and shininess.
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).
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.
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.
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.