How does Blender Combine the Refraction Pass?

Sebastian, thanks it works! I was pretty sure that I had checked that the combined pass was the same as the diffuse pass beforehand (which it is, sort of). It’s true I did have the same problem when using the diffuse pass in place of the Combined pass (with other passes excluded). But the difference is that I never un-clicked the “exclude from Combined” buttons. But this shouldn’t affect the diffuse pass at all!

Either way, it works now. The solution is to use the Diffuse pass and to NOT click the exclusion buttons for the other pass. To me, these buttons should strictly affect the Combined pass, but for some reason it makes Diffuse not work if you click them.

I’ll look into your environment lighting problem.

OK I have a few questions then, Sebastian.

First, your pre-processing nodes for the environment lighting: 0.2EnvColor. Do you know that environment lighting must be multiplied by the color pass? And is multiplying the environment pass by 0.2 just a guess? I see that it does correctly match the Combined pass for the plane in your file (but not the sphere).

Next, do you know how to composite environment lighting correctly in the absence of refraction, reflection, AO? I changed the scene so that there was no reflection, refraction, or AO were present. Adding the unaltered Env pass gave an incorrect result, as did adding the Env pass using your preprocessing nodes (although this comes much closer). So if we don’t have compositing the Env pass by itself figured out, we should focus on that for simplicity (should be the same in the end).

EDIT: Oh, I noticed you didn’t have Environment Lighting enabled in your file. How come you don’t have to enable Environment Lighting in the world settings for the pass to be available? Is this just because when you enable AO, it activates the “Gather” panel? That seems to be the case; when I disable AO, the Environment Lighting pass does not render. Maybe this is a bug, or at least unintended.

I got that information form this site: http://wiki.blender.org/index.php/Doc:Manual/Render/Passes
I found that Env.Light is basically the same as AO, if it is just set to white. If you compare these passes you’ll see that they look identically. But they are then treated differently, AO by multiplying, Env.Light by multiplying with colorpass and then adding according to the setting in EnvLight settings. (Usually factor 1)
But I am really not sure what brought me up to that setup. Maybe the link I posted above. I just found out that it works.
And again, without reflection/refraction, the setup with AO and Env.Light do work fine. But I have really no idea how blender treats Env.Light in combination with refraction.

A working setup with AO and EnvLight and reflections, but without any transparency looks like this ( In my tests it seemed that you need a factor of 0.4 instead of 0.5 for EnvLightPass):
(Diffuse*(InvertedAlpha+Shadow))(InvertedAlpha+AO)+Spec+Emit+((EnvLight[50% grey])*0.4)+Reflection

I suck at math, so this might be wrong. An image might be better, so here it is:
http://img.skitch.com/20100728-unxxncb2cnft9f3i6bwhsrpew.jpg
File is here:

But as soon as you turn on refraction, this setup doesn’t work anymore.

Oh, sorry. You’re right, that setup does work with no refraction. I think it just didn’t update for me when I changed back to no refraction.

But I digress. Problem solved! If you use the difference node to look at the error between the final image and the composite you can see that the only part in error in your composite is the sphere. And this difference is not a pure red color - it’s a bit shaded. In fact it looks exactly like the shaded red sphere in the altered environment lighting pass (where you multiply 0.4*(50% gray)colorEnvLight). So the solution is to (using the Object Index pass) isolate the red sphere (or the object(s) with transparency) from the “altered environment light” and add that to the composite an additional time. Checking the difference node then shows that the images are in agreement (i.e. a black result. Also, I didn’t worry about compositing the sky.)

As to why this needs to be added in an additional time, I have no idea. Maybe this is subtracted from the refraction pass for some reason. I’ve looked into this part of the code before and there’s a lot of back and forth subtracting and adding of passes in order to get the correct result - could be a mistake here. Or maybe Blender’s Combined method incorrectly adds an extra copy of this environment light. I’m not sure which is the case, but my feeling is something is wrong here - a bug somewhere.

