extends SceneTree
## Render the ocean to a PNG so its SHADING can be judged without a round trip.
##
## The waves displace correctly; what is wrong is how they are lit. Iterating on
## that through in-game screenshots costs a launch each time and I have already
## misread one. This puts the real Ocean node, a real sun and a real sky in a
## SubViewport and writes the frame to disk.
##
## DISPLAY=:0 "$HYPER_TPS_GODOT" --path . --rendering-driver vulkan \
## --script res://scenes/test/ocean_preview.gd
const N := Vector2i(1280, 720)
var _vp: SubViewport
var _frames := 0
var _shots := [[30.0, -6.0, "origin", 0.0], [30.0, -6.0, "far640km", 640000.0],
[300.0, -25.0, "far_high", 640000.0]]
var _i := 0
var _cam: Camera3D
func _initialize() -> void:
_vp = SubViewport.new()
_vp.size = N
_vp.render_target_update_mode = SubViewport.UPDATE_ALWAYS
var ocean := Ocean.new()
ocean.water_y = 0.0 # preview in open water, away from the shore
_vp.add_child(ocean)
_cam = Camera3D.new()
_cam.position = Vector3(_shots[0][3], _shots[0][0], _shots[0][3])
_cam.rotation_degrees = Vector3(_shots[0][1], 0, 0)
_cam.far = 40000.0
_cam.current = true
_vp.add_child(_cam)
var sun := DirectionalLight3D.new()
sun.rotation_degrees = Vector3(-25, 140, 0)
sun.light_energy = 1.2
_vp.add_child(sun)
var env := WorldEnvironment.new()
var e := Environment.new()
e.background_mode = Environment.BG_SKY
var sky := Sky.new()
sky.sky_material = ProceduralSkyMaterial.new()
e.sky = sky
e.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
e.reflected_light_source = Environment.REFLECTION_SOURCE_SKY
e.tonemap_mode = Environment.TONE_MAPPER_FILMIC
env.environment = e
_vp.add_child(env)
root.add_child(_vp)
print("PREVIEW: ocean, %dx%d, sky + sun, filmic" % [N.x, N.y])
func _process(_d: float) -> bool:
_frames += 1
# The FFT needs frames to populate; the node publishes on its first update.
if _frames < 90:
return false
var img := _vp.get_texture().get_image()
var path := "/tmp/ocean_preview_%s.png" % _shots[_i][2]
img.save_png(path)
print(" wrote %s (alt %.0f m, pitch %.0f deg, %.0f km from origin)"
% [path, _shots[_i][0], _shots[_i][1], _shots[_i][3] * 1.414 / 1000.0])
_i += 1
_frames = 60
if _i >= _shots.size():
quit(0); return true
_cam.position = Vector3(_shots[_i][3], _shots[_i][0], _shots[_i][3])
_cam.rotation_degrees = Vector3(_shots[_i][1], 0, 0)
return false