Trying to create a fake glass material in Cycles using transparent+glossy...

I’m trying to create a fake glass material for a more complex scene I’m working on. My scene has large glass windows and a sun lamp, with the sun pointed towards the windows, so lots of sunlight should be entering the room. When I use a pure transparent material, it looks great. Here’s from an earlier render (many materials still unfinished)


there you can see the sunlight hitting the floor and even reflecting off the floor and hitting the ceiling. Still a bit grainy even with the maximum number of samples, but it looks okay.

After some more work on the scene I decided to try using real glass for the windows, with the same number of samples, and I got this:


The caustics from the chandelier didn’t pose too much of a problem, probably because of their relative size and distance to the rest of the scene, but the caustics from the sun looked terrible. While reflections can’t be seen from this angle, reflective glass does affect the way light bounces around the room, and I may want to produce HDR tonemapped images of the room later, which will make reflections show up a lot better.

So I decided to make a fake glass material, which would produce the same transparent shadows as the transparent material, but also produce the reflections of the glass. I did it by using a mix shader to combine a transparent shader with a glossy shader, using a fresnel node set to the same IOR as glass as the mix factor. This produced a weird artifact. Adjusting the roughness of the glass doesn’t appear to change the dark artifact. Changing the IOR does, and applying the same mix with a diffuse instead of transparent also looks fine, so it must be the transparent shader that’s mesing things up here. Here’s a look at my render + nodes


Anybody have a clue what’s going wrong here and some way to fix it? I also tried a glass material with light paths shadow mixing factor for transparent shadows, which gave me the shadows I wanted but refractive caustics were still shining through. This would be okay if I disabled refractive caustics, but I want to keep the real glass material and caustics from the chandelier in my scene, so it’s not ideal.

Fresnel does not work correctly with the Transparent shader. And I’m still wondering if that is a bug or rather the expected behaviour: From my understanding the Fresnel equations describe the behaviour of light when moving between media of differing refractive indices (thanks, Wikipedia…). Since a transparent medium has no refractive (or reflective, for that matter) index at all, any Fresnel calculation must end in a wrong result - I guess.

Use Layer Weight > Facing instead.



Glass is just a flat plane, no thickness.

1 Like

Generally, a modified glass setup that allows sunlight through would mix the two based on a simple lightpath equation rather than a simple mix (it would appear as glass to camera rays, but as a simple transparent material for indirect rays).

Can you explain what the add node was for? Also, how do I modify the “facing” value so that it approximates the IOR of the glass better?

I tried using the “is shadow ray” to mix glass and transparent but it still let the refractive caustics through. I just tried using “is camera ray” and it fixes the caustic problem, but both light path solutions result in this strange refraction: (fake glass on the right)


My guess is when light paths are used, it treats the glass like it’s a flat plane, rather than a solid object with light coming in and out both sides. When you do that with real glass, the space between the plane and the camera gets treated like it’s all solid glass and the light is refracting the entire way.

I also like the way IkariShinji’s shader works if you remove the “is shadow ray” part, as it seems to create a shadow that looks a lot like what the caustics would probably result in if they were higher quality. A more “glass” like shadow, without the caustics. I just need a better approximation of the IOR.

I thought we were talking window glass? If we’re talking about plain, regular window panes, the refractive effect will be negligible anyway - that’s why I used no refractive shader at all. And if the refraction is irrelevant, so is the IOR (and also the caustics, btw). I would not use this shader on any “non-architectural” glass.

The Add node ensures that the window glass always stays a little bit reflective (glossy), even when viewed straight on. Without the Add node you would get the plain Transparent node on straight on views.

I just figured out that this solved the light path refraction issue.


Actually, this is even better. The other one was still having weird issues around the edges.


IOR also affects the reflectivity of the glass depending on what angle the camera is viewing it from, does it not?

On a flat, mostly transparent window pane - who is ever going to be able to spot the difference between an IOR-based solution and the approximation you get from the Layer Weight > Facing node? That node has a very similar approach, as it blends according to the angle a face is viewed at.

So, in my setup: If the window is looked at perpendicularly, the transparency will dominate. At glancing angles the gloss will become more and more important.

True it would be hard to notice the difference, but surely there would be a way to modify the number output by the facing node to better approximate the amount of reflectivity you get from different angles. Better approximation of that would also result in more accurate reflection of light around the room as well, even if just slightly. I found that setting the “blend” option to 0.2, it came pretty close, but I’m guessing more complicated math might be necessary to get a near perfect representation of that IOR. Either way, the node setup I’m using with camera and glossy ray light paths right now seems to be doing what I set out to do, so I think I’ll stick with that.

Well, perhaps it wasn’t a great idea anyway. Here is my render from last night with 65535 samples:


The glass reflection certainly added more light to the scene, but even with that many samples, it’s still incredibly noisy. Compare this to a render I just did with transparent windows, with only 23699 samples:


Looks a lot better imo. The extra caustics from the glass reflection don’t even seem to have made much of a difference at all in the room’s overall lighting, so it might be best to just use transparent windows for now.

I may try playing around with the branched path tracer later though to see if I can improve things with that.

EDIT: Apparently Branched Path Tracing with glossy samples at 2 crashes my GPU, lol

By the way, I want to mention that I’m not too worried about noise at the moment, because I’m going to be baking the lighting, and then using that baked lighting (with HDR) as a mesh light to replace the diffuse portion, which should make much less noise on each subsequently baked surface, while retaining pretty much the same lighting. Then I can simply rebake any surface that’s still too noisy. Rinse, and repeat until I get satisfactory results. I plan on using the final results of my baked lighting in the game engine when I’m done, which is why you may have noticed that my objects are fairly low poly.

but I won’t be baking anything until my entire project is complete, as I want any light leaking between rooms to be represented properly.

Has someone ever reported a bug report with this issue? Should I report it? I find it a bit annoying…

Is it a bug? Or something immanent to the Fresnel equations themselves?
And what’s wrong with using Layer Weight > Facing instead?

I do not know if it is a bug but IMHO it should be reported (unless you know for certain that this is expected behaviour). The thing is that fresnel gives different results that facing. I don’t know the math behind it but if you input it into emission shader it is clear that it is not exactly the same.

Edit: I played with that a bit and found out that you can easily edit the facing input with curves and that way you get almost the same result as with fresnel. Using fresnel directly would be still much easier…

Well, facing and fresnel should be different values, as they represent different things. And the fresnel node allows you to choose an IOR, making the results even more physically accurate as well.