Skip to content

Commit

Permalink
Fix height_blend ignoring alpha values
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Nov 15, 2023
1 parent 6edf50c commit 07b187a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/shaders/main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ vec2 rotate(vec2 v, float cosa, float sina) {
return vec2(cosa * v.x - sina * v.y, sina * v.x + cosa * v.y);
}

vec3 height_blend(vec4 a_value, float a_height, vec4 b_value, float b_height, float t) {
vec4 height_blend(vec4 a_value, float a_height, vec4 b_value, float b_height, float t) {
float ma = max(a_height + (1.0 - t), b_height + t) - height_blend_sharpness;
float b1 = max(a_height + (1.0 - t) - ma, 0.0);
float b2 = max(b_height + t - ma, 0.0);
return (a_value.rgb * b1 + b_value.rgb * b2) / (b1 + b2);
return (a_value * b1 + b_value * b2) / (b1 + b2);
}

// 2-4 lookups
Expand Down Expand Up @@ -186,8 +186,8 @@ void get_material(vec2 uv, uint control, ivec2 iuv_center, out Material out_mat)
n = unpack_normal(normal_rg2);
normal_rg2.xz = rotate(n.xz, rot2.x, -rot2.y);

albedo_ht.rgb = height_blend(albedo_ht, albedo_ht.a, albedo_ht2, albedo_ht2.a, blend);
normal_rg.rgb = height_blend(normal_rg, albedo_ht.a, normal_rg2, albedo_ht2.a, blend);
albedo_ht = height_blend(albedo_ht, albedo_ht.a, albedo_ht2, albedo_ht2.a, blend);
normal_rg = height_blend(normal_rg, albedo_ht.a, normal_rg2, albedo_ht2.a, blend);
}

normal_rg = pack_normal(normal_rg.xyz, normal_rg.a);
Expand Down

0 comments on commit 07b187a

Please sign in to comment.