User Tools

Site Tools


tutorials:light-modeling-light-shader

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:light-modeling-light-shader [2025/01/11 20:33] – created MHtutorials:light-modeling-light-shader [2025/01/22 15:13] (current) – [Lambert Shader] MH
Line 7: Line 7:
 Computer graphics knows several implementations of local illumination models. The most common are:  Computer graphics knows several implementations of local illumination models. The most common are: 
  
-  * Labertian shader, and+  * Labertian reflection, and
   * Phong shader   * 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.
 +
 +{{ :tutorials:light6.png?direct&550 |}}
 +
 +
  
 ==== Lambert Shader ==== ==== Lambert Shader ====
  
-tbd+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. 
 + 
 +In GroIPM, a shader that simulates a Lambertian reflections can be implemented in two ways. The most straight forward way is to use a //RGBAShader// that just defines a colour (and an optional transparent part). The following code will generate a green box. 
 + 
 +<code java> 
 +protected void init() [ 
 +    Axiom ==> Box(0.1, 1, 1).(setShader(new RGBAShader(0, 1, 0))); 
 +
 +</code> 
 + 
 +There are a set for standard coulours (red, green, blue, black, white, etc.) defined that can be used instead. For instance the same green shader from above can be generated using the following code.    
 + 
 +<code java> 
 +protected void init() [ 
 +    Axiom ==> Box(0.1, 1, 1).(setShader(GREEN)); 
 +
 +</code> 
 + 
 +The second way would be to use a //Phong// shader and use only the diffuse (reflectance) part of it whereas the not required aspects are turned off. The following will create an equivalent Lambertian reflection using a //Phong// shader object. 
 + 
 +<code java> 
 +protected void init() [ 
 +    Axiom ==> Box(0.1, 1, 1).(setShader(new Phong().( 
 +      setDiffuse(new RGBColor(0,1,0)), 
 +      setTransparency(new Graytone(0)), // no transparency 
 +      setSpecular(new Graytone(0)), // no specular reflection 
 +      setShininess(new Graytone(0)) // no shininess 
 +    ))); 
 +
 +</code>
  
 ==== Phong Shader ==== ==== Phong Shader ====
  
-A Phong shader can be defined as following:+Phong shader represents a Phong-like reflector. Its bidirectional reflection/transmission distribution functions are as follows: 
 + 
 +At a given point x, let c<sub>d</sub> be the diffuse color (components R, G, B) at that point, &alpha; the alpha-component of the diffuse color and c<sub>t</sub> the transparency color.  For each color component, set  
 + 
 + c<sup>α</sup><sub>t</sub> = 1 + α (c<sub>t</sub> - 1) 
 + 
 + Let c<sub>s</sub> 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 
 + 
 +  * k<sub>d</sub> = (1 - c<sup>α</sup><sub>t</sub>) c<sub>d</sub> 
 +  * k<sub>s</sub> = (1 - c<sup>α</sup><sub>t</sub>) c<sub>s</sub> * + r c<sup>α</sup><sub>t</sub> 
 +  * k<sub>t</sub> = (1 - r) c<sup>α</sup><sub>t</sub> 
 + 
 +Otherwise, set 
 + 
 +  * k<sub>d</sub> = c<sub>d</sub> 
 +  * k<sub>s</sub> = c<sub>s</sub> + r c<sup>α</sup><sub>t</sub> 
 +  * k<sub>t</sub> = (1 - r) c<sup>α</sup><sub>t</sub> 
 +  
 +The bidirectional reflection distribution function is 
 +  
 + BRDF(x, ω<sub>i</sub>, ω<sub>o</sub>) = k<sub>d</sub> / π + k<sub>s</sub> (n + 2) max(cos β, 0)<sup>n</sup> / 2π 
 +  
 +where β is the angle between ω<sub>i</sub> and the direction of ideal reflection of ω<sub>o</sub>. The bidirectional transmission distribution function is 
 + 
 + BTDF(x, ω<sub>i</sub>, ω<sub>t</sub>) = k<sub>t</sub> (η<sub>t</sub> / η<sub>i</sub>)<sup>2</sup> δ<sub>ω<sup>+</sup></sub> (ω<sub>i</sub> - T(ω<sub>t</sub>)) 
 +  
 +where η stands for the index of refraction, T for the direction of transmission according to Fresnel's formulas, and δ<sub>ω<sup>+</sup></sub> is the δ-distribution with respect to projected solid angle ω<sup>+</sup>.  
 + 
 +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.
  
 <code java> <code java>
Line 22: Line 88:
 static { static {
   myShader.setDiffuse(new RGBAShader(0.1, 0.9, 0.0));   myShader.setDiffuse(new RGBAShader(0.1, 0.9, 0.0));
-  myShader.setTransparency(new Graytone(0.3));+  myShader.setTransparency(new Graytone(0.1));
   myShader.setSpecular(new Graytone(0.1));   myShader.setSpecular(new Graytone(0.1));
   myShader.setShininess(new Graytone(0.05));   myShader.setShininess(new Graytone(0.05));
Line 31: Line 97:
 ] ]
 </code> </code>
 +
 +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:
 +
 +{{ :tutorials:light-phong_attributes.png?direct&350 |}}
 +
 +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:
 +
 +{{ :tutorials:light-spec_vs_shiny.png?direct&450 |}}
 +
 +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.1736624000.txt.gz · Last modified: 2025/01/11 20:33 by MH