From 71b3cd829f80de4c2cd3972d8bfd5ee470a5d180 Mon Sep 17 00:00:00 2001 From: Gone2Daly <71726742+Gone2Daly@users.noreply.github.com> Date: Sat, 22 Jul 2023 21:05:42 +0200 Subject: init_test --- .../tools/texture_editor/display_normal.gdshader | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 game/addons/zylann.hterrain/tools/texture_editor/display_normal.gdshader (limited to 'game/addons/zylann.hterrain/tools/texture_editor/display_normal.gdshader') diff --git a/game/addons/zylann.hterrain/tools/texture_editor/display_normal.gdshader b/game/addons/zylann.hterrain/tools/texture_editor/display_normal.gdshader new file mode 100644 index 0000000..665af53 --- /dev/null +++ b/game/addons/zylann.hterrain/tools/texture_editor/display_normal.gdshader @@ -0,0 +1,28 @@ +shader_type canvas_item; + +uniform float u_strength = 1.0; +uniform bool u_flip_y = false; + +vec3 unpack_normal(vec4 rgba) { + vec3 n = rgba.xzy * 2.0 - vec3(1.0); + // Had to negate Z because it comes from Y in the normal map, + // and OpenGL-style normal maps are Y-up. + n.z *= -1.0; + return n; +} + +vec3 pack_normal(vec3 n) { + n.z *= -1.0; + return 0.5 * (n.xzy + vec3(1.0)); +} + +void fragment() { + vec4 col = texture(TEXTURE, UV); + vec3 n = unpack_normal(col); + n = normalize(mix(n, vec3(-n.x, n.y, -n.z), 0.5 - 0.5 * u_strength)); + if (u_flip_y) { + n.z = -n.z; + } + col.rgb = pack_normal(n); + COLOR = vec4(col.rgb, 1.0); +} -- cgit v1.2.3-56-ga3b1