diff --git a/NoclipCamera.gd b/NoclipCamera.gd index 3ccab4f..030e472 100644 --- a/NoclipCamera.gd +++ b/NoclipCamera.gd @@ -2,8 +2,6 @@ extends RigidBody3D var rot_x = 0 var rot_y = 0 -@onready var world = preload("res://world.tscn") - @export var PLAYER_SPEED = 1.0 @export var PLAYER_REACH = 1000 @export var NOCLIP = false @@ -20,7 +18,7 @@ var delta_speed = 0 # Called when the node enters the scene tree for the first time. func _ready(): - Input.mouse_mode = Input.MOUSE_MODE_CAPTURED + #Input.mouse_mode = Input.MOUSE_MODE_CAPTURED camera = find_child("PlayerCamera") pass # Replace with function body. diff --git a/SurfaceNetsWorld/chunk.gd b/SurfaceNetsWorld/chunk.gd index 8ece6ae..39a2ca7 100644 --- a/SurfaceNetsWorld/chunk.gd +++ b/SurfaceNetsWorld/chunk.gd @@ -41,7 +41,7 @@ func _process(_delta: float) -> void: if regenerate_mesh: regenerate_mesh = false clear() - var array_mesh = gpu_sdf.compute_mesh(chunk_size, threshold, self.position) + var array_mesh = await gpu_sdf.compute_mesh(chunk_size, threshold, self.position) var trimesh_collision = array_mesh.create_trimesh_shape() collisionShape3D.set_shape(trimesh_collision) staticBody = StaticBody3D.new() diff --git a/SurfaceNetsWorld/compute_samples.gd b/SurfaceNetsWorld/compute_samples.gd index a8c7188..2b64c5b 100644 --- a/SurfaceNetsWorld/compute_samples.gd +++ b/SurfaceNetsWorld/compute_samples.gd @@ -16,7 +16,6 @@ var pipeline2 var buffer var surface_buffer var normal_buffer -var uv_buffer var idx_buffer var counter_buffer var chunk_position_buffer @@ -46,14 +45,15 @@ func create_device(world_size: int): buffer = rd.storage_buffer_create(total * 4) surface_buffer = rd.storage_buffer_create(total * 3 * 4) normal_buffer = rd.storage_buffer_create(total * 3 * 4) - uv_buffer = rd.storage_buffer_create(total * 2 * 4) idx_buffer = rd.storage_buffer_create(total * 6 * 4) counter_buffer = rd.storage_buffer_create(4) chunk_position_buffer = rd.storage_buffer_create(16) # vec4 params_buffer = rd.uniform_buffer_create(16) # world_size, threshold, time, etc player_edits_buffer = rd.storage_buffer_create(256) + print("device created") func compute_mesh(world_size: int, threshold: float, chunk_pos: Vector3) -> ArrayMesh: + await Engine.get_main_loop().process_frame world_size += 2 # 1. Update existing buffers with NEW data for THIS chunk @@ -104,30 +104,25 @@ func compute_mesh(world_size: int, threshold: float, chunk_pos: Vector3) -> Arra normal_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER normal_uniform.binding = 3 normal_uniform.add_id(normal_buffer) - - var uv_uniform = RDUniform.new() - uv_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER - uv_uniform.binding = 4 - uv_uniform.add_id(uv_buffer) var idx_uniform := RDUniform.new() idx_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER - idx_uniform.binding = 5 + idx_uniform.binding = 4 idx_uniform.add_id(idx_buffer) var counter_uniform := RDUniform.new() counter_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER - counter_uniform.binding = 6 + counter_uniform.binding = 5 counter_uniform.add_id(counter_buffer) var chunk_position_uniform := RDUniform.new() chunk_position_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER - chunk_position_uniform.binding = 7 + chunk_position_uniform.binding = 6 chunk_position_uniform.add_id(chunk_position_buffer) var player_edits_uniform := RDUniform.new() player_edits_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER - player_edits_uniform.binding = 8 + player_edits_uniform.binding = 7 player_edits_uniform.add_id(player_edits_buffer) var uniform_params := RDUniform.new() @@ -135,8 +130,8 @@ func compute_mesh(world_size: int, threshold: float, chunk_pos: Vector3) -> Arra uniform_params.binding = 1 uniform_params.add_id(params_buffer) - var uniform_set1 := rd.uniform_set_create([uniform_buf, uniform_params, surface_uniform_buf, normal_uniform, uv_uniform, idx_uniform, counter_uniform, chunk_position_uniform, player_edits_uniform], shader_pass1, 0) # the last parameter (the 0) needs to match the "set" in our shader file - var uniform_set2 := rd.uniform_set_create([uniform_buf, uniform_params, surface_uniform_buf, normal_uniform, uv_uniform, idx_uniform, counter_uniform], shader_pass2, 0) + var uniform_set1 := rd.uniform_set_create([uniform_buf, uniform_params, surface_uniform_buf, normal_uniform, idx_uniform, counter_uniform, chunk_position_uniform, player_edits_uniform], shader_pass1, 0) # the last parameter (the 0) needs to match the "set" in our shader file + var uniform_set2 := rd.uniform_set_create([uniform_buf, uniform_params, surface_uniform_buf, normal_uniform, idx_uniform, counter_uniform], shader_pass2, 0) var dispatch_count = int(ceil(world_size / 4.0)) @@ -272,7 +267,6 @@ func _exit_tree(): buffer, surface_buffer, normal_buffer, - uv_buffer, idx_buffer, counter_buffer, chunk_position_buffer, diff --git a/SurfaceNetsWorld/compute_surface_points.glsl b/SurfaceNetsWorld/compute_surface_points.glsl index 7a8629e..1beca4b 100644 --- a/SurfaceNetsWorld/compute_surface_points.glsl +++ b/SurfaceNetsWorld/compute_surface_points.glsl @@ -19,27 +19,23 @@ layout(set = 0, binding = 2, std430) buffer SurfaceBuffer { float surface_points[]; } surface; -layout(set = 0, binding = 3, std430) buffer NormalsBuffer { - float normals[]; -} normal; - -layout(set = 0, binding = 4, std430) buffer UVBuffer { - vec2 UVs[]; -} UV; - -layout(set = 0, binding = 5, std430) buffer IndexBuffer { +layout(set = 0, binding = 3, std430) buffer IndexBuffer { uint indices[]; } mesh_indices; -layout(set = 0, binding = 6, std430) buffer Counter { +layout(set = 0, binding = 4, std430) buffer Counter { uint count; } index_count; -layout(set = 0, binding = 7, std430) buffer ChunkPos { +layout(set = 0, binding = 5, std430) buffer NormalsBuffer { + float normals[]; +} normal; + +layout(set = 0, binding = 6, std430) buffer ChunkPos { float position_array[]; } chunk; -layout(set = 0, binding = 8, std430) buffer PlayerEdits { +layout(set = 0, binding = 7, std430) buffer PlayerEdits { float position_size_array[]; } edits; diff --git a/SurfaceNetsWorld/sdf_mesh_generation.glsl b/SurfaceNetsWorld/sdf_mesh_generation.glsl index 2cf38f8..95ff1be 100644 --- a/SurfaceNetsWorld/sdf_mesh_generation.glsl +++ b/SurfaceNetsWorld/sdf_mesh_generation.glsl @@ -6,8 +6,8 @@ layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in; layout(set = 0, binding = 0, std430) buffer DataBuffer { float sample_points[]; } voxels; layout(set = 0, binding = 1) uniform Params { int world_size; float threshold; float u_time; } params; layout(set = 0, binding = 2, std430) buffer SurfaceBuffer { float surface_points[]; } surface; -layout(set = 0, binding = 5, std430) buffer IndexBuffer { uint indices[]; } mesh_indices; -layout(set = 0, binding = 6, std430) buffer Counter { uint count; } index_count; +layout(set = 0, binding = 4, std430) buffer IndexBuffer { uint indices[]; } mesh_indices; +layout(set = 0, binding = 5, std430) buffer Counter { uint count; } index_count; uint index3(uint x, uint y, uint z) { return x + y * params.world_size + z * params.world_size * params.world_size; diff --git a/SurfaceNetsWorld/smooth_world.gd b/SurfaceNetsWorld/smooth_world.gd index a414eed..6b53c73 100644 --- a/SurfaceNetsWorld/smooth_world.gd +++ b/SurfaceNetsWorld/smooth_world.gd @@ -12,7 +12,9 @@ var gpu_sdf # Called when the node enters the scene tree for the first time. func _ready() -> void: gpu_sdf = ComputeSdf.new() + print("creating device") gpu_sdf.create_device(chunk_size) + await Engine.get_main_loop().process_frame for x in range(world_size): for y in range(world_size): for z in range(world_size): diff --git a/SurfaceNetsWorld/smooth_world.tscn b/SurfaceNetsWorld/smooth_world.tscn index 2b7a250..7feb8e4 100644 --- a/SurfaceNetsWorld/smooth_world.tscn +++ b/SurfaceNetsWorld/smooth_world.tscn @@ -4,5 +4,6 @@ [node name="SmoothWorld" type="Node3D" unique_id=113243680] script = ExtResource("1_4h467") -world_size = 8 +chunk_size = 4 +world_size = 2 threshold = 0.46 diff --git a/activation.gd b/activation.gd index 908da37..f9b10f0 100644 --- a/activation.gd +++ b/activation.gd @@ -4,22 +4,21 @@ enum EnumWorld {CUBIC_WORLD, SMOOTH_WORLD} @export var wanted_world: EnumWorld -var enabled_world: EnumWorld = EnumWorld.CUBIC_WORLD +var enabled_world: EnumWorld = EnumWorld.SMOOTH_WORLD var smooth_world = preload("res://SurfaceNetsWorld/smooth_world.tscn") var cubic_world = preload("res://cubic_world.tscn") -signal change_world +func _init() -> void: + add_child(smooth_world.instantiate()) -func _process(_delta: float) -> void: - if enabled_world != wanted_world: - print("changing world") - emit_signal("change_world") -func _on_change_world(): +func change_world(): match wanted_world: EnumWorld.CUBIC_WORLD: + remove_child(smooth_world) add_child(cubic_world.instantiate()) EnumWorld.SMOOTH_WORLD: + remove_child(cubic_world) add_child(smooth_world.instantiate()) enabled_world = wanted_world diff --git a/project.godot b/project.godot index 533ad08..b40863e 100644 --- a/project.godot +++ b/project.godot @@ -33,6 +33,7 @@ settings/addon_root_folder="res://addons/debug_draw_3d" [display] +display_server/driver.linuxbsd="wayland" window/vsync/vsync_mode=0 [editor] diff --git a/world.tscn b/world.tscn index 06ded1a..5bac935 100644 --- a/world.tscn +++ b/world.tscn @@ -28,8 +28,7 @@ transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, - shadow_enabled = true [node name="Player" parent="." unique_id=1950519856 instance=ExtResource("3_036b0")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.182447, 0.6673207, 0.0726881) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.0396366, 2.252273, 7.2927423) gravity_scale = 2.0 PLAYER_SPEED = 0.035 - -[connection signal="change_world" from="." to="." method="_on_change_world"] +NOCLIP = true