diff options
| -rw-r--r-- | client/game.tscn | 1 | ||||
| -rw-r--r-- | client/map/map.gd | 52 | ||||
| -rw-r--r-- | client/map/map.tscn | 13 | 
3 files changed, 53 insertions, 13 deletions
| diff --git a/client/game.tscn b/client/game.tscn index b93f6b68..278f31d3 100644 --- a/client/game.tscn +++ b/client/game.tscn @@ -18,7 +18,6 @@ background_mode = 2  sky = SubResource("Sky_ultpf")  tonemap_mode = 2  ssao_enabled = true -sdfgi_enabled = true  sdfgi_use_occlusion = true  sdfgi_energy = 2.0 diff --git a/client/map/map.gd b/client/map/map.gd index 1cd0bd30..af80d9ac 100644 --- a/client/map/map.gd +++ b/client/map/map.gd @@ -2,22 +2,23 @@ class_name Map  extends Node3D  var tile_by_pos: Dictionary = {} +var baking = false - -func get_tile_name(position: Vector2i): -	var e = tile_by_pos[str(position)] -	if e != null: return e[0] -	else: return null -func get_tile_instance(position: Vector2i) -> Tile: -	var e = tile_by_pos[str(position)] +func get_tile_name(pos: Vector2i): +	var e = tile_by_pos[str(pos)]  	if e != null: return e[1]  	else: return null +func get_tile_instance(pos: Vector2i) -> Tile: +	var e = tile_by_pos[str(pos)] +	if e != null: return e[2] +	else: return null -func set_tile(position: Vector2i, name: String, neighbors: Array = [null,null,null,null]) -> Tile: -	var tile = TileFactory.produce(name, str(position), neighbors) +func set_tile(pos: Vector2i, name_: String, neighbors: Array = [null,null,null,null]) -> Tile: +	var tile = TileFactory.produce(name_, str(pos), neighbors)  	add_child(tile) -	tile.position = Vector3(position.x, 0, position.y) -	tile_by_pos[str(position)] = [name, tile] +	tile.position = Vector3(pos.x, 0, pos.y) +	tile_by_pos[str(pos)] = [pos, name_, tile, neighbors] +	if not baking: voxelgi_timer.start(1)  	return tile  func remove_tile_if_exists(pos: Vector2i): @@ -27,3 +28,32 @@ func remove_tile_if_exists(pos: Vector2i):  	tile_by_pos.erase(str(pos))  	tile.name += "_queued_free"  	tile.queue_free() + +@onready var voxelgi_timer: Timer = $Timer +@onready var voxelgi: VoxelGI = $VoxelGI + +func _ready(): +	if baking: return +	voxelgi_timer.connect("timeout", gi_bake) + +func gi_bake(): +	print("Map: Rebaking VoxelGI") +	gi_bake_blocking() + +func gi_bake_blocking(): +	var extent_min = Vector2(0,0) +	var extent_max = Vector2(0,0) +	for e in tile_by_pos.values(): +		extent_min.x = min(extent_min.x, e[0].x) +		extent_min.y = min(extent_min.y, e[0].y) +		extent_max.x = max(extent_max.x, e[0].x) +		extent_max.y = max(extent_max.y, e[0].y) + +	var center = (extent_max + extent_min) / 2 +	var size = extent_max - extent_min +	voxelgi.position = Vector3(center.x, 2, center.y) +	voxelgi.size = Vector3(size.x, 5., size.y) +	print("Baking now!") +	var start = Time.get_ticks_msec() +	voxelgi.bake() +	print("Bake done. elapsed=", Time.get_ticks_msec() - start) diff --git a/client/map/map.tscn b/client/map/map.tscn index df359214..cd08e416 100644 --- a/client/map/map.tscn +++ b/client/map/map.tscn @@ -1,6 +1,17 @@ -[gd_scene load_steps=2 format=3 uid="uid://b4gone8fu53r7"] +[gd_scene load_steps=4 format=3 uid="uid://b4gone8fu53r7"]  [ext_resource type="Script" path="res://map/map.gd" id="1_3en0a"] +[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_kwk4i"] + +[sub_resource type="VoxelGIData" id="VoxelGIData_m5j5n"] +  [node name="Map" type="Node3D"]  script = ExtResource("1_3en0a") + +[node name="Timer" type="Timer" parent="."] +one_shot = true + +[node name="VoxelGI" type="VoxelGI" parent="."] +camera_attributes = SubResource("CameraAttributesPractical_kwk4i") +data = SubResource("VoxelGIData_m5j5n") | 
