Skip to content

Commit 11ceb5c

Browse files
committed
add more to task7
1 parent 2cdf0d6 commit 11ceb5c

File tree

10 files changed

+99
-12
lines changed

10 files changed

+99
-12
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Notes15.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ PS: 这里的H 表示半球面
7878

7979
关于此渲染方程 Read More https://zh.wikipedia.org/wiki/%E6%B8%B2%E6%9F%93%E6%96%B9%E7%A8%8B
8080

81-
![image](https://raw.githubusercontent.com/lumixraku/NotesForGraphics/master/images/rendering1.png)
81+
![image](https://raw.githubusercontent.com/lumixraku/NotesForGraphics/master/images/rendering1.jpg)
8282

8383

8484
Lo(p, ω0) 是点p在出射ω0方向的最终渲染结果

Notes16.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ PS: 有的地方也称为面积形式的的渲染方程, 并且将前面介绍
170170

171171
来自于光源的部分, 可以使用对光源采样。其他非光源的贡献,继续使用RR
172172
![image](https://raw.githubusercontent.com/lumixraku/NotesForGraphics/master/images/tracing15.jpg)
173-
173+
PS dA 是光源上的一个小的表面
174174

175175
![image](https://raw.githubusercontent.com/lumixraku/NotesForGraphics/master/images/tracing16.jpg)
176176

task7/task7/.vscode/settings.json

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,51 @@
22
"files.associations": {
33
"limits": "cpp",
44
"array": "cpp",
5-
"cmath": "cpp"
5+
"cmath": "cpp",
6+
"typeinfo": "cpp",
7+
"atomic": "cpp",
8+
"bit": "cpp",
9+
"*.tcc": "cpp",
10+
"cctype": "cpp",
11+
"chrono": "cpp",
12+
"clocale": "cpp",
13+
"complex": "cpp",
14+
"cstdarg": "cpp",
15+
"cstddef": "cpp",
16+
"cstdint": "cpp",
17+
"cstdio": "cpp",
18+
"cstdlib": "cpp",
19+
"ctime": "cpp",
20+
"cwchar": "cpp",
21+
"cwctype": "cpp",
22+
"deque": "cpp",
23+
"unordered_map": "cpp",
24+
"vector": "cpp",
25+
"exception": "cpp",
26+
"algorithm": "cpp",
27+
"functional": "cpp",
28+
"iterator": "cpp",
29+
"memory": "cpp",
30+
"memory_resource": "cpp",
31+
"numeric": "cpp",
32+
"optional": "cpp",
33+
"random": "cpp",
34+
"ratio": "cpp",
35+
"string": "cpp",
36+
"string_view": "cpp",
37+
"system_error": "cpp",
38+
"tuple": "cpp",
39+
"type_traits": "cpp",
40+
"utility": "cpp",
41+
"fstream": "cpp",
42+
"initializer_list": "cpp",
43+
"iosfwd": "cpp",
44+
"iostream": "cpp",
45+
"istream": "cpp",
46+
"new": "cpp",
47+
"ostream": "cpp",
48+
"sstream": "cpp",
49+
"stdexcept": "cpp",
50+
"streambuf": "cpp"
651
}
752
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,37 @@
2020
landmarkType = "7">
2121
</BreakpointContent>
2222
</BreakpointProxy>
23+
<BreakpointProxy
24+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
25+
<BreakpointContent
26+
uuid = "9F733401-2730-41AB-93A9-EF0543841AD0"
27+
shouldBeEnabled = "Yes"
28+
ignoreCount = "0"
29+
continueAfterRunningActions = "No"
30+
filePath = "task7/Scene.cpp"
31+
startingColumnNumber = "9223372036854775807"
32+
endingColumnNumber = "9223372036854775807"
33+
startingLineNumber = "79"
34+
endingLineNumber = "79"
35+
landmarkName = "Scene::castRay(ray, depth)"
36+
landmarkType = "7">
37+
</BreakpointContent>
38+
</BreakpointProxy>
39+
<BreakpointProxy
40+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
41+
<BreakpointContent
42+
uuid = "5CF217F2-FDA8-4E2A-B0F5-F114137246C2"
43+
shouldBeEnabled = "Yes"
44+
ignoreCount = "0"
45+
continueAfterRunningActions = "No"
46+
filePath = "task7/Scene.cpp"
47+
startingColumnNumber = "9223372036854775807"
48+
endingColumnNumber = "9223372036854775807"
49+
startingLineNumber = "78"
50+
endingLineNumber = "78"
51+
landmarkName = "Scene::castRay(ray, depth)"
52+
landmarkType = "7">
53+
</BreakpointContent>
54+
</BreakpointProxy>
2355
</Breakpoints>
2456
</Bucket>

task7/task7/task7/Material.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ Vector3f Material::sample(const Vector3f &wi, const Vector3f &N){
136136
case DIFFUSE:
137137
{
138138
// uniform sample on the hemisphere
139+
// 半球面采样
140+
// 参考 https://000ddd00dd0d.github.io/2019/04/07/Spherical-Sampling/
139141
float x_1 = get_random_float(), x_2 = get_random_float();
140142
float z = std::fabs(1.0f - 2.0f * x_1);
141143
float r = std::sqrt(1.0f - z * z), phi = 2 * M_PI * x_2;

task7/task7/task7/Renderer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ void Renderer::Render(const Scene& scene)
7979
Vector3f dir = normalize(Vector3f(-x, y, 1));
8080
thread_local Vector3f color;
8181
color = Vector3f(0);
82+
83+
// SPP 每个像素点多发出几条射线采样
8284
for (int k = 0; k < spp; k++){
8385
color += scene.castRay(Ray(eye_pos, dir), 0) / spp;
8486
}

task7/task7/task7/Scene.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void Scene::sampleLight(Intersection &pos, float &pdf) const
2020
float emit_area_sum = 0;
2121
for (uint32_t k = 0; k < objects.size(); ++k) {
2222
if (objects[k]->hasEmit()){
23-
emit_area_sum += objects[k]->getArea();
23+
emit_area_sum += objects[k]->getArea(); //物体的表面积
2424
}
2525
}
2626
float p = get_random_float() * emit_area_sum;
@@ -69,27 +69,30 @@ Vector3f Scene::castRay(const Ray &ray, int depth) const
6969
hitcolor = Vector3f(1);
7070
else if(intersection.happened)
7171
{
72-
Vector3f wo = normalize(-ray.direction);
73-
Vector3f p = intersection.coords;
74-
Vector3f N = normalize(intersection.normal);
72+
Vector3f wo = normalize(-ray.direction); // 光的出射方向
73+
Vector3f p = intersection.coords; // 射线和物体的坐标
74+
Vector3f N = normalize(intersection.normal);
7575

7676
float pdf_light = 0.0f;
77-
Intersection inter;
78-
sampleLight(inter,pdf_light);
77+
Intersection inter;
78+
sampleLight(inter,pdf_light); // 任意物体表面上任意一个点
7979
Vector3f x = inter.coords;
80-
Vector3f ws = normalize(x-p);
80+
Vector3f ws = normalize(x-p); //
8181
Vector3f NN = normalize(inter.normal);
8282

8383
Vector3f L_dir = Vector3f(0);
84-
//direct light
84+
// direct light
85+
// 这里的公式参考 Notes16 P43
8586
if((intersect(Ray(p,ws)).coords - x).norm() < 0.01)
8687
{
88+
// inter.emit 是发光物体才有意义 不然inter.emit 是0
89+
// eval(wo,ws,N) 返回的是一个漫反射系数
8790
L_dir = inter.emit * intersection.m->eval(wo,ws,N)*dotProduct(ws,N) * dotProduct(-ws,NN) / (((x-p).norm()* (x-p).norm()) * pdf_light);
8891
}
8992

9093
Vector3f L_indir = Vector3f(0);
9194
float P_RR = get_random_float();
92-
//indirect light
95+
// indirect light
9396
if(P_RR < Scene::RussianRoulette)
9497
{
9598
Vector3f wi = intersection.m->sample(wo,N);

task7/task7/task7/Sphere.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Sphere : public Object{
1616
float radius, radius2;
1717
Material *m;
1818
float area;
19+
// 初始化列表
1920
Sphere(const Vector3f &c, const float &r, Material* mt = new Material()) : center(c), radius(r), radius2(r * r), m(mt), area(4 * M_PI *r *r) {}
2021
bool intersect(const Ray& ray) {
2122
// analytic solution
@@ -24,6 +25,8 @@ class Sphere : public Object{
2425
float b = 2 * dotProduct(ray.direction, L);
2526
float c = dotProduct(L, L) - radius2;
2627
float t0, t1;
28+
29+
// 球表面积 S=4πr²
2730
float area = 4 * M_PI * radius2;
2831
if (!solveQuadratic(a, b, c, t0, t1)) return false;
2932
if (t0 < 0) t0 = t1;

0 commit comments

Comments
 (0)