Skip to content

Misc cleanup of aspheric_surf code#1

Open
jtkornel wants to merge 8 commits intokrisrst:krisrst/advanced_lensesfrom
jtkornel:users/jtk/misc_cleanup
Open

Misc cleanup of aspheric_surf code#1
jtkornel wants to merge 8 commits intokrisrst:krisrst/advanced_lensesfrom
jtkornel:users/jtk/misc_cleanup

Conversation

@jtkornel
Copy link
Copy Markdown
Collaborator

@jtkornel jtkornel commented Jul 27, 2022

Please add the labels (e.g. bug, feature, ..) corresponding to this PR

Description

  • Fixed curvature and normal flip so that there are no special case handling in the code or limitations for where rays originate.
  • The near solution is used if it is valid, otherwise the far solution is used. If far is invalid too it is a no-hit. (A solution is valid if the ray parameter is positive and the solution is within some lens surface bound)
  • Curvature flip can also be done by setting negative radius, as the formulas allow that "out of the box" and it is common in optics specs.
  • Removed an unused radius parameter.
  • Removed use of m_ prefix where the variable is not a member variable.
  • Change from pow(x,2.0) to sqr(x) which gives shorter expressions and better performance.

I have also independently verified that the intersection formula was/is correct. But for hyperbolic surfaces (kappa < 0) the boxing of the lens surface (currently named point_on_lens_surface) has not been tight enough because there is a mirror hyperbola on the other side of the origin along z, thus another z bound is needed. Will do fix in another PR.

Fixes # (issue)

Testing

Please describe the tests that you added to verify your changes.

Checklist:

Please make sure to complete this checklist before requesting a review.

  • My code follows the style guidelines of this project
  • My changes generate no new warnings
  • My code also compiles for gpu_* and packet_* variants. If you can't test this, please leave below
  • I have commented my code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I cleaned the commit history and removed any "Merge" commits
  • I give permission that the Mitsuba 2 project may redistribute my contributions under the terms of its license

jtkornel added 7 commits July 20, 2022 12:46
Enoki offers a template which rewrites it to x*x, used by other plugins
Main reason is that the expressions become a bit simpler and readable
This may use a little less compute resources if it avoids a function call (did not see any significant change with gpu_rgb profile)
The radius parameter was useful for the basic shapes like cylinder and sphere to scale it from unit size,
but with more fine control of the geometry through other parameters it is not necessary.

Also arbitrary scaling through the m_to_world transform can destroy assumptions in the geometry calculations so do not allow that,
require that scaling is an identity matrix.

Translation and translation through the m_to_world transform is still allowed and useful (but rotation may need a bit of fixing)
This gives a nice speedup from 19s to 13.3s with the GPU backend on my machine

BEFORE

2022-07-20 15:19:55 INFO  main  [PluginManager] Loading plugin "plugins/asphsurf.so" ..
Update
AsphSurf using flip=false inv_norm=false kappa=0.00 radius=172.00 (rho=0.005814) hlim=12.70 zlim=0.47
2022-07-20 15:19:55 INFO  main  [PluginManager] Loading plugin "plugins/cylhollow.so" ..
2022-07-20 15:19:55 INFO  main  [PluginManager] Loading plugin "plugins/diffuse.so" ..
2022-07-20 15:19:55 INFO  main  [PluginManager] Loading plugin "plugins/uniform.so" ..
Update
AsphSurf using flip=true inv_norm=false kappa=0.00 radius=30.06 (rho=0.033267) hlim=12.70 zlim=2.81
2022-07-20 15:19:55 INFO  main  [PluginManager] Loading plugin "plugins/obj.so" ..
2022-07-20 15:19:55 INFO  main  [PluginManager] Loading plugin "plugins/area.so" ..
2022-07-20 15:19:55 INFO  main  [Scene] Building scene in OptiX ..
2022-07-20 15:19:55 INFO  main  [SamplingIntegrator] Start rendering...
2022-07-20 15:20:14 INFO  main  [SamplingIntegrator] Rendering finished. (took 19.067s)
2022-07-20 15:20:14 INFO  main  [HDRFilm] ✔  Developing "test.exr" ..
2022-07-20 15:20:14 INFO  main  [Profiler] Recorded 1954 samples, used 11/256 hash table entries.
2022-07-20 15:20:14 INFO  main  [Profiler] ⏱  Profile (hierarchical):
2022-07-20 15:20:14 INFO  main  [Profiler]     Idle                                           2.00%
2022-07-20 15:20:14 INFO  main  [Profiler]     Integrator::render()                           97.70%
2022-07-20 15:20:14 INFO  main  [Profiler]       Endpoint::sample_ray()                       0.05%
2022-07-20 15:20:14 INFO  main  [Profiler]       ImageBlock::put()                            0.26%
2022-07-20 15:20:14 INFO  main  [Profiler]       SamplingIntegrator::sample()                 97.39%
2022-07-20 15:20:14 INFO  main  [Profiler]         BSDF::eval(), pdf()                        0.10%
2022-07-20 15:20:14 INFO  main  [Profiler]         BSDF::sample()                             0.20%
2022-07-20 15:20:14 INFO  main  [Profiler]         Endpoint::eval(), pdf()                    0.05%
2022-07-20 15:20:14 INFO  main  [Profiler]         Scene::ray_intersect()                     16.17%
2022-07-20 15:20:14 INFO  main  [Profiler]         Scene::sample_emitter_direction()          8.96%
2022-07-20 15:20:14 INFO  main  [Profiler]           Endpoint::sample_direction()             0.20%
2022-07-20 15:20:14 INFO  main  [Profiler]           Scene::ray_test()                        8.75%
2022-07-20 15:20:14 INFO  main  [Profiler]     Scene initialization                           0.31%
2022-07-20 15:20:14 INFO  main  [Profiler] ⏱  Profile (flat):
2022-07-20 15:20:14 INFO  main  [Profiler]     SamplingIntegrator::sample()                   71.90%
2022-07-20 15:20:14 INFO  main  [Profiler]     Scene::ray_intersect()                         16.17%
2022-07-20 15:20:14 INFO  main  [Profiler]     Scene::ray_test()                              8.75%
2022-07-20 15:20:14 INFO  main  [Profiler]     Idle                                           2.00%
2022-07-20 15:20:14 INFO  main  [Profiler]     Scene initialization                           0.31%
2022-07-20 15:20:14 INFO  main  [Profiler]     ImageBlock::put()                              0.26%
2022-07-20 15:20:14 INFO  main  [Profiler]     Endpoint::sample_direction()                   0.20%
2022-07-20 15:20:14 INFO  main  [Profiler]     BSDF::sample()                                 0.20%
2022-07-20 15:20:14 INFO  main  [Profiler]     BSDF::eval(), pdf()                            0.10%
2022-07-20 15:20:14 INFO  main  [Profiler]     Endpoint::sample_ray()                         0.05%
2022-07-20 15:20:14 INFO  main  [Profiler]     Endpoint::eval(), pdf()                        0.05%

