Skip to content

Commit

Permalink
Fix detail layer chunks were not fully clamped to scaled terrain size
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Dec 10, 2023
1 parent d10555a commit 42b861e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For a more detailed list of past and incoming changes, see the commit history.
- Fixed shader parameters not displaying the right value in the inspector until they are set by the user at least once
- Fixed `lod_scale` property getter was always returning 2 instead of the last set value
- Fixed LOD chunks sometimes overlapping when the heightmap is modified (issue #411)
- Fixed detail layers were rendering repeating instances outside the terrain when `map_scale` is not 1.0


1.7.2
Expand Down
3 changes: 3 additions & 0 deletions addons/zylann.hterrain/hterrain_detail_layer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ func process(delta: float, viewer_pos: Vector3):
cmin_x = clampi(cmin_x, 0, terrain_chunks_x)
cmin_z = clampi(cmin_z, 0, terrain_chunks_z)

cmax_x = clampi(cmax_x, 0, terrain_chunks_x + 1)
cmax_z = clampi(cmax_z, 0, terrain_chunks_z + 1)

if DEBUG and visible:
_debug_cubes.clear()
for cz in range(cmin_z, cmax_z):
Expand Down
8 changes: 7 additions & 1 deletion addons/zylann.hterrain/shaders/detail.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ void vertex() {
v_map_uv = map_uv;

//float density = 0.5 + 0.5 * sin(4.0*TIME); // test
float density = texture(u_terrain_detailmap, map_uv).r;
float density = 0.0;
// Force density to be 0 outside of bounds. This can be necessary when terrain is scaled,
// as detail chunks will keep their size and may partially overlap outside bounds at the edges
// of the terrain.
if (map_uv.x >= 0.0 && map_uv.y >= 0.0 && map_uv.x < 1.0 && map_uv.y < 1.0) {
density = texture(u_terrain_detailmap, map_uv).r;
}
float hash = get_hash(obj_pos.xz);

if (density > hash) {
Expand Down

0 comments on commit 42b861e

Please sign in to comment.