Fix washed-out look (inverted terrain normals via winding), tune lighting/fog, add tree+rock collision
This commit is contained in:
@@ -36,6 +36,17 @@ func _make_tree(pos: Vector3, rng: RandomNumberGenerator) -> void:
|
||||
trunk.material_override = _mat(Color(0.33, 0.24, 0.16))
|
||||
root.add_child(trunk)
|
||||
|
||||
# Collision: a capsule around the trunk so you can't walk through the tree.
|
||||
var body := StaticBody3D.new()
|
||||
root.add_child(body)
|
||||
var col := CollisionShape3D.new()
|
||||
var cap := CapsuleShape3D.new()
|
||||
cap.radius = 0.35
|
||||
cap.height = 4.0
|
||||
col.shape = cap
|
||||
col.position = Vector3(0, 2.0, 0)
|
||||
body.add_child(col)
|
||||
|
||||
# Low-poly conifer canopy: stacked cones.
|
||||
var h := 3.0
|
||||
for j in range(3):
|
||||
@@ -57,13 +68,25 @@ func _make_tree(pos: Vector3, rng: RandomNumberGenerator) -> void:
|
||||
func _make_rock(pos: Vector3, rng: RandomNumberGenerator) -> void:
|
||||
var rock := MeshInstance3D.new()
|
||||
var bm := BoxMesh.new()
|
||||
bm.size = Vector3(rng.randf_range(0.8, 1.8), rng.randf_range(0.6, 1.2), rng.randf_range(0.8, 1.8))
|
||||
var box_size := Vector3(rng.randf_range(0.8, 1.8), rng.randf_range(0.6, 1.2), rng.randf_range(0.8, 1.8))
|
||||
bm.size = box_size
|
||||
rock.mesh = bm
|
||||
rock.position = pos + Vector3(0, 0.3, 0)
|
||||
rock.rotation = Vector3(rng.randf_range(-0.2, 0.2), rng.randf_range(0, TAU), rng.randf_range(-0.2, 0.2))
|
||||
rock.material_override = _mat(Color(0.42, 0.42, 0.45))
|
||||
add_child(rock)
|
||||
|
||||
# Collision: a box matching the rock mesh.
|
||||
var body := StaticBody3D.new()
|
||||
body.position = rock.position
|
||||
body.rotation = rock.rotation
|
||||
add_child(body)
|
||||
var col := CollisionShape3D.new()
|
||||
var box := BoxShape3D.new()
|
||||
box.size = box_size
|
||||
col.shape = box
|
||||
body.add_child(col)
|
||||
|
||||
func _mat(c: Color) -> StandardMaterial3D:
|
||||
var m := StandardMaterial3D.new()
|
||||
m.albedo_color = c
|
||||
|
||||
@@ -57,8 +57,12 @@ func _build() -> void:
|
||||
var p01 := Vector3(x0, sample_height(x0, z1), z1)
|
||||
var p11 := Vector3(x1, sample_height(x1, z1), z1)
|
||||
|
||||
_add_tri(st, p00, p01, p11, half, uv_scale)
|
||||
_add_tri(st, p00, p11, p10, half, uv_scale)
|
||||
# Winding order chosen so generate_normals() produces UPWARD normals.
|
||||
# (The reverse winding gave downward normals, so the sun lit the
|
||||
# underside and the top surface rendered black — confirmed by an
|
||||
# unshaded render showing the true bright-green albedo.)
|
||||
_add_tri(st, p00, p11, p01, half, uv_scale)
|
||||
_add_tri(st, p00, p10, p11, half, uv_scale)
|
||||
|
||||
st.generate_normals()
|
||||
|
||||
@@ -67,7 +71,7 @@ func _build() -> void:
|
||||
mi.name = "TerrainMesh"
|
||||
mi.mesh = mesh
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.albedo_color = Color(0.33, 0.45, 0.22) # mossy green
|
||||
mat.albedo_color = Color(0.36, 0.47, 0.26) # mossy green (lit, not fluorescent)
|
||||
mat.roughness = 0.95
|
||||
mi.material_override = mat
|
||||
add_child(mi)
|
||||
|
||||
Reference in New Issue
Block a user