AFTER

Update
AsphSurf using flip=false inv_norm=false kappa=0.00 radius=172.00 (rho=0.005814) hlim=12.70 zlim=0.47
2022-07-20 15:45:44 INFO  main  [PluginManager] Loading plugin "plugins/cylhollow.so" ..
2022-07-20 15:45:44 INFO  main  [PluginManager] Loading plugin "plugins/diffuse.so" ..
2022-07-20 15:45:44 INFO  main  [PluginManager] Loading plugin "plugins/uniform.so" ..
Update
AsphSurf using flip=true inv_norm=false kappa=0.00 radius=30.06 (rho=0.033267) hlim=12.70 zlim=2.81
2022-07-20 15:45:44 INFO  main  [PluginManager] Loading plugin "plugins/obj.so" ..
2022-07-20 15:45:44 INFO  main  [PluginManager] Loading plugin "plugins/area.so" ..
2022-07-20 15:45:44 INFO  main  [Scene] Building scene in OptiX ..
2022-07-20 15:45:44 INFO  main  [SamplingIntegrator] Start rendering...
2022-07-20 15:45:58 INFO  main  [SamplingIntegrator] Rendering finished. (took 13.28s)
2022-07-20 15:45:58 INFO  main  [HDRFilm] ✔  Developing "test.exr" ..
2022-07-20 15:45:58 INFO  main  [Profiler] Recorded 1362 samples, used 10/256 hash table entries.
2022-07-20 15:45:58 INFO  main  [Profiler] ⏱  Profile (hierarchical):
2022-07-20 15:45:58 INFO  main  [Profiler]     Idle                                           2.35%
2022-07-20 15:45:58 INFO  main  [Profiler]     Integrator::render()                           97.28%
2022-07-20 15:45:58 INFO  main  [Profiler]       ImageBlock::put()                            0.51%
2022-07-20 15:45:58 INFO  main  [Profiler]       SamplingIntegrator::sample()                 96.77%
2022-07-20 15:45:58 INFO  main  [Profiler]         BSDF::eval(), pdf()                        0.15%
2022-07-20 15:45:58 INFO  main  [Profiler]         BSDF::sample()                             0.07%
2022-07-20 15:45:58 INFO  main  [Profiler]         Scene::ray_intersect()                     22.32%
2022-07-20 15:45:58 INFO  main  [Profiler]         Scene::sample_emitter_direction()          12.04%
2022-07-20 15:45:58 INFO  main  [Profiler]           Endpoint::sample_direction()             0.29%
2022-07-20 15:45:58 INFO  main  [Profiler]           Scene::ray_test()                        11.60%
2022-07-20 15:45:58 INFO  main  [Profiler]     Scene initialization                           0.37%
2022-07-20 15:45:58 INFO  main  [Profiler] ⏱  Profile (flat):
2022-07-20 15:45:58 INFO  main  [Profiler]     SamplingIntegrator::sample()                   62.19%
2022-07-20 15:45:58 INFO  main  [Profiler]     Scene::ray_intersect()                         22.32%
2022-07-20 15:45:58 INFO  main  [Profiler]     Scene::ray_test()                              11.60%
2022-07-20 15:45:58 INFO  main  [Profiler]     Idle                                           2.35%
2022-07-20 15:45:58 INFO  main  [Profiler]     ImageBlock::put()                              0.51%
2022-07-20 15:45:58 INFO  main  [Profiler]     Scene initialization                           0.37%
2022-07-20 15:45:58 INFO  main  [Profiler]     Endpoint::sample_direction()                   0.29%
2022-07-20 15:45:58 INFO  main  [Profiler]     BSDF::eval(), pdf()                            0.15%
2022-07-20 15:45:58 INFO  main  [Profiler]     Scene::sample_emitter_direction()              0.15%
2022-07-20 15:45:58 INFO  main  [Profiler]     BSDF::sample()                                 0.07%
Remove the special case handling for curvature flipping

Now allow curvature flipping by using negative radius values which is common in optics specs. The flip flag is still kept working.
Surface normals always pointing in the negative z-direction by default
Surface normals must therefore be flipped for "exit surfaces" facing right
@jtkornel jtkornel changed the base branch from master to krisrst/advanced_lenses July 27, 2022 07:36
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.

1 participant