-
13 |
- Scattering 14 |
Scattering
19 |Problem Statement
21 |22 | What happens when light hits on the surface of an object ? 23 |
24 |Description
26 |27 | When thinking about light scattering, it is better to let the model 28 | guide the discourse rather than the inverse. Light scattering 29 | is modeled as 30 | bidirectional reflectance distribution 31 | function ( BRDF ). It describes how 33 | much wavelength incoming to a relative surface coordinate is 34 | emitted. The function can be written as \( 35 | f_r(\theta_{\text{incoming}}, \phi_{\text{incoming}}, 36 | \theta_{\text{emitted}}, \phi_{\text{emitted}}; \lambda) 37 | \) where \(\phi\) and \( \theta \) are spherical coordinates 38 | for the incident flux, meaning they are the angles in which 39 | the flux is arriving and emitted. 40 |
41 |42 | It is a reciprocal function where you can change the roles of the 43 | incoming and emitted angles and you would obtain the same value 44 | anyway due to the physics of light transport. The full model 45 | has two parts: \[ 46 | L_{r}(\hat{v};\lambda) = \int L_i(\theta_i; \lambda) 47 | \hspace{0.5em} 48 | f_r(\theta_i, \phi_i, \theta_e, \phi_e; \lambda)\hspace{0.5em} 49 | max(0, \cos(\theta_i))\hspace{0.5em} d \theta_i \phi_i 50 | \] 51 | 52 | Though this equation is particularly important for rendering a 53 | scene, its explanation is beyond the scope of the course of 54 | this year. It might be treated in the following years. However 55 | here is a link 56 | that explains how rendering equation works. 57 |
58 |
59 | Phong Shading Model: \[
60 | I_{\lambda} = I_{a\lambda}k_a O_{d\lambda} +
61 | f_{att}I_{p\lambda}[k_d O_{d\lambda} (\hat{N} \cdot \hat{L}) + k_s
62 | (\hat{R} \cdot \hat{V})^n] \hspace{1em}
63 | \hat{R} \cdot \hat{V} = (2\hat{N} (\hat{N} \cdot \hat{L}) -
64 | \hat{L} ) \cdot \hat{V}
65 | \]
66 |
-
75 |
- \(I_{\lambda}\) 77 |
- 78 | Light intensity for channel \(\lambda\). In 79 | practice this is the value for one of your color 80 | channels R,G, or B. In most cases it is a 81 | normalized value between 0 and 1.0, we interpolate 82 | it to a value between 0 and 255. 83 | 84 |
- \(I_{a\lambda}\) 87 |
- 88 | Ambient light intensity for the channel 89 | \(\lambda\). The amount of light in the 90 | environment. 91 | 92 |
- \(k_a\) 95 |
- 96 | Ambient light coefficient. This help us to control 97 | how much the ambient light should effect the 98 | overall color of the object. 99 | 100 |
- \(O_{d\lambda}\) 103 |
- 104 | Object diffuse coefficient. It is a material 105 | property of the object. It models how much the 106 | object reacts to the wavelength \(\lambda\) of the 107 | light. 108 | 109 |
- \(f_{att}\) 112 |
- 113 | Attenuation value. Since light reduces its 114 | intensity as it travels from its caster to the 115 | material that scatters it. If this would not be 116 | the case, we would not be able to distinguish 117 | objects that emit same color and that are 118 | equidistant to us. Their distance to the light 119 | source changes the attenuation factor of the light 120 | rays that scatter on them, which in turn reflects 121 | as an intensity change, that intensity change help 122 | us to distinguish the objects. In most cases it is 123 | calculated as follows: \( 124 | f_att = \frac{1}{a_c + a_l * d + a_q * d^2} 125 | \) 126 | where \(a_c\) is constant factor, \(a_l\) is 127 | linear factor, \(a_q\) is quadratic factor. These 128 | are arbitrary factors. Constant factor is mostly 129 | 1.0. Linear and quadratic change with respect to 130 | distance. 131 | 132 |
- 135 | \( I_{p\lambda} \) 136 | 137 |
- 138 | Diffuse intensity of light. This is mostly 139 | used for incoming ray intensity. For example 1.0 140 | for the channel \(\lambda\) which is a place 141 | holder for R, G, B. 142 | 143 |
- N 146 |
- 147 | Surface normal. 148 | 149 |
- L 152 |
- 153 | Direction of incoming light 154 | 155 |
- \(k_s\) 158 |
- 159 | Specular coefficient. It permits us to control how 160 | much specular radiance of the object. This is 161 | actually a material property. 162 | 163 |
- \(\hat{R}\) 166 |
- 167 | Reflection vector. Direction to which light is 168 | reflected from the surface. Normalized. 169 | 170 |
- \(\hat{V}\) 173 |
- 174 | Viewer vector. Direction in which the viewer is 175 | located. Normalized. 176 | 177 |
- n 180 |
- 181 | Specular reflection exponent coefficient. 182 | Another material property. This also help us to 183 | control specularity. 184 | 185 |
189 | Phong shading model is superseded by microfacet based models but 190 | still for quick experiments it gives acceptable results, and 191 | it is easy to evaluate. The final color, final appearance, is 192 | composed of three elements: ambient, diffuse, specular. These 193 | components are controlled via coefficients. These coefficients 194 | are based on the material properties of the objects. However 195 | the problem with Phong model is that the contribution of the 196 | material properties is modeled in rather arbitrary fashion. 197 | Thus, it is difficult to explain why some value works for 198 | modeling the behavior of an object. 199 |
200 |Code snippets
201 |
222 |
223 |
224 |
225 |
228 |
229 |
230 |
231 |
234 |
235 |
236 |
237 |
240 |
241 |
242 |
243 |
246 |
247 |
248 |
249 | Exercise
254 |-
255 |
-
256 | Implement and test Phong model on scene. The scene
257 | contains the following:
258 |
-
259 |
- Rectangle whose vertices are:
260 |
-
261 |
- [0.0, 5.0, 0.0] 262 |
- [0.0, 1.0, 0.0] 263 |
- [8.0, 1.0, 0.0] 264 |
- [8.0, 5.0, 0.0] 265 |
267 | - The color matrix of the rectangle is 268 | \( 269 | \pmatrix{ 270 | 10 & 120 & 120 & 120 & 86 & 132 & 200 & 250 \\ 271 | 100 & 10 & 10 & 10 & 8 & 12 & 200 & 250 \\ 272 | 120 & 10 & 130 & 130 & 132 & 32 & 100 & 150 \\ 273 | 150 & 180 & 220 & 220 & 159 & 136 & 250 & 250 274 | }\) 275 | 276 |
- 277 | Light source who is positioned at [4.0, 20.0, 278 | 4.0] and whose diffuse intensity is 255. 279 | 280 |
- Viewer who is positioned at [8.0, 12.0, 6.0] 281 |
- Attenuation factor values are 1.0, 0.7, 1.8 282 |
- Ambient intensity is 1.0 283 |
- The values for \(k_a, k_s\) are arbitrary values between 0 284 | and 1 285 | 286 |
- The value for n can be anything between 1 287 | and 800 288 |
290 | - Rectangle whose vertices are:
260 |
156 | The bounding boxes of the circles are:
157 |