diff options
author | Gone2Daly <71726742+Gone2Daly@users.noreply.github.com> | 2023-07-22 21:05:42 +0200 |
---|---|---|
committer | Gone2Daly <71726742+Gone2Daly@users.noreply.github.com> | 2023-07-22 21:05:42 +0200 |
commit | 71b3cd829f80de4c2cd3972d8bfd5ee470a5d180 (patch) | |
tree | b4280fde6eef2ae6987648bc7bf8e00e9011bb7f /game/addons/zylann.hterrain/tools/bump2normal_tex.gdshader | |
parent | ce9022d0df74d6c33db3686622be2050d873ab0b (diff) |
init_testtest3d
Diffstat (limited to 'game/addons/zylann.hterrain/tools/bump2normal_tex.gdshader')
-rw-r--r-- | game/addons/zylann.hterrain/tools/bump2normal_tex.gdshader | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/game/addons/zylann.hterrain/tools/bump2normal_tex.gdshader b/game/addons/zylann.hterrain/tools/bump2normal_tex.gdshader new file mode 100644 index 0000000..b0c97da --- /dev/null +++ b/game/addons/zylann.hterrain/tools/bump2normal_tex.gdshader @@ -0,0 +1,25 @@ +shader_type canvas_item; + +#include "res://addons/zylann.hterrain/shaders/include/heightmap.gdshaderinc" + +vec4 pack_normal(vec3 n) { + return vec4((0.5 * (n + 1.0)).xzy, 1.0); +} + +float get_height(sampler2D tex, vec2 uv) { + return sample_heightmap(tex, uv); +} + +void fragment() { + vec2 uv = UV; + vec2 ps = TEXTURE_PIXEL_SIZE; + float left = get_height(TEXTURE, uv + vec2(-ps.x, 0)); + float right = get_height(TEXTURE, uv + vec2(ps.x, 0)); + float back = get_height(TEXTURE, uv + vec2(0, -ps.y)); + float fore = get_height(TEXTURE, uv + vec2(0, ps.y)); + vec3 n = normalize(vec3(left - right, 2.0, fore - back)); + COLOR = pack_normal(n); + // DEBUG + //COLOR.r = fract(TIME * 100.0); +} + |