• Godot HelpShaders
  • Questions regarding refraction, transparency, and the usage of light.

I need some help, please. I'm trying to pull off the following thing seen in this photo: https://ae01.alicdn.com/kf/UTB8im5_s8ahduJk43Jaq6zM8FXaf/Nanguang-NG-10X-Studio-Light-Focus-Lens-Bowen-Mount-For-Flash-Led-Light-With-4-Color.jpg with a spotlight and a colored translucent mesh. But apparently meshes do not work this way with lights in Godot. Also, meshes lose their shadows the moment transparency is activated. Is there some way to activate both shadows and refraction or transparency?

Then there's the problem of refractive objects being unable to "see" each other or transparent models. This is the situation: https://imgur.com/mzdVD11.jpg I've read this tutorial https://docs.godotengine.org/en/stable/tutorials/shading/screen-reading_shaders.html but ended up confused regarding what I'm missing aside from the code at the bottom regarding DEPTH_TEXTURE. Writing shader_type spatial; in the code causes errors instantly (Unexpected token: Identifier shader_type). How am I supposed to tackle this situation? Which type of coding (GDScript or Visual Script) can be easier for allowing full visibility of transparent/refractive objects? Is there a video tutorial covering this somewhere?

Light is really tricky. I'd be surprised if this sort of thing were running out of the box by default, the newest graphics cards on the market are starting to support raytracing which would do what you want. There are even dedicated raytracing cards coming out because of the intense amount of processing power they use. From my understanding even the upcoming ps5 doesn't support it.

You can colour your lights, if you did this a bit differently. You can "apply" the lens to the light and then change the actual colour of the light. Would that do what you needed? You're still not going to see advanced lighting effects, like mirrors perfectly reflecting light for example.

Materials with transparency are rendered last, which would be a reason why you're not seeing a lot of the effects like shadows you are looking for. You may have to simulate some of these types of effects, how best to do that I have no idea.

Exactly! Unfortunately for you, Godot and most other real time rasterizing engines don't support recursive refractions/reflections, or coloured shadows (that last one actually can be done, but I don't see many engines doing it out of the box). Like the comment above said, that sort of graphical fidelity is best left for ray tracers. Realtime or not. The thing with rasterizers is that it cheats a lot to get good real time graphics. Shadows are just depth maps projected from light sources, reflections are either just the scene rendered as second or pseudo-raytraced in screen space, and global illumination is usually baked!

@Kequc said: Light is really tricky. I'd be surprised if this sort of thing were running out of the box by default, the newest graphics cards on the market are starting to support raytracing which would do what you want. There are even dedicated raytracing cards coming out because of the intense amount of processing power they use. From my understanding even the upcoming ps5 doesn't support it.

You can colour your lights, if you did this a bit differently. You can "apply" the lens to the light and then change the actual colour of the light. Would that do what you needed?

I don't have a recent GPU, so was wondering if there are some tricks that could be pulled off. I did consider having the drone (player character) rotate the colored lens in a rapid movement and instantly switch the light color, but I don't know if it would look weird that the light changes abruptly (in 3rd person at least). This is a rough sketch of what the drone would be like https://imgur.com/ZB4x7X3.jpg

Weren't there old games that used stained glass and sunlight shining through them? How did they pull that off? Baked lighting? There may be some situations in my game where I'd like to give the illusion that a white light shining through a crystal can change color. I'm considering adding a 2nd light to do that trick for that situation, but not sure if it would look acceptable.

@SIsilicon28 said: Exactly! Unfortunately for you, Godot and most other real time rasterizing engines don't support recursive refractions/reflections, or coloured shadows (that last one actually can be done, but I don't see many engines doing it out of the box). Like the comment above said, that sort of graphical fidelity is best left for ray tracers. Realtime or not. The thing with rasterizers is that it cheats a lot to get good real time graphics. Shadows are just depth maps projected from light sources, reflections are either just the scene rendered as second or pseudo-raytraced in screen space, and global illumination is usually baked!

But the tutorial itself says it does support multiple refractions through the use of DEPTH_TEXTURE , I just have no idea how to apply the code (and am probably applying it in the wrong area too, of the shader's GDScript). https://docs.godotengine.org/en/stable/tutorials/shading/screen-reading_shaders.html it even shows an example for 2D.

And let's suppose the shadows cannot be colored unless I add a 2nd light source or something, is there a way to at least apply shadows to transparent/refractive models? (other than duplicating the model, setting it to Shadow Only, and parenting it to the refractive or transparent original model).

@Detonatress said: https://docs.godotengine.org/en/stable/tutorials/shading/screen-reading_shaders.html it even shows an example for 2D. That's the problem. The multiple refractions thing can only work in 2D! In 3D, you are limited to only refracting solid objects. Transparent objects, including other refractive surfaces, don't get rendered into the SCREEN_TEXTURE and they won't show up in other refractions.

Infact, that very same tutorial says that this is unavoidable in 3D. To quote this part of the tutorial,

In 3D, this is unavoidable because copying happens when opaque rendering completes. So you can have refractions, but no recursive refractions.

@SIsilicon28 said:

@Detonatress said: https://docs.godotengine.org/en/stable/tutorials/shading/screen-reading_shaders.html it even shows an example for 2D. That's the problem. The multiple refractions thing can only work in 2D! In 3D, you are limited to only refracting solid objects. Transparent objects, including other refractive surfaces, don't get rendered into the SCREEN_TEXTURE and they won't show up in other refractions.

So the last part of that page says that it's no use to try this method for 3D refractive objects? That's going to be quite a challenge to have a bunch of crystal rocks form a room. Maybe with a mix of transparent colored objects and some bumpmaps an illusion could be created. Now if only transparent objects could be seen through refractive ones ...

EDIT: actually, transparent object within refractive object can be done. No Depth Test + Inserting colored object inside refractive object. https://imgur.com/chC13K8.jpg Forgot to mention though, the sphere within that sphere uses a texture with alpha < 1, which might be why it can be seen by the refracting sphere.

Things get a bit trippy when it has to deal with this transparent cube though: https://imgur.com/vfHskRq.jpg

I'm sorry. What can be done? The multiple refractions thing? I don't see how that's being demonstrated in the screenshot. :/

@SIsilicon28 said: I'm sorry. What can be done? The multiple refractions thing? I don't see how that's being demonstrated in the screenshot. :/

Not refraction, the transparent object within refractive one. https://imgur.com/0aFqSIT.jpg

I'm glad that at least this can be done, as it can give the illusion of a crystal if I'd fill it with transparent blue objects. And the weirdness that happens when a transparent object is on the outside can also be used for some strange mechanics, due to how weird it acts (one cube remains unaffected while the other is affected by refraction in a screenshot).

3 years later