So basically I think either 1) the refraction pass mistakenly has a negative environment light component included or 2) Blender’s Combined method is applying extra environment lighting to transparent objects (in which case the Combined pass is actually the “incorrect” one!).

So this does correct the problem, but I find it hard to believe this is what was intended to get a “correct” result. Any thoughts?

Here’s my .blend: http://dl.dropbox.com/u/1531862/Blender/CompTest_Working_Env-AO_WITH-refract.blend

A related note, check out this page (specifically the Render Pass section): http://wiki.blender.org/index.php/User:Broken/BreakingRenderCompatibility

I couldn’t agree more.

Wow! Thank you! This seems to work!
Yeah, and judging from Broken’s complaints in your link above about the way reflect/refract are handled by BI in renderlayers there really seems to be quite a mess. Maybe that will be cleaned up sometimes.
But knowing this workaround already helps a lot! Maybe not what you’d call elegant, but still doable.
Thanks again.
So our questions are all answered. Or are they?
:slight_smile:

Yes. I think now they are. I added an Indirect Lighting pass. The same technique is required for this pass as for the Environment Lighting pass.

==> 0.450%grayIndLight*Color -> AlphaOver Object Index (for refractive materials) and Add back to your other nodes.

So I think this pretty much solves everything.

My final .blend: http://dl.dropbox.com/u/1531862/Blender/CompTest_Working_Env-AO-Refract-IndLight.blend

This was an amazing analysis, SCUEY and SebastianK. I want to try your formula now!

Hey SCUEY! I’ve been playing around with this setup, and it works great so far.
However, I’ve got a problem with this setup when working with different Alpha-settings. With alpha set to sky everything works as described. But once you set the Alpha to PREMUL, there are some problems.
Here’s an image that illustrates that, and also the blendfile.

http://img.skitch.com/20100830-b4957cqx2naux35npcx71txb6d.preview.jpg

First of all, with alpha set to premul, it exceeds the values between 0-1. So when you add shadow and AO to alpha, you’ll get a problem, unless you “cut off” values above 1 with a map-value-node.
When you compare the outputs of a scene with SKY and a scene with PREMUL with a difference-node, you’ll see that all passes are exactly the same, except the Alpha.
So there has to be a change in that formula to achieve a correct combination of the nodes. That change takes place in the refraction pass.
But I simply cannot figure out how and what to change so that the refraction is composited correctly. I believe you have to do something with the Alpha-output.
Do you have any ideas?

I think i found a possible solution for the problem from my previous post, which at the same time seems to reveal a bug with Blender’s scene-alpha. When you render with alpha set to PREMUL, and have objects with transparency in your scene, the alpha pass includes values that are greater than one. That forces you to create some workarounds for different isseus, for example you have to cut off the alpha values above one to still be able to compose shadow and AO (see image)

http://img.skitch.com/20100902-errj1t24jij1g738mn5qahmym6.preview.jpg

So, the solution to the problem in my previous post is to multiply the final composite with the “wrong” alpha pass in the end. Due to the values above 1 in alpha, the areas with transparency becomes brighter. See image:

http://img.skitch.com/20100902-cgynj3xsd493i4e8i6h6kb8r61.preview.jpg

So i think the question is: is it “legal” for the alpha-pass to have pixel-values above 1?

Here’s the blendfile: https://www.dropbox.com/s/ec4lvgbo2qmdguq/PREMUL_problems.blend

Ah, Sebastian, sorry I couldn’t get back to you on this earlier! I’ve been absorbed by my thesis research lately and haven’t had much of a chance to look into the issue. I’ve got a couple of days off now so maybe I’ll have a chance to check it out. Are you still having the problem?

Are you using color correction?

Thanks SCUEY.
Well, no, I have a solution for this problem now, which I described in my previous post. I am pretty sure it is a bug, or at least a very bad workaround for something. The alpha-pass should not have values greater than one.

