IBL wrong integration - energy conservation issues!

Project:YafaRay
Component:YafaRay Core
Category:bug report
Priority:critical
Assigned:David Bluecame
Status:closed
Description

Hello,

While testing some Wings3D scenes, oort has told me that the HDRI/IBL scenes were too bright compared with, for example, TheBounty.

I've done some checks and I've found what I believe is a serious bug in YafaRay: when rendering scenes with IBL, energy is not conserved and sometimes (often) the shiny diffuse surfaces reflect more light than the light coming from IBL, what I think is very wrong.

For this test, I've created a very simple test scene with the following:

* To avoid any color management issues, I've disabled sRGB, set all to linear, gamma=1 and gamma input=1

* World background set to "constant color" 0.5,0.5,0.5, IBL enabled with gain 1.0

* Sphere with shiny diffuse set to color 1.0,1.0,1.0 and diffuse amount 1.0

Under the above conditions, I would expect the sphere to reflect the IBL light, that is 0.5,0.5,0.5

However, unfortunately, in YafaRay v3.0.0-beta it does not happen. The sphere is reflecting more than 0.5,0.5,0.5!!

I think this is not a problem in the Shiny Diffuse material but in the Integration/Sampling process, which worries me a lot, as it's a fundamental part of YafaRay.

I've tried to trace back this bug and it seems to go back a long way. I've built the code from the very old v0.1.2 and the same issue happens there.

My results are:

* Blender internal: correct, sphere reflects 0.5 (you cannot distinguish the sphere from the background in this example)

