Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Example] Fix rounding error for cornell_box.py #1908

Merged
merged 7 commits into from
Oct 1, 2020

Conversation

lyd405121
Copy link
Contributor

[fix]
fix rounding error artifact for cornell_box

Related issue = #

[Click here for the format server]


[fix]
fix rounding error artifact for cornell_box
@archibate archibate requested a review from k-ye September 29, 2020 14:51
@@ -354,6 +358,7 @@ def sample_direct_light(hit_pos, hit_normal, hit_color):
w = mis_power_heuristic(brdf_pdf, light_pdf)
nl = dot_or_zero(brdf_dir, hit_normal)
direct_li += fl * w * nl / brdf_pdf
'''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this part commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my opinion:
[1] this part sample a reflect direction, so that is indirect lighting, not direct lighting
[2] next iter will count direct lighting as previous indirect lighting, so the radiance is over counted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now thinking it back, this is actually doing multiple importance sampling (MIS). See http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Direct_Lighting.html#fragment-SampleBSDFwithmultipleimportancesampling-0, so it's not really over counted.

I cannot say that the MIS impl was correct, but could you keep this part, and just tweak the epsilon to see if the dark ring problem goes away?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no doubt that you are right!
This implementation is the same with pbrt-v3 ,totally right!

---------------------------advice -----------------------
I have advice for efficience:

change the calculation when hitting a light for depth > 0 and always record the brdfPdf
if hit_light:
acc_color += throughput * light_color * powerHeuristic(brdfPdf, lightPdf) / brdfPdf
break
Then comment the brdf mis part

--------------------compare------------------------------
[current method] there are two sample direction, three brdf color eval , one intersect detection for light in one iter
[anthoer method] one sample dir, two brdf color eval, none for light intersection
where I learn from:
https://github.com/knightcrawler25/Optix-PathTracer/blob/master/src/optixPathTracer/hit_program.cu
https://github.com/knightcrawler25/Optix-PathTracer/blob/master/src/optixPathTracer/light_hit_program.cu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am so sorry that I commit 5 times for such minor bug······
And seems the 5th commits still fails:
Error: Process completed with exit code 1.

Copy link
Member

@k-ye k-ye Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am so sorry that I commit 5 times for such minor bug

No worries && no need to apologize at all!

Just FYI, the check failed at Code Format https://github.com/taichi-dev/taichi/pull/1908/checks?check_run_id=1187328749. Usually you can add @taichi-gardener for review, which is a bot that does the code format automatically :)

I have advice for efficience:

Ah I see. Do I understand correctly that, if the direct light sampling actual hits the light source, then we no longer need to do the BRDF sampling (Sorry I'm no expert on this, and it's been a while since i wrote this example... )?

examples/cornell_box.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #1908 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1908   +/-   ##
=======================================
  Coverage   43.86%   43.86%           
=======================================
  Files          45       45           
  Lines        6190     6190           
  Branches     1099     1099           
=======================================
  Hits         2715     2715           
  Misses       3306     3306           
  Partials      169      169           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18bb5ed...a6cc61a. Read the comment docs.

@lyd405121 lyd405121 changed the title Update cornell_box.py [Example] fix rounding error for cornell_box.py Sep 29, 2020
add space for code format
@lyd405121 lyd405121 changed the title [Example] fix rounding error for cornell_box.py [Example] Fix rounding error for cornell_box.py Sep 30, 2020
[1] Add space for code format
[2] Delete over count dor indirect lighting
[1] previous comment is based on direct sampling light,not a good  strategy
[2] more info can get from mit course:https://graphics.stanford.edu/courses/cs348b-03/papers/veach-chapter9.pdf
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you!

@k-ye k-ye merged commit 21ad346 into taichi-dev:master Oct 1, 2020
@yuanming-hu yuanming-hu mentioned this pull request Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants