extends SceneTree
## What does the ocean actually cost, and which part?
##
## GPU-timed with viewport_get_measured_render_time_gpu, not wall time -- an
## earlier bench in this project timed _process and reported 6.900 ms for every
## configuration including a trivial shader, which was 144 Hz vsync.
##
## DISPLAY=:0 "$HYPER_TPS_GODOT" --path . --rendering-driver vulkan \
## --script res://scenes/test/ocean_bench.gd
var _vp: SubViewport
var _mat: ShaderMaterial
var _i := -1
var _frames := 0
var _acc := 0.0
var _res := []
const WARM := 30
const MEASURE := 90
# name, shore_refine_band, depth_query_footprint, resolution-of-sheet
var _cases := [
["as shipped ", 25.0, 0.5],
["no per-frag depth ", 0.0, 0.5],
["coarse depth (25 m) ", 25.0, 25.0],
["both ", 0.0, 25.0],
]
func _initialize() -> void:
_vp = SubViewport.new()
_vp.size = Vector2i(1920, 1080)
_vp.render_target_update_mode = SubViewport.UPDATE_ALWAYS
var ocean := Ocean.new()
ocean.water_y = 0.0
_vp.add_child(ocean)
var cam := Camera3D.new()
# Low and looking along the water: the worst case, water fills the frame.
cam.position = Vector3(640000.0, 12.0, 640000.0)
cam.rotation_degrees = Vector3(-3.0, 0, 0)
cam.far = 40000.0
cam.current = true
_vp.add_child(cam)
var sun := DirectionalLight3D.new()
sun.rotation_degrees = Vector3(-25, 140, 0)
_vp.add_child(sun)
var we := 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
we.environment = e
_vp.add_child(we)
root.add_child(_vp)
_mat = ocean.material_override as ShaderMaterial
RenderingServer.viewport_set_measure_render_time(_vp.get_viewport_rid(), true)
print("BENCH: ocean at 1920x1080, camera 12 m above water, 905 km from origin")
func _process(_d: float) -> bool:
if _mat == null:
return false
_frames += 1
if _frames > WARM:
_acc += RenderingServer.viewport_get_measured_render_time_gpu(_vp.get_viewport_rid())
if _frames < WARM + MEASURE:
return false
var ms := _acc / float(MEASURE)
if _i >= 0:
print(" %s : %6.3f ms GPU" % [_cases[_i][0], ms])
_res.append(ms)
_i += 1; _frames = 0; _acc = 0.0
if _i >= _cases.size():
if _res.size() >= 4:
print("BENCH: per-fragment depth costs %.3f ms; coarsening octaves saves %.3f ms"
% [_res[0] - _res[1], _res[0] - _res[2]])
quit(0); return true
_mat.set_shader_parameter(&'shore_refine_band', _cases[_i][1])
_mat.set_shader_parameter(&'depth_query_footprint', _cases[_i][2])
return false