IBL Energy Conservation - Blender 2.77a Internal, ok, sphere reflects approx 0.5 (IBL Energy Conservation - Blender 2.77a Internal, ok, sphere reflects approx 0.5 (

* Blender cycles: correct, sphere reflects 0.5 (you cannot distinguish the sphere from the background in this example)

IBL Energy Conservation - Blender 2.77a Cycles, ok, sphere reflects approx 0.5 (liIBL Energy Conservation - Blender 2.77a Cycles, ok, sphere reflects approx 0.5 (li

* YafaRay v3.0.0-beta INCORRECT, sphere reflects MORE than 0.5 (you can clearly distinguish the sphere from the background in this example)

IBL Energy Conservation - YafaRay v3.0.1 code - Sphere reflects more than 0.5 (linIBL Energy Conservation - YafaRay v3.0.1 code - Sphere reflects more than 0.5 (lin

* YafaRay v0.1.2 INCORRECT, sphere reflects MORE than 0.5 (you can clearly distinguish the sphere from the background in this example)

IBL Energy Conservation - YafaRay v0.1.2 code, Sphere reflects more than 0.5, stilIBL Energy Conservation - YafaRay v0.1.2 code, Sphere reflects more than 0.5, stil

 

I've attached the test scene for your reference.

 

Of course, this is a simple scene, but I would expect this issue to be quite bad when using other IBL with more contrast such as HDRI or Sky. Even when this seems to have been happening for a long time, for me this is now a maximum priority as it affects the realism of the scenes and the correct illumination of the objects. However, it will take me quite some time to figure out how to fix this, because I have the feeling that the TheBounty results are somewhat darker than they should, but I have to do more tests to confirm if this is true or not.

Comments

#1

Test scene attached here (for some reason does not show in the original post)

AttachmentSize
test_hdri1.blend.zip 138.32 KB

#2

For your information, I've built TheBounty 0.1.6.rc4 and (unless I made some kind of mistake while building it or setting the scene for the Bounty materials, etc), I think the same issue happens there:

IBL Energy Conservation - TheBounty v0.1.6.rc4 code - Sphere reflects more than 0.IBL Energy Conservation - TheBounty v0.1.6.rc4 code - Sphere reflects more than 0.

#3

Attached the .blend file with the Bounty settings

AttachmentSize
test_hdri1 (with TheBounty settings).blend.zip 137.39 KB

#4

Status:active» needs review

I think this issue requires input from several people to make sure if this is a bug or not, and how important this is to be fixed.

#5

I can see that in luxrender the behaviour is also the correct.

What I can see is that on blender's yafaray output the backgound is shown as  0.5 (when srgb space is enabled). The sphere is shown as 0.58, not 0.5.

So the image given to blender should be 0.5 when no colorspace is selected, so there is somewhere a double colorspace correction. Maybe this is the problem.

And the image writed to disk has the correct background value but sphere shows 0.58 value.

It is important to get coherent results with other software.

Regards

#6

I'm not sure this is related to color management, as I believe I set all to raw/linear/gamma input/output=1.0, etc

I suspect something weird in the integration/sampling. I cannot make sense of how Yafaray handles the PDF functions/values, multiple important sampling, etc. For now it's still too ahead of my current skills, but I'm trying to learn.

What I've seen is that there are for some reason two componemts in the integration of area/IBL lights: ccol and ccol2.

In this test scene, one of them is correct and gives the expected values, while the other is adding an "extra" that causes the >0.5 final value.

I have no idea yet why is this happening, but if I eventually have to rework the integration and sampling...well it will not be easy and will require ,any tests to ensure the changes don't break anything...

#7

Hi,

I've made a little chart and seems that every value goes in a different progression, maybe helps.

Thanks

AttachmentSize
yafaray_ibl.ods 18.32 KB

#8

Hello,

The reason why you see that "curve" that looks like a Color Management problem is because in my test scene I'm rendering into an image PNG file and not into Blender.

Blender is applying a sRGB conversion to the PNG when it loads it, that's the reason for those values. However, if you analyze directy the generated PNG file with a painting software you will see the "normal" values.

Otherwise you can choose to render into Blender and then the values will show correctly without that curve.

On the other side, things are even worse than I initially thought. Some materials such as Glossy have even worse behavior (appearing darker than they should, not reflecting all light!)

From my tests it looks like it goes back a very long time spanning many versions since (at least) v0.1.2. I'm investigating all this but I'm starting to worry that this is a fundamental problem in YafaRay, not sure if it will be difficult or very difficult to solve :-(

#9

IBL constant 0.5,0.5,0.5 and glossy give pretty bad results too:

Glossy diffuse color and amount=1.0, reflective color 1.0 and amount 0.0   (way too dark, it should reflect the background "as is")

test_hdri1b - 001.pngtest_hdri1b - 001.png

 

Glossy diffuse color 1.0 and amount=0.0, reflective color 1.0 and amount 1.0   (closer to the correct result, but what is that dark edge!?, maybe related to this bug report http://www.yafaray.org/node/571 ?)

test_hdri1cc - 001.pngtest_hdri1cc - 001.png

 

Glossy diffuse color and amount=1.0, reflective color 1.0 and amount 1.0   (too bright, not energy conserving! it should reflect the background "as is")

test_hdri1d - 001.pngtest_hdri1d - 001.png

 

Argh!!!! :-(

#10

In my tests same things happens in YafaRay v0.1.2 and TheBounty v0.1.6.rc4... I guess it's time to try to fix all these problems for good (if I can!) :-(((

#11

Be careful because a fresnel reflection could be a phisically correct model. You should compare first with another physical engine. Try with luxrender or mitsuba.

Regards

#12

Hello,

You are right, I will compare with LuxRender, for example, but I cannot believe those are correct. Moreover, these examples are even weirder. Look at the **tiny** difference in the Diffuse amount and the huge difference in the result. To me this is clearly a bug (or perhaps several bugs in different places):

weird IBL glossy - diffuse reflection exactly 0.0

 

weird IBL glossy - diffuse reflection just above 0.0.png

 

This cannot be right :-(((

AttachmentSize
weird IBL glossy - diffuse reflection exactly 0.0.png 226.44 KB
weird IBL glossy - diffuse reflection just above 0.0.png 230.7 KB

#13

This is a similar example with LuxRender (background Hemi color 0.5, sphere glossy diffuse color 1.0, amount 1.0 and reflection 1.0 with IOR fresnel 1.47). However this looks much more what I would expect:

AttachmentSize
weird IBL glossy - luxrender glossy with colors 1.0 and IOR fresnel 1.47.png 165.76 KB

#14

Yes. Seems wrong. Well, if i remember correctly, you had on the To Do list to improve the shaders model. It seems what is needed is a rewrite of the models, because fixing everything could be a parchment, not a solution.

Seems to be the next step. But the needed understanding of the yafaray code for this... do you feel confident about this? Take the time you need. I'm sure you will solve it. :)

I cannot help you, sorry. no idea of coding.

#15

I just want to say, since you mention "TheBounty", that I do not use the RC4 build. The results for SSS are  not as good as they are in RC3. I use your RC3 build of the Bounty.

Version 0.1.6 rc3.

*** 2015-03-28 unofficial build for Windows 7 and 8.1 (64 bits) by David Bluecame

Also, all the comparisons I have been doing since your relesas of 3.0.0 have been with YafaRay and not "TheBounty"

Thanks,

oort

#16

Status:needs review» ready to commit

Hello,

There are several problems here:

* First example with Shiny Diffuse energy conservation issues. I found this is caused by a bug, an incorrectly written macro in the Background Light code

* Second example, with Glossy, is probably a problem in the Glossy material itself. As I will focus on materials from now on, I will leave this for a later time.

So, I've sent this commit to solve the problem with Background Light, which is significant as the background light sampling was incorrect (and has been incorrect for years!!)

https://github.com/YafaRay/Core/commit/543e2a447742ad1f6d2b9f9a5197f2ded...

This fix will also solve many of the fireflies that happen when using HDRI for background IBL lighting.

This will be available in the upcoming YafaRay v3.0.1-beta

#17

Status:ready to commit» fixed

IBL sampling fixed in v3.0.1-beta: http://www.yafaray.org/community/forum/viewtopic.php?f=15&t=5173

 

Note: this fix does not solve the Glossy material problems, that's something I will try to solve in the short/medium term as the next objective is to improve the material system.

#18

Status:fixed» closed

Marked as "fixed" for more than 3 weeks without any further user comments. Closing.