Created
February 1, 2025 06:27
-
-
Save belzecue/316e5b4174af7bd1bb85839843c7b4be to your computer and use it in GitHub Desktop.
Optimised Godot 3 version of this Godot 4 shader: https://github.com/Foyezes/Godot-HeightBlend-Node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type spatial; | |
// alpha for tex1 and tex2 is the heightmap | |
uniform sampler2D tex1 : hint_black_albedo; | |
uniform sampler2D tex2 : hint_black_albedo; | |
uniform vec2 tex1_scale = vec2(1.); | |
uniform vec2 tex2_scale = vec2(1.); | |
uniform float height_offset = 0.; | |
uniform float contrast = 1.; | |
varying vec2 uv1; | |
varying vec2 uv2; | |
float heightBlend(float height1, float height2, float contrast_in, float height_offset_in, float mask){ | |
float add1 = height1 + height_offset_in; | |
float subtract1 = height2 - height_offset_in; | |
float add2 = subtract1 + mask; | |
float max1 = max(add1, add2); | |
float subtract2 = max1 - add1; | |
float multiply1 = subtract2 * contrast_in; | |
float result = clamp(multiply1, 0.0, 1.0); | |
return result; | |
} | |
void vertex() { | |
uv1 = UV * tex1_scale; | |
uv2 = UV * tex2_scale; | |
} | |
void fragment() { | |
vec4 col1 = texture(tex1, uv1); | |
vec4 col2 = texture(tex2, uv2); | |
float _heightblend = heightBlend( | |
col1.a, | |
col2.a, | |
contrast, | |
height_offset, | |
col2.a // use second texture alpha as mask | |
); | |
vec4 blended = mix( | |
col1, | |
col2, | |
_heightblend | |
); | |
ALBEDO = blended.rgb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Gimp or Photoshop or similar to add the texture displacement/heightmap as the diffuse alpha channel for each of the textures to blend.
The shader will automatically use the second texture's alpha/heightmap as the mask.
Output example: https://i.imgur.com/bilWB2e.jpeg