Every time I try out a new version of HDRP, I try playing around with glass a bit, to see if I can achieve a convincing look for windows. Some of the techniques for glass look really cool in isolation, but they don’t seem practical for the kinds of conditions that exist in actual games. There always seem to be major drawbacks that keep me from making my windows more interesting.
For my glass/windows, I’m aiming for a highly transparent surface, but with a bit of distortion/refraction from them to make it more convincing that it’s glass. Unfortunately, neither distortion not refraction seem feasible for glass that a player will be looking through. I was wondering if anyone else uses these features for windows in their game, if they have workarounds for the issues below, or if there’s just a better way to do glass than I’ve tried.
My first attempt was to use Distortion. This seemed pretty good in terms of the blur it applied to objects behind it, but it had two bad drawbacks:
- The blur would also be applied to other transparent objects in front of it, including the UI
- The blue would also be applied to the surface of the glass itself, so any attempt to have some surface detail on the glass texture was wasted, as the surface of the glass would just get blurred.
Mainly I stopped using distortion for glass because it blurs UI in front of the glass. But I have other objects that are transparent that get blurred when they’re placed in front of a piece of glass.
So I tried refraction instead of distortion. The overall effect can be much better. But it doesn’t seem that any transparent objects will be rendered behind the window. So, if I look through a window at the scene, none of the other transparent objects in the scene will be rendered. You can set the other transparent objects to be rendered “Before Refraction”, but then any objects in front of the window will get refracted.
So, in short, I don’t know how to make a glass window look interesting in HDRP without either rendering the objects in front or behind the window badly. Has anyone successfully created distortion/refraction in windows in HDRP such that transparent objects rendering correctly in front of or behind it? Is there a different technique I don’t know about, or some other detail? So far, glass effects seem like they can only be used in extreme isolation.
Did you find any solution?
My original post is a bit out of date now, at least in more recent versions of HDRP, as various UI elements (such as TextMeshPro) can be configured to display properly in front of or behind refractive materials now. If you’re having an issue, I’d recommend posting a screenshot of what you’re seeing.
So various issues were described in the original post, in relation to the distortion and refraction approaches. So it depends what you mean by “did you find any solution”.
Coincidentally, I noticed a few days ago for the first time, that my glass windows surface details were lost due to distortion blurring - this was quite surprising as I thought that it would blur and distort the background, but draw the window surface over that - after all, this is happening during a forward pass. I probably misunderstand how it is implemented, maybe as some kind of post effect that applies over everything, who knows.
My solution was to make a custom Shader Graph, and to use the HD Scene Color node to sample the background, using a distorted lookup while also adding blur via the mip parameter. It works very well and preserves the glass surface detail such as the normal map for specular/reflections and the dirt detail.
I’m sorry I didn’t write it down in more detail
in my case,
I solved the problem using After PostProcess for UI.
However, I have yet to get a clear solution about Refraction(Distortion)
There are many information about distortion effects that using HD Scene Color node or sampling information from Screen.
But they are also affected by objects in front of windows
For example
There’s a window that’s very distorted because it’s wet.
window frame is red.
window frame is clearly located in front of the window
outside view of window should look distorted(Refraction)
The problem is that the red color of the window frame is distorted on the window.
There are also other problems that arise in the order of transparent objects and refraction objects
I think I’ve also seen that this is the limitation of HDRP
But most of the information was a little old,
and I was wondering if there was any new information or detours.
These issues are, of course, the same with VFX Graph’s Distortion.
So, in short,
Looking for information about
how to make Refraction Window drawn well,
when there is a object in front of (or behind) Refraction Window.
This is also a classic issue that you see in water in a lot of games, with objects above the water appearing in the distorted pixels that are meant to be under water (behind the surface).
I solved this by doing a depth comparison and only distorting pixels that are below the surface. For a given pixel:
- Calculate your distortion vector (typically based on surface normal or whatever)
- Fetch the scene depth at the distorted position.
- Compare that depth to depth of the surface pixel you are currently drawing.
- If the surface pixel is deeper than the distorted test depth, reset your distortion vector to zero.
- Use your distortion vector (now possibly zero) to read the HD scene color with an offset.