appleseedhq / appleseed

A modern open source rendering engine for animation and visual effects
https://appleseedhq.net/
MIT License
2.2k stars 329 forks source link

Importance sampling of OSL environment EDFs #2784

Closed lorentzo closed 4 years ago

lorentzo commented 4 years ago

Contribution of this PR

Issue:

This is PR for issue #701 (Importance sampling of OSL environment EDFs).

Summary:

Notes:

Further work

lorentzo commented 4 years ago

@dictoon thank you for detailed code review. I have fixed everything you asked. I have two doubts for now:

lorentzo commented 4 years ago

OK, now all commits have been squashed and rebased on master. No conflicts. Buildable.

Only this is left to consider: https://github.com/appleseedhq/appleseed/pull/2784#issuecomment-593100136.

I have discussed this problem in Discord #dev, here: https://discordapp.com/channels/430063582777049089/430064067873472526/683677424088514571.

dictoon commented 4 years ago

To answer your previous points:

Moving build_importance_map() from on_frame_begin() to on_render_begin() as you proposed in #2784 (comment) results in segmentation error while calling m_osl_shadergroup_exec.execute_background() (this function is needed for building the importance map). After some experiments I think I have figured out what might be the problem. I think that when on_render_begin() is called, OSL shaders haven't been configured yet (path, headers etc.). While when build_importance_map() is in on_frame_begin(), no problem occurs. That is because on_frame_begin() is called after the OSL shaders have been configured. I will discuss this further on discord.

That's interesting. I haven't checked exactly what's going on but I trust your analysis. What we could do to prevent this PR from stalling is keep this in on_frame_begin() for now, with a comment explaining the problem, then investigate how to fix the problem in a second time.

The impact of rebuilding the importance map in on_frame_begin() is low since you check if the shader group version has changed.

Do you require some additional test scenes for this issue? For example I have modified some test scenes for OSL environment where metadata is used.

It would be nice to have at least one scene in the test suite that checks that this code works correctly.

lorentzo commented 4 years ago

To answer your previous points:

Moving build_importance_map() from on_frame_begin() to on_render_begin() as you proposed in #2784 (comment) results in segmentation error while calling m_osl_shadergroup_exec.execute_background() (this function is needed for building the importance map). After some experiments I think I have figured out what might be the problem. I think that when on_render_begin() is called, OSL shaders haven't been configured yet (path, headers etc.). While when build_importance_map() is in on_frame_begin(), no problem occurs. That is because on_frame_begin() is called after the OSL shaders have been configured. I will discuss this further on discord.

That's interesting. I haven't checked exactly what's going on but I trust your analysis. What we could do to prevent this PR from stalling is keep this in on_frame_begin() for now, with a comment explaining the problem, then investigate how to fix the problem in a second time.

The impact of rebuilding the importance map in on_frame_begin() is low since you check if the shader group version has changed.

I would suggest opening an issue: "Investigate a way to add build importance map inside of OSLEnvironmentEDF::on_render_begin() instead of OSLEnvironmentEDF::on_frame_begin()". I would reference this PR and provide analysis that I have done. Do you agree?

Do you require some additional test scenes for this issue? For example I have modified some test scenes for OSL environment where metadata is used.

It would be nice to have at least one scene in the test suite that checks that this code works correctly.

The test suite already contains a test scene that uses/test the code I have created, here: https://github.com/appleseedhq/appleseed/blob/master/sandbox/tests/test%20scenes/environment/29%20-%20osl%20environment%20reflection%20direct%20lighting.appleseed. This test is a good comparison with the LongLat environment EDF.

NEW: I have also added the test scene in this PR. I have used HDR from texturehaven.com. I have set explicit importance map size to 2048. Also, I have stored the reference image. Now, there are 2 test scenes for OSL environment EDF!

lorentzo commented 4 years ago

OK, now all the required changes are done. PR is squashed and rebased on the master. It is ready for merging. Summary:

Further work. Issue: "Investigate a way to add build importance map inside of OSLEnvironmentEDF::on_render_begin() instead of OSLEnvironmentEDF::on_frame_begin()". NEW: @est77 proposed:

"in masterrenderer.cpp, line 359 is where we compile OSL shaders if we move that a few lines, before on_render_begin is called, we would have compiled OSL shaders in on_render_begin"

lorentzo commented 4 years ago

HDR map colorful_studio_2k.hdr is taken from https://hdrihaven.com/ which states:

All HDRIs are licenced as CC0 and can be downloaded instantly, giving you complete freedom.

dictoon commented 4 years ago

Thanks for your contribution!