The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hi all--

I need help with the Refract node in visual shader. Does anyone have any examples of how to use the damn thing? There don't seem to be any tutorials. I'm building a visual shader for water and I need refraction in it. Any tips appreciated.

Godot version 4.0
in Engine by (513 points)

1 Answer

0 votes

Refraction is usually achieved by using a distorted screen texture. It's quite simple actually, you just add a texture node and set the texture to screen in its drop down menu, then add a noise texture to the screen uv and subtract 0.5 from both the x and y component of the resulting vector to recenter the resulting uvs. Then multiply the results with a float that controls how much 'refraction' you want and finally hook that to the uv input of the screen texture node. Plug the screen texture to the base color and you have refraction.

You may want to blend the screen texture with another image or tint it with a color to look more like water.

by (2,018 points)

I'm trying to do something along those lines but there must be a missing element - I can't get the refracted parts of the immersed object to align with the parts that are sticking out above the surface - clearly the uv offset is off. Could you provide an example of what the shader graph should look like?

Mine looks like this. There are several problems with it, eg, the surface is semi transparent and I can see the undistorted parts of the immersed cylinder which I want clipped just like when using the Refraction property on a standard material.

image url:

The result so far is (image url: You can see the problems. the bottom of the cube, which is under water, is still seen unrefracted from under the refracted projection. The other problem is the refracted projection extends beyond the cube into the distance - it basically stretches along the y coordinate of the screen uv... How do I fix these?

I will as soon as I get back to my computer.

Here is a google drive link to the screenshots and a sample visual shader.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.