diff options
author | CaptainProton42 <john.wigg@gmx.net> | 2020-11-21 12:14:36 +0100 |
---|---|---|
committer | CaptainProton42 <john.wigg@gmx.net> | 2021-03-19 20:35:20 +0100 |
commit | 856312ca6da3dd624ef69a0a5bca77fe507e4715 (patch) | |
tree | 33408ab9f8498091f2c9ab8df408b72345dbb645 | |
parent | ec3f220098f4bf5a10809e6682a9a24ff93d85cb (diff) |
Implement FLAG_UV*_USE_WORLD_TRIPLANAR
Implements triplanar mapping in world space for UV1 and UV2
when the respective flags are enabled.
-rw-r--r-- | scene/resources/material.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 0d02bde90d..5647856736 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -829,16 +829,26 @@ void BaseMaterial3D::_update_shader() { } if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n"; + if (flags[FLAG_UV1_USE_WORLD_TRIPLANAR]) { + code += "\tuv1_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL),vec3(uv1_blend_sharpness));\n"; + code += "\tuv1_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv1_scale + uv1_offset;\n"; + } else { + code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n"; + code += "\tuv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n"; + } code += "\tuv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n"; - code += "\tuv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n"; code += "\tuv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n"; } if (flags[FLAG_UV2_USE_TRIPLANAR]) { - code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n"; + if (flags[FLAG_UV2_USE_WORLD_TRIPLANAR]) { + code += "\tuv2_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL), vec3(uv2_blend_sharpness));\n"; + code += "\tuv2_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv2_scale + uv2_offset;\n"; + } else { + code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n"; + code += "\tuv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n"; + } code += "\tuv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n"; - code += "\tuv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n"; code += "\tuv2_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n"; } |