I’m having a problem figuring out how to combine a glass shader that lets light pass through it, with dirt shader that adds some edges and scratches. Separately they both both work, but I can’t figure out how to combine them.
The glass node setup is the one recommended here on several occasions and it lets the light pass through it.
and it gives me this kind of effect with dirt on the edges. As you can see the green wall behind is visible, but this glass material doesn’t let the light pass through it. As you can see it casts a shadow on the grey box below.
I’m a bit at a loss and not sure how I would combine glass dirt with glass that lets the light pass through. Now I’m not even sure if that is possible, so any help is greatly appreciated.
That setup does not let much light through, if you get rid of the “minimum node” (use just the shadow output) and get rid of the layer weight and invert colour (use just the transparent node) the glass will not cast shadows at all and let all the light through.
If you want the dirt to cast shadows you can use the dirt mask and subtract it (or add it depending on the mask) from the shadow rays.
Edit should have said shadow rays, have corrected.
Wow, thank yout. This is too much for me atm, so I’ll just copy this to try to finish what I started. Hopefully I’ll figure things out on my own, but If I don’t and have more stupid questions, please bare with me
I use a slightly different set-up that can be duplicated in the Nodes to add as many layers of grunge as you want for dirt-scratches-fingerprints, etc.
Just switch out the Noise texture withj any image texture Grunge or prints…works real well as paint layers on glass…
@RSEhlers Thanks, but this doesn’t let the light pass through it. @DNorman
Generally I’m having a problem understanding why you have to have a glass shader, transparent shader and light path? What is the difference between them so you have to use them all together?
That’s a trick to bypass a limitation of Cycles. By default, Cycles struggles to pass light through glass, because of the way refractions distort light.
Usually, Cycles would calculate shadows by tracing rays between objects and light sources. If the ray manages to connect without any obstacle in the way, the surface is considered to be lit. However, if there is glass in the way, the path the light ray would have to take is distorted, so Cycles cannot simply trace it and you get a scene that’s too dark and noisy, because the only light that will cross that glass is the rays that happen to randomly bounce in the correct direction.
The light path trick makes it so this shadow ray will perceive the glass shader as being a transparent shader instead. The transparent shader doesn’t have refraction, so Cycles can trace the ray easily in a straight line and light the scene as if the glass wasn’t there. This is much faster and cleaner to render and will save you from some problems (especially if a lot of the scene’s lighting passes through the glass).
I have to note that this trick does reduce realism: you are removing the glass’ shadow instead of calculating it accurately with all its complicated caustics and variance.
There are 2 more realistic (but heavier) alternatives to this trick:
Make the glass a caustics caster. This allows the distorted path to actually be calculated. This is better used for simpler refractive object (like a water surface), as it stops working after a few layers of refraction. https://www.youtube.com/watch?v=GHv2U9AXbNA
Use path guiding. This is only available for the CPU for now and is very slow, but it will help pass light through glass with full realism. It can even somewhat do intricate caustics if you lower “filter glossy”, though it’s not built for it and isn’t guaranteed to catch them all.
As etn249 says it is a “trick” to let light through glass. Not physically correct.
The light path node’s “is shadow ray” output, outputs a value of 1 if where the material is casting a shadow and 0 for all the other rays (glossy, diffuse etc)
The glass shader is what makes the glass look like glass (with its transparency, refraction and reflections etc).
The principled shader is the dirt’s material.
The transparent shader is needed for the “trick” so that light goes straight through the glass without calculating any shadows.
I used a mask (a procedural grayscale pattern) to mix the glass shader with the dirt (the first mix shader node on the left), that is what puts the dirt on the sides of the glass pane.
As etn249 says, Cycles takes a long time (many samples) to calculate the light refracting through the glass, a way around this is to use the light path node’s Shadow ray output to tell the material that if it casts a shadow cycles will consider it transparent. This is done with the second mix shader node.
The second mix shader node makes the material totally transparent only for shadow rays.
The output of the lightpath node is giving a value of 1 where the material casts a shadow so by subtracting the “dirt mask” values from it I am saying that the glass should be transparent for shadow rays unless there is dirt on it.
This is a trick and is useful especially when you want a lot of light to come in from a window, but it will not be realistic in all situations as glass does cast shadows and more importantly refract (change the angle) of light rays.
So the alternative methods that etn249 mentions would be much better for things like a bottle of perfume (that has rounded glass), a diamond, a prism etc or any other situation when you do want refracted light rays or shadow caustics.
I wouldn’t recommend doing it that way, because the bottle itself will have a mix of refractive and non-refractive transparency, which is going to double the image you see through it.
If you want to keep some shadow, you can still use the light path trick and instead make the transparent color darker. If you want the shdaow to look like in your image, you could even plug a fresnel node in the transparent color to keep the edges of the shadow.
Just not trying to confuse the OP…
The shader I showed doesn’t have a Glass Node in it But just the principled and it is for Grunge Layers…with the correct settings ( which changed in 4.2, you can still get Light Through Glass with Grunge with just the Principled Shade …
You or the OP might want a fake shader to get more Light passing through the Glass and Grunge but it would be a hack or I would use a different Fresnel that was provided with Blender…
A custom fake fresnel for glass would be something like Layer Weight/Facing → Power 5 → +0.05. Works well to produce “fresnel shadows” on thin geometry, but its a less solid replacement to real fresnel with thickness that handles backfacing faces correctly (snells window). I don’t think a perfect solution/hack exist, so best to check each use case.
Hello good people. Just wanted to say thank you for helping me figuring out how to do the glass. It’s not really seen here that much, but I played with it a lot and had some less subtle results I abandoned.