From cc2b6acbd2f7d11e24c08672b2136168c57304c0 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Mon, 9 Aug 2021 15:11:36 +0200 Subject: [PATCH] Improve the appearance of simple parallax in SpatialMaterial This uses offset limiting to avoid distortion in the distance, and makes simple (non-deep) parallax more usable overall. --- scene/resources/material.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 15f5e9635e7..58c5e886cdf 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -776,7 +776,9 @@ void SpatialMaterial::_update_shader() { } else { code += "\t\tfloat depth = texture(texture_depth, base_uv).r;\n"; - code += "\t\tvec2 ofs = base_uv - view_dir.xy / view_dir.z * (depth * depth_scale);\n"; + // Use offset limiting to improve the appearance of non-deep parallax. + // This reduces the impression of depth, but avoids visible warping in the distance. + code += "\t\tvec2 ofs = base_uv - view_dir.xy * depth * depth_scale;\n"; } code += "\t\tbase_uv=ofs;\n";