mirror of
https://github.com/ssloy/tinyraytracer.git
synced 2025-09-01 02:01:55 +02:00
Updated Home (markdown)
14
Home.md
14
Home.md
@@ -148,7 +148,7 @@ struct Light {
|
||||
|
||||
Computing real global illumination is a very, very difficult task, so like everyone else, we will trick the eye by drawing completely non-physical, but visually plausible results. To start with: why is it cold in winter and hot in summer? Because the heating of the Earth's surface depends on the angle of incidence of the Sun's rays. The higher the sun rises above the horizon, the brighter the surface is. Conversely, the lower it is above the horizon, the dimmer it is. And after the sun sets over the horizon, photons don't even reach us at all.
|
||||
|
||||
Back our spheres: we emit a ray from the camera (no relation to photons!) at it stops at a sphere. How do we know the intensity of the intersection point illumination? In fact, it suffices to check the angle between a normal vector in this point and the vector describing a direction of light. The smaller the angle, the better the surface is illuminated. Recall that the scalar product between two vectors a and b is equal to product of norms of vectors times the cosine of the angle between the vectors: a*b = |a| |b| cos(alpha(a,b)). If we take vectors of unit length, the scalar product will give us the intensity of surface illumination.
|
||||
Back our spheres: we emit a ray from the camera (no relation to photons!) at it stops at a sphere. How do we know the intensity of the intersection point illumination? In fact, it suffices to check the angle between a normal vector in this point and the vector describing a direction of light. The smaller the angle, the better the surface is illuminated. Recall that the scalar product between two vectors a and b is equal to product of norms of vectors times the cosine of the angle between the vectors: a*b = |a| |b| cos(alpha(a,b)). If we take vectors of unit length, the dot product will give us the intensity of surface illumination.
|
||||
|
||||
|
||||
Thus, in the cast_ray function, instead of a constant color we will return the color taking into account the light sources:
|
||||
@@ -168,18 +168,18 @@ The modifications w.r.t the previous step <a href="https://github.com/ssloy/tiny
|
||||
|
||||
<img src="https://raw.githubusercontent.com/ssloy/tinyraytracer/9a728fff2bbebb1eedd86e1ac89f657d43191609/out.jpg"/>
|
||||
|
||||
<h1>Этап пятый: блестящие поверхности</h1>
|
||||
Трюк со скалярным произведением между нормальным вектором и вектором света неплохо приближает освещение матовых поверхностей, в литературе называется диффузным освещением. Что же делать, если мы хотим гладкие да блестящие? Я хочу получить вот такую картинку:
|
||||
<h1>Step 5: specular lighting</h1>
|
||||
The dot product trick gives a good approximation of the illumination of matt surfaces, in the literature it is called diffuse illumination. What should we do if we want to draw shiny surfaces? I want to get a picture like this:
|
||||
|
||||
<img src="https://raw.githubusercontent.com/ssloy/tinyraytracer/f5ec45c2541feb86b6a30cc3bb04917d60d13e9b/out.jpg"/>
|
||||
|
||||
Посмотрите, <a href="https://github.com/ssloy/tinyraytracer/commit/f5ec45c2541feb86b6a30cc3bb04917d60d13e9b">насколько мало</a> нужно было сделать изменений. Если вкратце, то отсветы на блестящих поверхностях тем ярче, чем меньше угол между направлением взгляда и направлением <i>отражённого</i> света. Ну а углы, понятно, мы будем считать через скалярные произведения, ровно как и раньше.
|
||||
Check <a href="https://github.com/ssloy/tinyraytracer/commit/f5ec45c2541feb86b6a30cc3bb04917d60d13e9b">how few modifications</a> were necessary. In short, the brighter the light on the shiny surfaces, the less the angle between the view direction and the direction of <i>reflected</i> light.
|
||||
|
||||
Эта гимнастика с освещением матовых и блестящих поверхностей известна как <a href="https://en.wikipedia.org/wiki/Phong_reflection_modell">модель Фонга</a>. В вики есть довольно детальное описание этой модели освещения, она хорошо читается при параллельном сравнении с моим кодом. Вот ключевая для понимания картинка:
|
||||
This trickery with illumination of matt and shiny surfaces is known as <a href="https://en.wikipedia.org/wiki/Phong_reflection_modell">Phong reflection model</a>. The wiki has a fairly detailed description of this lighting model. It can be nice to read it side-by-side with the source code. Here is the key picture to understanding the magic:
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/Phong_components_version_4.png"/>
|
||||
|
||||
<h1>Этап шестой: тени</h1>
|
||||
А почему это у нас есть свет, но нет теней? Непорядок! Хочу вот такую картинку:
|
||||
<h1>Step 6: shadows</h1>
|
||||
Why do we have the light, but no shadows? It's not okay! I want this picture:
|
||||
<img src="https://raw.githubusercontent.com/ssloy/tinyraytracer/ef70d1356169dacb3183ad4fcb4c23f1d7003e1b/out.jpg"/>
|
||||
|
||||
<a href="https://github.com/ssloy/tinyraytracer/commit/ef70d1356169dacb3183ad4fcb4c23f1d7003e1b">Всего шесть строчек кода</a> позволяют этого добиться: при отрисовке каждой точки мы просто убеждаемся, не пересекает ли луч точка-источник света объекты нашей сцены, и если пересекает, то пропускам текущий источник света. Тут есть только маленькая тонкость: я самую малость сдвигаю точку в направлении нормали:
|
||||
|
Reference in New Issue
Block a user