tutorials:light-modeling-light-shader
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorials:light-modeling-light-shader [2025/01/11 20:33] – created MH | tutorials: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 | + | * Labertian |
* 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. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
==== 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' |
+ | |||
+ | In GroIPM, a shader that simulates a Lambertian reflections can be implemented in two ways. The most straight forward way is to use a // | ||
+ | |||
+ | <code java> | ||
+ | protected void init() [ | ||
+ | Axiom ==> Box(0.1, 1, 1).(setShader(new RGBAShader(0, | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | 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)); | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | 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, | ||
+ | setTransparency(new Graytone(0)), | ||
+ | setSpecular(new Graytone(0)), | ||
+ | setShininess(new Graytone(0)) // no shininess | ||
+ | ))); | ||
+ | ] | ||
+ | </ | ||
==== Phong Shader ==== | ==== Phong Shader ==== | ||
- | A Phong shader can be defined as following: | + | A Phong shader represents a Phong-like reflector. Its bidirectional reflection/ |
+ | |||
+ | At a given point x, let c< | ||
+ | |||
+ | | ||
+ | |||
+ | Let c< | ||
+ | |||
+ | |||
+ | Now if // | ||
+ | |||
+ | * k< | ||
+ | * k< | ||
+ | * k< | ||
+ | |||
+ | Otherwise, set | ||
+ | |||
+ | * k< | ||
+ | * k< | ||
+ | * k< | ||
+ | |||
+ | The bidirectional reflection distribution function is | ||
+ | |||
+ | | ||
+ | |||
+ | where β is the angle between ω< | ||
+ | |||
+ | | ||
+ | |||
+ | where η stands for the index of refraction, T for the direction of transmission according to Fresnel' | ||
+ | |||
+ | In GroIMP, a Phong shader can be defined as following, where the use of the // | ||
<code java> | <code java> | ||
Line 22: | Line 88: | ||
static { | static { | ||
myShader.setDiffuse(new RGBAShader(0.1, | myShader.setDiffuse(new RGBAShader(0.1, | ||
- | 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: | ||
] | ] | ||
</ | </ | ||
+ | |||
+ | 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** | ||
+ | * **setInterpolatedTransparency** switch to turn on or off the interpolation of transmitted radiation | ||
+ | |||
+ | Alternatively, | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | 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, | ||
+ | |||
+ | |||
+ | ==== 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 (// | ||
+ | |||
+ | |||
+ | === Algorithm Switch Shader === | ||
+ | The // | ||
+ | |||
+ | * //public AlgorithmSwitchShader (Shader guiShader, Shader raytracerShader, | ||
+ | * //public AlgorithmSwitchShader (Shader guiShader, Shader radiationShader)// | ||
+ | |||
+ | Personal note: I nearly never use the // | ||
+ | |||
+ | === Side Switch Shader === | ||
+ | The // | ||
+ | |||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | * Lambert JH, Photometria, | ||
+ | * Phong BT, Illumination of Computer-Generated Images, Department of Computer Science, University of Utah, UTEC-CSc-73-129, | ||
tutorials/light-modeling-light-shader.1736624000.txt.gz · Last modified: 2025/01/11 20:33 by MH