Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed May 2, 2020
1 parent 158b469 commit 17abc14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Homeworks/9_PathTracing/project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- v0.0.7
- 修复 `SampleBRDF()``pd==0` 时引发的 bug
- `SampleLight()` 给面光源添加了**多重重要性采样**,从而修复了金色噪点问题
- `SampleLight()` 给面光源添加了**多重重要性采样**~~从而修复了金色噪点问题~~
- `CMakeLists.txt` 大幅优化
- v0.0.6
- `Inspector` 添加 `range`
Expand Down
12 changes: 8 additions & 4 deletions Homeworks/9_PathTracing/project/src/PathTracer/PathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ PathTracer::SampleLightResult PathTracer::SampleLight(const IntersectorClosest::
rgbf albedo = brdf->Albedo(intersection.uv);
float metalness = brdf->Metalness(intersection.uv);
float roughness = brdf->Roughness(intersection.uv);
float lambda = (1 + metalness) / 2 * (1 - stdBRDF::Alpha(roughness)); // 0 - 1
float p_mat = lambda; // 1 / (2 - lambda); // 0.5 - 1
// roughness 0 0.5 1
// metalness----------------------------
// 0 | 0.5 0.38 0
// 0.5 | 0.75 0.56 0
// 1 | 1 0.75 0
float p_mat = (1 + metalness) / 2 * (1 - stdBRDF::Alpha(roughness)); // 0 - 1

auto w2l = l2w->value->inverse();

Expand Down Expand Up @@ -215,7 +219,7 @@ PathTracer::SampleLightResult PathTracer::SampleLight(const IntersectorClosest::
// pd_mat : dw -> dA
float dist2 = light_p.distance2(p_on_light);
float cos_theta_l = (-light_wi)[1];
pd_mat = dist2 * pd_mat / std::abs(cos_theta_l);
pd_mat *= std::abs(cos_theta_l) / dist2;
}
else {
pd_light = 0.f;
Expand Down Expand Up @@ -248,7 +252,7 @@ PathTracer::SampleLightResult PathTracer::SampleLight(const IntersectorClosest::

// pd_mat : dw -> dA
float cos_theta_l = (-light_wi)[1];
pd_mat = dist2 * pd_mat / std::abs(cos_theta_l);
pd_mat *= std::abs(cos_theta_l) / dist2;
}
}
else if (vtable_is<EnvLight>(light->light.get())) {
Expand Down

0 comments on commit 17abc14

Please sign in to comment.