Skip to content

Commit 8d305c8

Browse files
committed
add more to task5
1 parent c84c53d commit 8d305c8

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

Notes8.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# Lecture 08 Shading 2
22

3-
## 高光模型
3+
## 高光模型 Phong
4+
和观察角度有关
5+
6+
Phong 重点在于计算 reflection
7+
8+
V 是观察角度 R 是反射方向
9+
```
10+
spec = pow(max(dot(V, R), 0.0), alpha);
11+
```
12+
13+
Read More https://www.qiujiawei.com/lighting-1/
14+
15+
16+
17+
## 高光模型 Blinn-Phong
18+
19+
和观察角度有关
420

521
![image](https://raw.githubusercontent.com/lumixraku/NotesForGraphics/master/images/shading4.jpg)
622

@@ -18,7 +34,7 @@ PS: cosα 可以写成 法线n 点乘 半程向量h
1834

1935
![image](https://raw.githubusercontent.com/lumixraku/NotesForGraphics/master/images/shading6.jpg)
2036

21-
PS: 另外需要说明的是入射光方向和中学物理中的方向是相反的, 这个公式中入射光的方向就是用光源减去点
37+
PS: 另外需要说明的是入射光方向其实是指光源的方向,而不是光线的方向。
2238

2339
## 环境光
2440

task5/task5/task5.xcodeproj/xcuserdata/lilin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,21 @@
2020
landmarkType = "9">
2121
</BreakpointContent>
2222
</BreakpointProxy>
23+
<BreakpointProxy
24+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
25+
<BreakpointContent
26+
uuid = "9DBD7F7D-7366-48DC-BB77-BB49588F9318"
27+
shouldBeEnabled = "No"
28+
ignoreCount = "0"
29+
continueAfterRunningActions = "No"
30+
filePath = "task5/Renderer.cpp"
31+
startingColumnNumber = "9223372036854775807"
32+
endingColumnNumber = "9223372036854775807"
33+
startingLineNumber = "227"
34+
endingLineNumber = "227"
35+
landmarkName = "castRay(orig, dir, scene, depth)"
36+
landmarkType = "9">
37+
</BreakpointContent>
38+
</BreakpointProxy>
2339
</Breakpoints>
2440
</Bucket>

task5/task5/task5/Renderer.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,30 @@ Vector3f castRay(
207207
// We also apply the lambert cosine law
208208
// [/comment]
209209
for (auto& light : scene.get_lights()) {
210-
Vector3f lightDir = light->position - hitPoint;
210+
Vector3f lightDir = light->position - hitPoint; // 光源和 hitPoint 的方向 // 后续判断阴影用
211211
// square of the distance between hitPoint and the light
212-
float lightDistance2 = dotProduct(lightDir, lightDir);
212+
float lightDistance2 = dotProduct(lightDir, lightDir); // 光源和 hitPointd 的距离平方
213213
lightDir = normalize(lightDir);
214214
float LdotN = std::max(0.f, dotProduct(lightDir, N));
215215
// is the point in shadow, and is the nearest occluding object closer to the object than the light itself?
216+
217+
// 判断是否有阴影
218+
// 射线从碰撞点出发 方向是g光源
216219
auto shadow_res = trace(shadowPointOrig, lightDir, scene.get_objects());
220+
221+
// tNear 是射线出发后碰到的最近的物体的距离
222+
// 如果这个距离小于光源到碰撞点的距离 表示其中有物体挡住了光源 存在阴影
217223
bool inShadow = shadow_res && (shadow_res->tNear * shadow_res->tNear < lightDistance2);
218-
224+
225+
// light->intensity * LdotN Lambert Cosine Law
219226
lightAmt += inShadow ? 0 : light->intensity * LdotN;
227+
228+
// 不要忘记负号
229+
// 在冯氏光照模型中 光的方向是指光源的方向 而不是光线的方向
220230
Vector3f reflectionDirection = reflect(-lightDir, N);
221-
231+
232+
233+
// 下面是计算specular 用的 Phong 高光模型
222234
specularColor += powf(std::max(0.f, -dotProduct(reflectionDirection, dir)),
223235
payload->hit_obj->specularExponent) * light->intensity;
224236
}

0 commit comments

Comments
 (0)