Material refraction in XR

Godot Version

4.2

Question

I’ve noticed refraction on standard PBR materials in godot 4.2 don’t work well in XR. The docs mention that some post processing effects don’t work yet in stereoscopic rendering so that is probably why, but does anyone have some resources on how to implement refraction as a custom shader for XR? Or just general tips for writing shaders for XR vs flatscreen?

That does sound like a bug.

Golden tip: if you want to know how something works in the StandardMaterial, configure your material and then right click → convert to shader material.

Now you have the shader code that Godot generates.

My guess here is that the refraction code is not taking EYE_OFFSET into account when determining the refraction vector.

Just to add some more feedback here, I did investigate this a bit further and the standard refraction logic is somewhat simplified (for performance reasons) and indeed does not produce an accurate result for stereo rendering.

It should be relatively easy to adjust for stereo in a custom shader. Making the standard material work correctly in stereo without sacrificing the performance gains for non-stereo, I’m not sure about yet.

I need to find some time to do some experimenting. to be continued :slight_smile:

Thanks, don’t sweat it too much as there are other things in the godot xr space which I’d put higher on the priority list than this!