Refraction with pyluxcore

Use this forum for general user support and related questions.
mick
Posts: 51
Joined: Mon May 21, 2018 7:57 pm

Re: Refraction with pyluxcore

Post by mick » Thu May 31, 2018 3:33 pm

Thanks. I'll check that code.

But just one immediate question: My objective is to precisely simulate the effect of lenses. Currently I assume that the best I can do is create a quite fine mesh to approximate the continuously concave/convex surfaces. I understand that normals help to smooth the shading of an object. I don't care much about the precise shading of the lenses. I want a precise refraction effect. Is it correct that luxcore cannot smooth that with normals?

If luxcore is capable to handle to calculate refraction of "non-flat shaded" meshes then it would bring me back to the question about how to specify that normals with pyluxcore.

User avatar
B.Y.O.B.
Developer
Posts: 1329
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Refraction with pyluxcore

Post by B.Y.O.B. » Thu May 31, 2018 3:52 pm

mick wrote:
Thu May 31, 2018 3:33 pm
But just one immediate question: My objective is to precisely simulate the effect of lenses. Currently I assume that the best I can do is create a quite fine mesh to approximate the continuously concave/convex surfaces. I understand that normals help to smooth the shading of an object. I don't care much about the precise shading of the lenses. I want a precise refraction effect. Is it correct that luxcore cannot smooth that with normals?
Well, so far the topic was a prism, which I assume you modelled out of a few flat triangles.

Lenses are another topic.
For lenses with curved surfaces you will want to use "smooth shading", which means that adjacent faces share their vertices and the vertices use an interpolated version of the surrounding face normals.
I do not know how this interpolation process works in detail, but I'm pretty sure there's a lot of information about it online.

Both flat and smooth shading are "correct" and produce correct reflections and refractions.
They are just a different way to interpret a mesh: Flat shading interprets it as a collection of independent flat faces, while smooth shading treats the mesh only as some kind of "supporting structure" for a smooth surface that is not really there, but simulated via normal interpolation.

Here is an image with the same mesh duplicated, on the left exported with flat shading, on the right with smooth shading.
Both glass spheres are "correct", but the one on the left appears to us as something like a cut diamond, with many individual facets, while the one on the right appears as a smooth, round sphere. Behind the scenes they are the same mesh, interpreted two different ways.
Attachments
scrn_2018-05-31_17-44-19.png
Support LuxCoreRender project with salts and bounties

mick
Posts: 51
Joined: Mon May 21, 2018 7:57 pm

Re: Refraction with pyluxcore

Post by mick » Thu May 31, 2018 10:11 pm

Thanks for the good explanation. I think I understand now.

But unfortunately I can still not produce refraction and realistic dissipation. I created a prism with flat shading between a wide laser and a projection plane.
image_rgb.png
The prism can hardly be seen. It can be imagined by the less scattering. This is because the prism volume is clear glass, in contrast to the world volume which is homogenous. This should be an indication the luxcore recognizes the prism as closed object with different volume inside, right?

But still there is no effect of refraction visible on the projection plane. There seems to be some reflective dissipation on the light-frontal face of the prism. And there is very random dissipation visible in the air scattering. I cannot bring this into accordance with real world experience.

Below a visualization of the prism ply to which I generated pikes to represent the normals. To me this looks fine. But maybe you can check better. So the ply is attached too. [Oops, cannot attach this file type, right.]
Untitled.png
Tomorrow I'll probably create a github project for it, if still necessary. But it would be great if could give me helpful hints now.

Is it the mesh, or there something wrong with the setup of rendering engine, volumes, laser/prism/projection plane?

User avatar
Dade
Developer
Posts: 1187
Joined: Mon Dec 04, 2017 8:36 pm

Re: Refraction with pyluxcore

Post by Dade » Thu May 31, 2018 10:26 pm

Are you using BIDIRCPU ?
Support LuxCoreRender project with salts and bounties

User avatar
B.Y.O.B.
Developer
Posts: 1329
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Refraction with pyluxcore

Post by B.Y.O.B. » Thu May 31, 2018 10:47 pm

Your prism mesh looks ok.
Did you specify an IOR for the volumes?
The exterior volume should use e.g. IOR = 1.0 (air), the interior volume should use e.g. IOR = 1.5 (glass) to get refraction.
(Just example values of course)

I think it would help if you could add a sky2 light with very low gain (something like 0.00001) so we can see a bit more, I can not really make out how your prism is placed in there.
Support LuxCoreRender project with salts and bounties

mick
Posts: 51
Joined: Mon May 21, 2018 7:57 pm

Re: Refraction with pyluxcore

Post by mick » Fri Jun 01, 2018 7:45 am

Yes, I set IORs.

Code: Select all

      scene.volumes.vol_air.type = homogeneous
      scene.volumes.vol_air.multiscattering = 0
      scene.volumes.vol_air.scattering = 0.001 0.001 0.001
      scene.volumes.vol_air.absorption = 0. 0. 0.
      scene.volumes.vol_air.asymmetry = 0.0 0.0 0.0
      scene.world.volume.default = vol_air

  props.Set(pyluxcore.Property("scene.volumes."+prism_vol+".type", "clear"))
  props.Set(pyluxcore.Property("scene.volumes."+prism_vol+".absorption", [0,0,0]))
  props.Set(pyluxcore.Property("scene.volumes."+prism_vol+".ior", 1.4580))
Here with weak sky2:
image_rgb.png

mick
Posts: 51
Joined: Mon May 21, 2018 7:57 pm

Re: Refraction with pyluxcore

Post by mick » Fri Jun 01, 2018 5:45 pm

Here the link to the github project with the test code:
https://github.com/ujikol/pyluxcore_test

User avatar
Dade
Developer
Posts: 1187
Joined: Mon Dec 04, 2017 8:36 pm

Re: Refraction with pyluxcore

Post by Dade » Fri Jun 01, 2018 8:52 pm

mick wrote:
Fri Jun 01, 2018 5:45 pm
Here the link to the github project with the test code:
https://github.com/ujikol/pyluxcore_test
Try to post the scene (.cfg, .scn, etc.) and answer questions otherwise it is a bit hard to help you.
Support LuxCoreRender project with salts and bounties

mick
Posts: 51
Joined: Mon May 21, 2018 7:57 pm

Re: Refraction with pyluxcore

Post by mick » Sat Jun 02, 2018 9:04 am

The forum does not allow to upload ply files.
render.cfg
(1.21 KiB) Downloaded 20 times
scene.scn
(10.43 KiB) Downloaded 16 times
I included the cfg, scn and ply files in the github repository, which B.Y.O.B. requested.

Question: Why isn't there any effect of refraction visible on the projection plane?

User avatar
B.Y.O.B.
Developer
Posts: 1329
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Refraction with pyluxcore

Post by B.Y.O.B. » Sat Jun 02, 2018 9:15 am

You can always zip disallowed file types to upload them.
Try to render with engine = BIDIRCPU, sampler = METROPOLIS.
Support LuxCoreRender project with salts and bounties

Post Reply