extends SceneTree
## Render the REAL map at a REAL shoreline, through the ocean debug channels.
##
## "The water looks wrong" has now survived several rounds of reading
## screenshots of a whole world, where white water, white snow, and water
## painted white by the atmosphere all look identical. This puts a camera on a
## known waterline -- coordinates from dc-terrain/tests/test_shore_profile.cpp
## -- and writes one PNG per debug channel, so the terms can be told apart.
##
## DISPLAY=:0 "$HYPER_TPS_GODOT" --path . --rendering-driver vulkan \
## --script res://scenes/test/map_water_preview.gd
const SHORE := Vector2(-455633.9, -451631.2) # seaward is -x
const WATER_Y := 700.0
var _map: Node = null
var _vp: SubViewport
var _cam: Camera3D
var _frames := 0
var _i := 0
# 0 shaded, 2 foam, 4 depth, 1 normal
var _channels := [0, 2, 4, 1]
func _initialize() -> void:
var packed := load("res://scenes/maps/map_dc_erosion.tscn") as PackedScene
# A SubViewport, not the root window: root.size never took effect and every
# saved PNG came out 2x2. This is the same pattern density_preview.gd uses
# and it works.
_vp = SubViewport.new()
_vp.size = Vector2i(1600, 900)
_vp.render_target_update_mode = SubViewport.UPDATE_ALWAYS
root.add_child(_vp)
_map = packed.instantiate()
_vp.add_child(_map)
_cam = Camera3D.new()
# 600 m out to sea, 40 m up, looking back at the beach.
_cam.position = Vector3(SHORE.x - 600.0, WATER_Y + 40.0, SHORE.y)
_cam.look_at(Vector3(SHORE.x + 400.0, WATER_Y - 10.0, SHORE.y))
_cam.far = 60000.0
_cam.current = true
_vp.add_child(_cam)
print("PREVIEW: map at a measured shoreline, camera 600 m offshore")
func _ocean():
for c in _map.get_children():
if c is Ocean: return c
return null
func _process(_d: float) -> bool:
_frames += 1
if _frames < 240: # terrain has to mesh before the shore exists
return false
var o = _ocean()
if o == null:
print("FAIL — no Ocean node in the map"); quit(1); return true
var mat := o.material_override as ShaderMaterial
mat.set_shader_parameter(&'ocean_debug', _channels[_i])
if _frames < 250:
return false
var img := _vp.get_texture().get_image()
var names := {0: "shaded", 1: "normal", 2: "foam", 4: "depth"}
var path := "/tmp/map_water_%s.png" % names[_channels[_i]]
img.save_png(path)
print(" wrote %s" % path)
_i += 1
_frames = 240
if _i >= _channels.size():
quit(0); return true
return false