Skip to content

Commit

Permalink
Fix region edge normal on small regions and normalize tangent and bin…
Browse files Browse the repository at this point in the history
…ormal
  • Loading branch information
Xtarsia authored and TokisanGames committed Oct 2, 2024
1 parent 39d3664 commit ea6520e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/shaders/main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ vec3 get_normal(vec2 uv, out vec3 tangent, out vec3 binormal) {
float u, v, height;
vec3 normal;
// Use vertex normals within radius of vertex_normals_distance, and along region borders.
if (v_region_border_mask > 0.5 || v_vertex_xz_dist < vertex_normals_distance) {
if ((v_region_border_mask > 0.5 || v_vertex_xz_dist < vertex_normals_distance) && v_region.z >= 0) {
normal = normalize(v_normal);
} else {
height = get_height(uv);
u = height - get_height(uv + vec2(_region_texel_size, 0));
v = height - get_height(uv + vec2(0, _region_texel_size));
normal = normalize(vec3(u, _vertex_spacing, v));
}
tangent = cross(normal, vec3(0, 0, 1));
binormal = cross(normal, tangent);
tangent = normalize(cross(normal, vec3(0, 0, 1)));
binormal = normalize(cross(normal, tangent));
return normal;
}

Expand Down

0 comments on commit ea6520e

Please sign in to comment.