Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

.cosmoloop presented a beautiful real-time water shader made in Blender, which delivers refraction, underside refraction, lights, and shadow interaction. Enjoy:

18,121 Aufrufe • vor 6 Monaten •via X (Twitter)

0 Kommentare

Keine Kommentare verfügbar

Kommentare vom Original-Post werden hier angezeigt

Ähnliche Videos

🧑‍🏫 How to make a glass/refraction shader: 🍷 Refraction will ultimately have the effect that whatever is behind your mesh should appear distorted by the surface of the mesh itself. We're not going for external caustics projection, just modelling glass-like, distorting "transparency". 🌆 In Unity, you can sample the *global* _CameraOpaqueTexture (make sure it's enabled in your URP asset settings), which is what your scene looks like rendered without any transparent objects. In Shader Graph, you can simply use the Scene Colour node. 🔢 The UVs required for this texture are the normalized screen coordinates, so if we offset/warp/distort these coordinates and sample the texture, we ultimately produce a distorted image. We can offset the UVs by some normal map, as well as a refraction vector based on the direction from the camera -> the vertex/fragment (flip viewDir, which is otherwise vertex/fragment -> camera) and normals of the object. 📸 Input the (reversed) world space view direction and normal into HLSL refract. **Convert the refraction direction vector to tangent space before adding it to the screen UV.** Use the result to sample _CameraOpaqueTexture. refract(-worldViewDirection, worldNormal, eta); eta -> refraction ratio (from_IOR / to_IOR), > for air, 1.0 / indexOfRefraction (IOR). IOR of water = 1.33, glass = 1.54... 💡 You can also do naive "looks about right" hacks: fresnel -> normal from grayscale, which can be used for distortion. Or distort it any other way (without even specifically using refract at all), really... 🧠 Thus, even if your object is rendered as a transparent type (and vanilla Unity URP will require that it is), it is fully 'opaque' (max alpha), but it renders on its surface what is behind it, using the screen UV. If you distort those UVs by the camera view and normals of the surface it will be rendered on, it then appears like refractive glass on that surface. > Transparent render queue, but alpha = 1.0.

Mirza Beig

125,253 Aufrufe • vor 1 Jahr

Great question! 🤔 How do you simulate *multiple* layers of glass/refraction in video games? In the last breakdown, I discussed how to create a glass shader in Unity URP. In essence, we were taking the render of the scene from the camera without any transparent objects. This is available in URP as the global _CameraOpaqueTexture. This is good enough for most use-cases, and more or less the classic way of doing it. 🔍 What is _CameraOpaqueTexture? As the name implies, there are no transparent objects rendered into this texture, so it's not possible by default to have something like a transparent-type ocean material/shader rendered through a refractive glass shader (which samples and distorts this texture to render on its surface, as if it's transparent). ⚠️ Why it’s tricky: It's much easier to sort without much further setup if you don't have refraction, and only a transparent material, because in that case you're not simulating the transparency yourself via sampling the rendered scene texture. But for refraction, it's required-- unless you want to go down the ray/path tracing route. You could simulate accurate, real dispersion... and that's about as expensive as it sounds, and it requires a rework of your entire rendering. --> 🚫 It's not a viable suggestion to offer. 📚 There are well-known terms regarding transparency sorting you can search up, but as you've specifically asked for refractive boxes, I'll discuss briefly about that. 🧱 Simulating layers of refraction: For this kind of rendering, you need some way to render the backfaces before rendering the front. And the backfaces that are rendered may contain whatever data you'd like for additional processing in the layer front-facing mesh render. 🧪 Examples: You could render the back face as a glass shader of its own, as an intermediate step after _CameraOpaqueTexture. Then you sample this texture instead and you end up with multi-layered refraction, "just like that". You can also render the back normals only, via a fully opaque shader, and use that to manually account for that during the front render. You could even bake in data needed for thickness in realtime. 🛠️ Without making it complicated for yourself, the most straightforward method is via render textures, and you can easily set some fractional resolution. Cameras in Unity have an open slot for target textures to render to. You can use custom render textures to process _SelfTexture2D. ⏱️ It's great to do low-resolution processing for more complex tasks, like blurring and caustics. You can get massive performance boosts, considering the square law and number of pixels/fragments that need calculations (quadratic scaling). 🚧 I've not fully exploited the possibilities myself, but research/development with PRISM is ongoing!

Mirza Beig

51,429 Aufrufe • vor 1 Jahr