Btw, remember that we thought Env.Light has to be multiplied with 50%grey0.4?
Hehe, turns out that is just to get the intensity of the diffuse color. So instead in a correct setup you have to multiply the color pass with the intensity value of the diffuse color (the default is usually 0.8, see intensity slider in shading buttons), and after that multiply it with the Env.Light.
So I think the correct setup is:
Diff
(AOShadow))+Spec+Emit+/(Ind.Light(Color*[Intensity color value])factor)+((Env.Light(Color*[Intensity color value])*factor)+Reflection+Refraction
Although:
When you have alpha values lower than 1 and use transparency then the color-pass gets messed up. if you have alpha 0 on ObjectX then X will be completely black in the color pass. Which of course is wrong. (Did not happen in 2.49b). To work around that you have to give the transparent object an ObjectIndex and use that to give X the correct color in the nodes / color-pass, so that you have the correct Env.Light and Ind.Light pass (which of course would otherwise be black, due to the multiplication).

Hello Sebastian, I was confused on something you said in your tut at cmiVFX and thought I would Google it before asking you and that brought me here.
I’ll have to reread this post again when it’s quiet and I have time, but my confusion was on the notion that light had to be Added and Shadows multiplied.
So I get Env Lighting is really similar to AO and therefore must be multiplied (since it is in the shadow family), but not sure why Indirect Lighting is multiplied.
I would think since it is light it would have to Added.
Similarly I’m confused on why Color is multiplied, because technically it is reflected light of that color’s wavelength. (or is it wrong to mix physics with 3D graphics, lol)
Any clarification would be great.

The “magic number” 0.92 should have been a dead-giveaway. This value just happens to be the standard gamma-correction factor. So, this strongly suggests that you are not working in a linear workspace … i.e. that washlg’s one-line comment about “are you using color correction” was straight on-the-mark.

For me it works with a factor of one. It could be that there are some problems when the scene alpha is set to “premulitpy”, but other than that, this is the correct formula:
Diffuse*(AOShadow))+Specular+Emit+((Ind.Light(Color*[Intensity color value])factor)+((Env.Light(Color*[Intensity color value])*factor)+Reflection+Refraction
And yes, I am working with color management enabled, so theoretically there shouldn’t be any gamma issues.

@FloridaJo:
I think you are confusing some things here:
EnvLight and IndLight are in fact being added (to the main compositing flow). But they need to be modified first. That modification happens with the color pass.
The color pass is not physical at all. You use the color pass to add the color information to indirect and Environment Light, and that happens by multiplication. If you want to think of it physically, you need to modify the wavelengths of Ind/EnvLight with the material color. But not only that, you first need to modifiy the color’s intensity with another multiplication. After all these modifications you add both to the main flow, like described in the formula above.
Sidenote: This is really only Blender. When you combine passes from e.g. Vray, things look a lot different and you have to use a different formula.

Cool. Thanks.

Okay, I’ll buy that.
Thanks for the clarification.

Sidenote: I’ve listened many hours to your tutorials so that when my wife asks me a question, I’m answering her in a German accent.
She: “How do you take the cap off this bottle?”
Me: (in German accent) "Well, first you must understand the bottle is glass and the lid is plastic, and the reason this was done was to prevent children from opening the bottle and removing the contents which would probably not be good for them if ingested in any quantities of more than a teaspoon or maybe a tablespoon, or even less if it is a pharmaceutical, so the thing to remember is what properties could best be connected between glass and plastic as it relates to friction…

I think she wants to hit me.

Uh oh, I guess in the next tutorials I can be a little bit more straightforward…
:smiley:

I haven’t really had a need to use transparency in composites. It’s funny how rarely we truly use glass. But now I need to composite some glass in a scene. Is there some trick to it? Maybe it’s talked about in your cmivfx video?

oops…sorry, quoted the wrong post!
Is it just me or is it weird that I cannot delete my edits?