Page 1 of 1

Issues with Sun and Distant light

Posted: Tue Feb 26, 2019 10:59 pm
by CodeHD
I was just playing around with glass and caustics and noticed the following two things with Sun and Distant light:

Setup (.blend attached):
- Diffuse Plane
- Glass Cylinder vertically above
- Sun source shining down vertically.
- BiDir of course for the caustics, any sampler
- v2.2alpha0 and a late 2.1 daily build

Issue #1:
The cylinder shouldn't cause much attenuation of light as the Sunlight is passing throgh 2 perpendicular surfaces. A bit darker underneath maybe due to Fresnel reflections sending some light back.

With the default Sun this looks as expected:
Sun_size1_BiDir.png
With the relative size set to 0.1, the circle underneath becomes brighter than the plane
Sun_size0p1_BiDir.png
With the distant source, this behaviour seems a bit worse, being visible at a size (half angle) of 0.25 degree, like the Sun.
Distant_size0p25_BiDir.png
Issue #2:
In the image with the distant source, notice how the plane gets darker away from the camera. This shouldn't be the case for a matte surface illuminated homogeneously.

Observations:
- Only happens with BiDir, not Path
- Independent of sampler and its settings.
- Only happens with distant, not Sun

Re: Issues with Sun and Distant light

Posted: Sun Apr 28, 2019 11:58 am
by CodeHD
This issue is still open in the latest daily build.

I just played around with issue #2 from my previous post again, there is also an issue with BiDir and the Sun lamp, not just distant. It just wasn't apparent to me in my earlier example scene.

(I could use it as another project to get familir with the code, but again I can't judge if it is something I will be able to crack down quickly...)

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 12:00 am
by Fox
i tested, this is not reflection, but transmission.
It looks like when i enable only red, or only green, or only blue transmission, then it's not brighter.

See that threat viewtopic.php?f=4&t=808&start=10

Can it be related, no issue with mesh emitter of same brightness?

With BiDirVM and random, 300sp
Color MiauMiau.jpg
Gray MiauMiau.jpg
This one is too BiDirVmCpu.jpg

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 9:04 am
by Dade
CodeHD wrote: Tue Feb 26, 2019 10:59 pm Issue #1:
The cylinder shouldn't cause much attenuation of light as the Sunlight is passing throgh 2 perpendicular surfaces. A bit darker underneath maybe due to Fresnel reflections sending some light back.
This is a numerical precision problem. If you check the code: https://github.com/LuxCoreRender/LuxCor ... ht.cpp#L40

The sun radius, scaled by the relative size, is divided by earth<->sun distance to compute the sine of the angle. Because of your scale factor, it is a small number divided by a very big one. The number is than squared to compute the sine square and becomes even smaller.

Than, to compute the cosine:

Code: Select all

cosThetaMax = sqrtf(1.f - sin2ThetaMax);
At this point, the cosine of the angle is 1.0 while the sine is > 0.0 and this is clearly very wrong. This happens because: "1.f - sin2ThetaMax" is 1.0 with floating point numbers and square root of 1.0 is 1.0.

Short version: relative size was never intended to be used for values <1.0 so I'm now capping the value to be always >= 1.0. the sun is already large as a pixel at is real world size.

I will check the other issue.

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 9:52 am
by CodeHD
Dade wrote: Mon Apr 29, 2019 9:04 am This is a numerical precision problem. If you check the code: https://github.com/LuxCoreRender/LuxCor ... ht.cpp#L40

[...]

Short version: relative size was never intended to be used for values <1.0 so I'm now capping the value to be always >= 1.0. the sun is already large as a pixel at is real world size.

[...]
Thanks for checking it out!
It sound to me though as if the problem you describe is specific to the sun lamp. I do not see equivalent code in the distant light, which suffers from the same problem.

I personally don't see a problem with size being limited for the Sun-type lamp (why not even remove it entirely?). After all, distant should provide the same features for simulation of optical phenomena.
It would be a shame to not have any source that can be smaller than the Sun, but I don't think that is what you meant to say anyways, since you only spoke of the Sun (?)
(sorry if this is already what you meant by you will check out the other issue)

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 10:21 am
by Dade
CodeHD wrote: Mon Apr 29, 2019 9:52 am I personally don't see a problem with size being limited for the Sun-type lamp (why not even remove it entirely?). After all, distant should provide the same features for simulation of optical phenomena.
The relative size parameter was originally intended to be used as an artistic tool in order to exaggerate and render some "dramatic" sunset like:

Image

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 10:58 am
by epilectrolytics
If someone would want to render a Jupiter moon scenery a smaller relative sun size might be desired...

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 12:14 pm
by B.Y.O.B.
epilectrolytics wrote: Mon Apr 29, 2019 10:58 am If someone would want to render a Jupiter moon scenery a smaller relative sun size might be desired...
You should use the distant light for this. The sun lamp includes simulation of the earth's atmosphere, you would not have this around Jupiter.
The sun lamp is only useful if you need sunlight in a scene located on the earth (behind earth's atmosphere). For everything else you should use distant light (e.g. rendering the ISS over earth, because it's outside the atmosphere).

By the way, you can make pictures like the one linked by Dade purely with relsize = 1. You just need to replicate the camera paremeters used, e.g. use a tele lens (large focal length like 600 mm).
It's purely an artistic parameter for cases where you want a shorter focal length for some reason, but still need a big sun.

Another use case: larger relsize can also be useful to simulate a slightly overcast sky (it makes the shadows softer).

Re: Issues with Sun and Distant light

Posted: Mon Apr 29, 2019 12:30 pm
by Dade
B.Y.O.B. wrote: Mon Apr 29, 2019 12:14 pm Another use case: larger relsize can also be useful to simulate a slightly overcast sky (it makes the shadows softer).
A large rel. size parameter can also be used to alleviate caustics fireflies with path tracing (it makes easier for a path to hit the sun) :idea: