User Tools

Site Tools


tutorials:light-modeling-light-shader

Local illumination - Shader

To set the optical properties of an object, in computer graphics the so-called local illumination model is used. It defines so-called shaders, that are define the amount of absorption, reflection and transmission and how the light rays are scattered. The values for absorption are obtained as the 'remaining radiation', i.e., the difference between reflectance and transmission, when we subtract the reflectance and transmission from the total of incoming radiation: Absorption = Total - Reflectance - Transmission.

Note: there is no check of plausibility implemented within the Phong shader. The user needs to make sure that the sum of reflectance and transmission is not higher than the actual incoming radiation. You cannot reflect or transmit more than what was incoming; otherwise, the object would be a light source emitting light.

Computer graphics knows several implementations of local illumination models. The most common are:

  • Labertian reflection, and
  • Phong shader

Whereas the Lambertian reflection model supports only diffuse reflection, the Phong reflection model (B.T. Phong, 1973) combines ambient, diffuse, and specular light reflections.

Lambert Shader

Lambertian reflection (Lambert 1760) is a widely used reflection model for diffuse reflection. The Lambert reflection model assumes an ideal diffusely reflecting surface, where the apparent brightness to an observer is the same regardless of the observer's angle of view, in this way it the reflected radiant intensity obeys 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) = ktt / η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 ω+.

In GroIMP, a Phong shader can be defined as following, where the use of the set-functions is optional. If not used, the default values are used.

static Phong myShader = new Phong();
static {
  myShader.setDiffuse(new RGBAShader(0.1, 0.9, 0.0));
  myShader.setTransparency(new Graytone(0.1));
  myShader.setSpecular(new Graytone(0.1));
  myShader.setShininess(new Graytone(0.05));
}
 
protected void init () [
  Axiom ==> Box(0.001,1,1).(setShader(myShader));
]

The Phong shader provides several functions

  • setDiffuse this defines the reflected radiation
  • setTransparency this defines the direct transparency
  • setDiffuseTransparency this defines the diffusetransparency
  • setSpecular the specular reflection, or regular reflection, is the mirror-like reflection responsible for specular highlights, the bright spots on reflecting surfaces. It defines the light from a light source reflected from the surface of an object directly into a camera.
  • setShininess The size of the specular highlight on an object. If an object is very smooth, the specular highlight will be small. For dull or rough objects, the size will be larger.
  • setTransparencyShininess
  • setAmbient this accounts for the small amount of light that is scattered about the entire scene
  • setEmissive defines the amount of emitted power
  • setInterpolatedTransparency switch to turn on or off the interpolation of transmitted radiation

Alternatively, the parameter can be changed/set using the Attribute Editor:

But keep in mind, when changing parameter within the Attribute Editor, they will set back to what is defined within your model code.

Below, an illustration of the effect of specular and shininess:

Note: In modern Phong shader implementations, roughness and glossiness are used instead of 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.
tutorials/light-modeling-light-shader.txt · Last modified: 2025/01/13 23:17 by MH