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

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:light-modeling-light-shader [2025/01/13 23:17] – extended MHtutorials:light-modeling-light-shader [2025/06/03 10:04] (current) MH
Line 20: Line 20:
 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. 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 ====
Line 59: Line 87:
 static Phong myShader = new Phong(); static Phong myShader = new Phong();
 static { static {
-  myShader.setDiffuse(new RGBAShader(0.1, 0.9, 0.0));+  myShader.setDiffuse(new RGBColor(0.1, 0.9, 0.0));
   myShader.setTransparency(new Graytone(0.1));   myShader.setTransparency(new Graytone(0.1));
   myShader.setSpecular(new Graytone(0.1));   myShader.setSpecular(new Graytone(0.1));
Line 109: Line 137:
  
 === Side Switch Shader === === 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.+The //SideSwitchShader// allows to two use different Shades for a planar object as parallelograms or triangulated mesh 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.
  
  
tutorials/light-modeling-light-shader.1736806659.txt.gz · Last modified: 2025/01/13 23:17 by MH