Skip to content

Commit 164d51a

Browse files
committed
encoding
1 parent 92e498b commit 164d51a

File tree

11 files changed

+54
-54
lines changed

11 files changed

+54
-54
lines changed

Frame/Source/Assignment/Assignment1/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Eigen::Matrix4f get_view_matrix(Eigen::Vector3f eyePos)
2121

2222
Eigen::Matrix4f get_model_matrix(float angle)
2323
{
24-
// 绕 Z 轴旋转
24+
// 绕 Z 轴旋转
2525
Eigen::Matrix4f model;
2626
model <<
2727
std::cos(angle), -std::sin(angle), 0.0f, 0.0f,
@@ -33,11 +33,11 @@ Eigen::Matrix4f get_model_matrix(float angle)
3333

3434
Eigen::Matrix4f get_projection_matrix(float fov, float aspect, float near, float far)
3535
{
36-
// 由 frustum 的定义得 top 与 right
36+
// 由 frustum 的定义得 top 与 right
3737
float top = std::tan(fov * 0.5f * MY_PI / 180.0f) * std::abs(near);
3838
float right = aspect * top;
3939

40-
// 由相机此时的位置与方向得 bottom = -top 与 left = -right
40+
// 由相机此时的位置与方向得 bottom = -top 与 left = -right
4141
float bottom = -top;
4242
float left = -right;
4343

Frame/Source/Assignment/Assignment2/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ Eigen::Matrix4f get_model_matrix(float rotation_angle)
3030

3131
Eigen::Matrix4f get_projection_matrix(float fov, float aspect, float near, float far)
3232
{
33-
// 修复框架 bug
33+
// 修复框架 bug
3434
near = -near;
3535
far = -far;
3636

37-
// 由 frustum 的定义得 top 与 right
37+
// 由 frustum 的定义得 top 与 right
3838
float top = std::tan(fov * 0.5f * MY_PI / 180.0f) * std::abs(near);
3939
float right = aspect * top;
4040

41-
// 由相机此时的位置与方向得 bottom = -top 与 left = -right
41+
// 由相机此时的位置与方向得 bottom = -top 与 left = -right
4242
float bottom = -top;
4343
float left = -right;
4444

Frame/Source/Assignment/Assignment2/rasterizer.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ auto to_vec4(const Eigen::Vector3f& v3, float w = 1.0f)
4242

4343
static bool insideTriangle(float x, float y, const Vector3f* v)
4444
{
45-
// 此时位于屏幕空间,保证 z 分量一致即可
45+
// 此时位于屏幕空间,保证 z 分量一致即可
4646
Eigen::Vector3f point = { x, y, 1.0f };
4747
Eigen::Vector3f vertex_a = { v[0].x(), v[0].y(), 1.0f };
4848
Eigen::Vector3f vertex_b = { v[1].x(), v[1].y(), 1.0f };
@@ -124,7 +124,7 @@ void rst::rasterizer::draw(pos_buf_id pos_buffer, ind_buf_id ind_buffer, col_buf
124124
void rst::rasterizer::rasterize_triangle(const Triangle& t) {
125125
auto v = t.toVector4();
126126

127-
// AABB 应当由整数的像素下标索引定义
127+
// AABB 应当由整数的像素下标索引定义
128128
uint16_t min_x = std::floor(std::min(v[0].x(), std::min(v[1].x(), v[2].x())));
129129
uint16_t max_x = std::ceil(std::max(v[0].x(), std::max(v[1].x(), v[2].x())));
130130
uint16_t min_y = std::floor(std::min(v[0].y(), std::min(v[1].y(), v[2].y())));
@@ -137,12 +137,12 @@ void rst::rasterizer::rasterize_triangle(const Triangle& t) {
137137
size_t index = static_cast<size_t>(get_index(static_cast<int>(pos_x), static_cast<int>(pos_y)));
138138
float &depth = depth_buf[index];
139139

140-
// SSAA 所采样的四个子像素相对于像素左下角坐标的偏移量
140+
// SSAA 所采样的四个子像素相对于像素左下角坐标的偏移量
141141
static const std::vector<Eigen::Vector2f> s_offsets = { {0.25f, 0.25f}, {0.75f, 0.25f}, {0.25f, 0.75f}, {0.75f, 0.75f} };
142142
constexpr uint8_t SubPixelCount = 4;
143143
assert(s_offsets.size() == SubPixelCount);
144144

145-
// 用于计算子像素贡献值
145+
// 用于计算子像素贡献值
146146
uint8_t activeColor = 0;
147147
uint8_t activeDepth = 0;
148148
Eigen::Vector3f finalColor = { 0.0f, 0.0f , 0.0f };
@@ -153,22 +153,22 @@ void rst::rasterizer::rasterize_triangle(const Triangle& t) {
153153
float subPos_x = static_cast<float>(pos_x) + offset.x();
154154
float subPos_y = static_cast<float>(pos_y) + offset.y();
155155

156-
// 获取子像素的深度插值
156+
// 获取子像素的深度插值
157157
auto [alpha, beta, gamma] = computeBarycentric2D(subPos_x, subPos_y, t.v);
158158
float w_reciprocal = 1.0 / (alpha / v[0].w() + beta / v[1].w() + gamma / v[2].w());
159159
float z_interpolated = alpha * v[0].z() / v[0].w() + beta * v[1].z() / v[1].w() + gamma * v[2].z() / v[2].w();
160160
z_interpolated *= w_reciprocal;
161161

162162
if (insideTriangle(subPos_x, subPos_y, t.v))
163163
{
164-
// 修复框架 bug
164+
// 修复框架 bug
165165
if (z_interpolated > depth)
166166
{
167-
// 只有同时通过了 inside 测试与深度测试才会对颜色有贡献
167+
// 只有同时通过了 inside 测试与深度测试才会对颜色有贡献
168168
++activeColor;
169169
finalColor += t.getColor();
170170
}
171-
// 只要通过 inside 测试就会对深度有贡献
171+
// 只要通过 inside 测试就会对深度有贡献
172172
++activeDepth;
173173
finalDepth += z_interpolated;
174174
}
@@ -177,13 +177,13 @@ void rst::rasterizer::rasterize_triangle(const Triangle& t) {
177177
finalColor /= static_cast<float>(activeColor);
178178
finalDepth /= static_cast<float>(activeDepth);
179179

180-
// 没有通过测试的子像素依旧应当对颜色与深度产生贡献,
181-
// 按理来说其值应从 frame_buf_ssaax4 与 depth_buf_ssaax4 中获取。
182-
// 鉴于框架本身较为简陋,这里意思到位即可。
180+
// 没有通过测试的子像素依旧应当对颜色与深度产生贡献,
181+
// 按理来说其值应从 frame_buf_ssaax4 与 depth_buf_ssaax4 中获取。
182+
// 鉴于框架本身较为简陋,这里意思到位即可。
183183
// finalColor += static_cast<float>(SubPixelCount - activeColor) / static_cast<float>(SubPixelCount) * frame_buf_ssaax2[subIndex];
184184
// finalDepth += static_cast<float>(SubPixelCount - activeDepth) / static_cast<float>(SubPixelCount) * depth_buf_ssaax2[subIndex];
185185

186-
// 修复框架 bug
186+
// 修复框架 bug
187187
if (finalDepth > depth)
188188
{
189189
depth = finalDepth;
@@ -216,7 +216,7 @@ void rst::rasterizer::clear(rst::Buffers buff)
216216
}
217217
if ((buff & rst::Buffers::Depth) == rst::Buffers::Depth)
218218
{
219-
// 修复框架 bug
219+
// 修复框架 bug
220220
std::fill(depth_buf.begin(), depth_buf.end(), std::numeric_limits<float>::lowest());
221221
}
222222
}

Frame/Source/Assignment/Assignment3/Texture.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ class Texture
6464
float v_img = (1.0f - v) * heightf;
6565
Eigen::Vector2f center{ std::round(u_img), std::round(v_img) };
6666

67-
// 边界情况,当采样点位于边界时进行 clamp,使得两对次采样点值相等,即此时双线性插值退化为单次线性插值
67+
// 边界情况,当采样点位于边界时进行 clamp,使得两对次采样点值相等,即此时双线性插值退化为单次线性插值
6868
Eigen::Vector2f u00{ std::max(0.0f, center.x() - 0.5f), std::max(0.0f, center.y() - 0.5f) };
6969
Eigen::Vector2f u01{ std::max(0.0f, center.x() - 0.5f), std::min(heightf, center.y() + 0.5f)};
7070
Eigen::Vector2f u10{ std::min(widthf, center.x() + 0.5f), std::max(0.0f, center.y() - 0.5f) };
7171
Eigen::Vector2f u11{ std::min(widthf, center.x() + 0.5f), std::min(heightf, center.y() + 0.5f) };
7272

73-
// 边界情况,假设次采样点坐标为 (width, height),它应当采样的下标则为 (width - 1, height - 1)
73+
// 边界情况,假设次采样点坐标为 (width, height),它应当采样的下标则为 (width - 1, height - 1)
7474
Eigen::Vector2i u00_index{ std::clamp(static_cast<int>(u00.x()), 0, width - 1), std::clamp(static_cast<int>(u00.y()), 0, height - 1) };
7575
Eigen::Vector2i u01_index{ std::clamp(static_cast<int>(u01.x()), 0, width - 1), std::clamp(static_cast<int>(u01.y()), 0, height - 1) };
7676
Eigen::Vector2i u10_index{ std::clamp(static_cast<int>(u10.x()), 0, width - 1), std::clamp(static_cast<int>(u10.y()), 0, height - 1) };

Frame/Source/Assignment/Assignment3/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ Eigen::Matrix4f get_model_matrix(float angle)
5151

5252
Eigen::Matrix4f get_projection_matrix(float fov, float aspect, float near, float far)
5353
{
54-
// 修复框架 bug
54+
// 修复框架 bug
5555
near = -near;
5656
far = -far;
5757

58-
// 由 frustum 的定义得 top 与 right
58+
// 由 frustum 的定义得 top 与 right
5959
float top = std::tan(fov * 0.5f * MY_PI / 180.0f) * std::abs(near);
6060
float right = aspect * top;
6161

62-
// 由相机此时的位置与方向得 bottom = -top 与 left = -right
62+
// 由相机此时的位置与方向得 bottom = -top 与 left = -right
6363
float bottom = -top;
6464
float left = -right;
6565

@@ -152,7 +152,7 @@ Eigen::Vector3f phong_fragment_shader(const fragment_shader_payload& payload)
152152

153153
Eigen::Vector3f texture_fragment_shader(const fragment_shader_payload &payload)
154154
{
155-
// 好像 OpenCV 读取 png 时的返回值范围是 [0, 255],而非 [0, 1]
155+
// 好像 OpenCV 读取 png 时的返回值范围是 [0, 255],而非 [0, 1]
156156
static constexpr float reciprocal = 1.0f / 255.0f;
157157

158158
static Eigen::Vector3f ka = Eigen::Vector3f(0.005f, 0.005f, 0.005f);
@@ -288,7 +288,7 @@ Eigen::Vector3f displacement_fragment_shader(const fragment_shader_payload& payl
288288
float du = kh * kn * (height_u - height);
289289
float dv = kh * kn * (height_v - height);
290290

291-
// 将着色点沿着原法线的方向进行位移
291+
// 将着色点沿着原法线的方向进行位移
292292
point += kn * normal * height;
293293

294294
Eigen::Vector3f localNormal = Eigen::Vector3f{ -du, -dv, 1.0f };

Frame/Source/Assignment/Assignment3/rasterizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ void rst::rasterizer::draw(std::vector<Triangle *> &TriangleList)
126126
// Screen space rasterization
127127
void rst::rasterizer::rasterize_triangle(const Triangle& t, const std::array<Eigen::Vector3f, 3>& view_pos)
128128
{
129-
// 为了获取顶点的 w 分量,这里不能使用 Triangle::toVector4
129+
// 为了获取顶点的 w 分量,这里不能使用 Triangle::toVector4
130130
const Eigen::Vector4f *v = t.v;
131131

132-
// AABB 应当由整数的像素下标索引定义
132+
// AABB 应当由整数的像素下标索引定义
133133
uint16_t min_x = std::floor(std::min(v[0].x(), std::min(v[1].x(), v[2].x())));
134134
uint16_t max_x = std::ceil(std::max(v[0].x(), std::max(v[1].x(), v[2].x())));
135135
uint16_t min_y = std::floor(std::min(v[0].y(), std::min(v[1].y(), v[2].y())));
@@ -153,7 +153,7 @@ void rst::rasterizer::rasterize_triangle(const Triangle& t, const std::array<Eig
153153
size_t index = static_cast<size_t>(get_index(static_cast<int>(pos_x), static_cast<int>(pos_y)));
154154
float &depth = depth_buf[index];
155155

156-
// 修复框架 bug
156+
// 修复框架 bug
157157
if (final_z > depth)
158158
{
159159
depth = final_z;
@@ -201,7 +201,7 @@ void rst::rasterizer::clear(rst::Buffers buff)
201201
}
202202
if ((buff & rst::Buffers::Depth) == rst::Buffers::Depth)
203203
{
204-
// 修复框架 bug
204+
// 修复框架 bug
205205
std::fill(depth_buf.begin(), depth_buf.end(), std::numeric_limits<float>::lowest());
206206
}
207207
}

Frame/Source/Assignment/Assignment4/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void bezier(const std::vector<cv::Point2f> &control_points, cv::Mat &window)
8181
int x_index = point.x() + offset[i][j].x();
8282
int y_index = point.y() + offset[i][j].y();
8383

84-
// OpenCV »áʹһ¸öÏñËØµãµÄÖµ mod 255
84+
// OpenCV 会使一个像素点的值 mod 255
8585
uchar color = std::max(static_cast<uchar>(filter[i][j] * 255), window.at<cv::Vec3b>(y_index, x_index)[1]);
8686
window.at<cv::Vec3b>(y_index, x_index)[1] = std::min(static_cast<uchar>(255), color);
8787
}

Frame/Source/Assignment/Assignment6/BVH.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
2929
{
3030
BVHBuildNode* pNode = new BVHBuildNode();
3131

32-
// 所有物体的包围盒集合。
32+
// 所有物体的包围盒集合。
3333
Bounds3 bounds;
3434
for (int i = 0; i < objects.size(); ++i)
3535
{
3636
bounds = Union(bounds, objects[i]->getBounds());
3737
}
3838

39-
// 只存在一个物体,建立叶节点。
39+
// 只存在一个物体,建立叶节点。
4040
if (objects.size() == 1)
4141
{
4242
pNode->bounds = objects[0]->getBounds();
@@ -46,7 +46,7 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
4646

4747
return pNode;
4848
}
49-
// 存在两个物体,建立其 left 和 right 叶节点。
49+
// 存在两个物体,建立其 left 和 right 叶节点。
5050
else if (objects.size() == 2)
5151
{
5252
pNode->left = recursiveBuild(std::vector{ objects[0] });
@@ -57,33 +57,33 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
5757
}
5858
else
5959
{
60-
// 由所有物体的质心组成的包围盒。
60+
// 由所有物体的质心组成的包围盒。
6161
Bounds3 centroidBounds;
6262
for (int i = 0; i < objects.size(); ++i)
6363
{
6464
centroidBounds = Union(centroidBounds, objects[i]->getBounds().Centroid());
6565
}
6666

67-
// 最长的维度。
67+
// 最长的维度。
6868
switch (centroidBounds.maxExtent())
6969
{
7070
case 0:
71-
// X 轴。
71+
// X 轴。
7272
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2)
7373
{
74-
// 将所有物体按照其包围盒的质心的 X 轴排序,Y 轴和 Z 轴的 case 同理。
74+
// 将所有物体按照其包围盒的质心的 X 轴排序,Y 轴和 Z 轴的 case 同理。
7575
return f1->getBounds().Centroid().x < f2->getBounds().Centroid().x;
7676
});
7777
break;
7878
case 1:
79-
// Y 轴。
79+
// Y 轴。
8080
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2)
8181
{
8282
return f1->getBounds().Centroid().y < f2->getBounds().Centroid().y;
8383
});
8484
break;
8585
case 2:
86-
// Z 轴。
86+
// Z 轴。
8787
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2)
8888
{
8989
return f1->getBounds().Centroid().z < f2->getBounds().Centroid().z;
@@ -98,14 +98,14 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
9898

9999
#if ENABLE_SAH
100100

101-
// 一份比较清晰的 SAH 介绍:https://zhuanlan.zhihu.com/p/50720158
101+
// 一份比较清晰的 SAH 介绍:https://zhuanlan.zhihu.com/p/50720158
102102

103-
// 划分方式的总数。
103+
// 划分方式的总数。
104104
constexpr uint8_t SlashCount = 8;
105105
constexpr float SlashCountInv = 1.0f / static_cast<float>(SlashCount);
106106
const float SC = centroidBounds.SurfaceArea();
107107

108-
// 用于记录最优的划分方式。
108+
// 用于记录最优的划分方式。
109109
uint8_t minCostIndex = SlashCount / 2;
110110
float minCost = std::numeric_limits<float>::infinity();
111111

@@ -115,7 +115,7 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
115115
auto leftObjects = std::vector<Object *>(begin, target);
116116
auto rightObjects = std::vector<Object *>(target, end);
117117

118-
// 分别计算划分之后两部分包围盒的表面积。
118+
// 分别计算划分之后两部分包围盒的表面积。
119119
Bounds3 leftBounds, rightBounds;
120120
for (const auto &obj : leftObjects)
121121
{
@@ -134,7 +134,7 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
134134

135135
if (cost < minCost)
136136
{
137-
// 更新更优的划分方式。
137+
// 更新更优的划分方式。
138138
minCost = cost;
139139
minCostIndex = index;
140140
}
@@ -144,7 +144,7 @@ BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
144144

145145
#else // ENABLE_SAH
146146

147-
// 基本的 BVH 划分方式,按数量从中间一分为二。
147+
// 基本的 BVH 划分方式,按数量从中间一分为二。
148148
const auto &target = objects.begin() + (objects.size() / 2);
149149

150150
#endif // ENABLE_SAH
@@ -181,7 +181,7 @@ Intersection BVHAccel::getIntersection(BVHBuildNode* node, const Ray& ray) const
181181
return Intersection{};
182182
}
183183

184-
// 叶节点
184+
// 叶节点
185185
if (node->left == nullptr && node->right == nullptr)
186186
{
187187
return node->object->getIntersection(ray);

Frame/Source/Assignment/Assignment6/Triangle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ inline Intersection Triangle::getIntersection(Ray ray)
212212
{
213213
if (dotProduct(ray.direction, normal) > 0.0f)
214214
{
215-
// ¹âԴλÓÚÈý½ÇÐα³Ãæ¡£
215+
// 光源位于三角形背面。
216216
return Intersection{};
217217
}
218218

Frame/Source/Assignment/Assignment7/Material.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ class Material
124124
return false;
125125
}
126126

127-
// 返回出射光线的方向。
127+
// 返回出射光线的方向。
128128
inline Vector3f sample(const Vector3f &wi, const Vector3f &N);
129-
// 返回采样的 PDF。
129+
// 返回采样的 PDF。
130130
inline float pdf(const Vector3f &wi, const Vector3f &wo, const Vector3f &N);
131-
// 返回 BRDF。
131+
// 返回 BRDF。
132132
inline Vector3f eval(const Vector3f &wi, const Vector3f &wo, const Vector3f &N);
133133
};
134134

@@ -220,7 +220,7 @@ Vector3f Material::eval(const Vector3f &wi, const Vector3f &wo, const Vector3f &
220220
}
221221
case MaterialType::MIRROR:
222222
{
223-
// 听说完美镜面是需要考虑菲涅尔项的,有空再研究吧。
223+
// 听说完美镜面是需要考虑菲涅尔项的,有空再研究吧。
224224
return Vector3f{ 1.0f , 1.0f , 1.0f };
225225
break;
226226
}

Frame/Source/Assignment/Assignment7/Triangle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ inline Intersection Triangle::getIntersection(Ray ray)
225225
{
226226
if (dotProduct(ray.direction, normal) > 0.0f)
227227
{
228-
// 光源位于三角形背面。
228+
// 光源位于三角形背面。
229229
return Intersection{};
230230
}
231231

232-
// E1, E2 在 Triangle 的构造函数中已经赋好值了。
232+
// E1, E2 在 Triangle 的构造函数中已经赋好值了。
233233
const Vector3f &E1 = e1;
234234
const Vector3f &E2 = e2;
235235
const Vector3f &D = ray.direction;

0 commit comments

Comments
 (0)