From 2fa552abfdf52c688bbec27edd676018a31373e0 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 24 Jan 2021 15:42:00 +0000 Subject: [PATCH] Fixes to support latest module version --- project/blocky_game/blocks/mesher.tres | 6 ++++++ project/blocky_game/blocky_game.tscn | 7 +++---- project/blocky_game/debug_info.gd | 7 ++++++- project/blocky_game/generator/generator.gd | 9 +++++++++ project/blocky_terrain/main.tscn | 11 +++++++---- project/blocky_terrain/voxel_library.tres | 2 ++ project/project.godot | 6 ------ project/smooth_terrain/main.tscn | 12 ++++++++---- 8 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 project/blocky_game/blocks/mesher.tres diff --git a/project/blocky_game/blocks/mesher.tres b/project/blocky_game/blocks/mesher.tres new file mode 100644 index 0000000..2a52080 --- /dev/null +++ b/project/blocky_game/blocks/mesher.tres @@ -0,0 +1,6 @@ +[gd_resource type="VoxelMesherBlocky" load_steps=2 format=2] + +[ext_resource path="res://blocky_game/blocks/voxel_library.tres" type="VoxelLibrary" id=1] + +[resource] +library = ExtResource( 1 ) diff --git a/project/blocky_game/blocky_game.tscn b/project/blocky_game/blocky_game.tscn index f3cb6fc..97fb403 100644 --- a/project/blocky_game/blocky_game.tscn +++ b/project/blocky_game/blocky_game.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=17 format=2] -[ext_resource path="res://blocky_game/blocks/voxel_library.tres" type="VoxelLibrary" id=1] +[ext_resource path="res://blocky_game/blocks/mesher.tres" type="VoxelMesherBlocky" id=1] [ext_resource path="res://blocky_game/blocks/terrain_material.tres" type="Material" id=2] [ext_resource path="res://blocky_game/blocks/terrain_material_transparent.tres" type="Material" id=3] [ext_resource path="res://blocky_game/generator/world_generator.tres" type="VoxelGeneratorScript" id=4] @@ -42,8 +42,6 @@ dof_blur_far_transition = 10.0 glow_hdr_threshold = 0.5 [sub_resource type="VoxelStreamRegionFiles" id=3] -fallback_stream = ExtResource( 4 ) -save_fallback_output = false directory = "res://blocky_game/save" [node name="Main" type="Node"] @@ -60,7 +58,8 @@ environment = SubResource( 2 ) [node name="VoxelTerrain" type="VoxelTerrain" parent="."] stream = SubResource( 3 ) -voxel_library = ExtResource( 1 ) +generator = ExtResource( 4 ) +mesher = ExtResource( 1 ) generate_collisions = false run_stream_in_editor = false material/0 = ExtResource( 2 ) diff --git a/project/blocky_game/debug_info.gd b/project/blocky_game/debug_info.gd index af1be34..da56348 100644 --- a/project/blocky_game/debug_info.gd +++ b/project/blocky_game/debug_info.gd @@ -11,7 +11,12 @@ func _process(delta): DDD.set_text("Static memory", _format_memory(sm)) var global_stats = VoxelServer.get_stats() - for p in [[global_stats.streaming, "streaming_"], [global_stats.meshing, "meshing_"]]: + var pairs = [ + [global_stats.streaming, "streaming_"], + [global_stats.generation, "generation_"], + [global_stats.meshing, "meshing_"] + ] + for p in pairs: var pool_stats = p[0] var prefix = p[1] for k in pool_stats: diff --git a/project/blocky_game/generator/generator.gd b/project/blocky_game/generator/generator.gd index a01adbb..77b75f1 100644 --- a/project/blocky_game/generator/generator.gd +++ b/project/blocky_game/generator/generator.gd @@ -58,15 +58,24 @@ func _init(): _trees_min_y = _heightmap_min_y _trees_max_y = _heightmap_max_y + tallest_tree_height + #_heightmap_noise.seed = 131183 _heightmap_noise.period = 128 _heightmap_noise.octaves = 4 + # IMPORTANT + # If we don't do this `Curve` could bake itself when interpolated, + # and this causes crashes when used in multiple threads + HeightmapCurve.bake() + func _get_used_channels_mask() -> int: return 1 << _CHANNEL func _generate_block(buffer: VoxelBuffer, origin_in_voxels: Vector3, lod: int): + # Saves from this demo used 8-bit, which is no longer the default + buffer.set_channel_depth(_CHANNEL, VoxelBuffer.DEPTH_8_BIT) + # Assuming input is cubic in our use case (it doesn't have to be!) var block_size := int(buffer.get_size().x) var oy := int(origin_in_voxels.y) diff --git a/project/blocky_terrain/main.tscn b/project/blocky_terrain/main.tscn index b04c40d..eb652b3 100644 --- a/project/blocky_terrain/main.tscn +++ b/project/blocky_terrain/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://blocky_terrain/voxel_library.tres" type="VoxelLibrary" id=1] [ext_resource path="res://blocky_terrain/terrain_material.tres" type="Material" id=2] @@ -34,6 +34,9 @@ dof_blur_far_distance = 128.0 dof_blur_far_transition = 10.0 glow_hdr_threshold = 0.5 +[sub_resource type="VoxelMesherBlocky" id=3] +library = ExtResource( 1 ) + [node name="Main" type="Node"] script = ExtResource( 5 ) @@ -41,12 +44,12 @@ script = ExtResource( 5 ) environment = SubResource( 2 ) [node name="VoxelTerrain" type="VoxelTerrain" parent="."] -stream = ExtResource( 4 ) -voxel_library = ExtResource( 1 ) +generator = ExtResource( 4 ) +mesher = SubResource( 3 ) +max_view_distance = 256 generate_collisions = false material/0 = ExtResource( 2 ) material/1 = ExtResource( 3 ) -max_view_distance = 256 [node name="DirectionalLight" type="DirectionalLight" parent="."] transform = Transform( -0.985468, 0.124099, -0.11598, 0.0154004, 0.745271, 0.666584, 0.169159, 0.655111, -0.736353, 1.51966, 19.7004, 14.0879 ) diff --git a/project/blocky_terrain/voxel_library.tres b/project/blocky_terrain/voxel_library.tres index b6a368d..d68dc3e 100644 --- a/project/blocky_terrain/voxel_library.tres +++ b/project/blocky_terrain/voxel_library.tres @@ -4,6 +4,7 @@ [sub_resource type="Voxel" id=1] transparent = true +transparency_index = 1 [sub_resource type="Voxel" id=2] geometry_type = 1 @@ -35,6 +36,7 @@ collision_aabbs = [ AABB( 0, 0, 0, 1, 0.8, 1 ) ] [resource] atlas_size = 4 +bake_tangents = false voxels/0 = SubResource( 1 ) voxels/1 = SubResource( 2 ) voxels/2 = SubResource( 3 ) diff --git a/project/project.godot b/project/project.godot index 6755974..b76622e 100644 --- a/project/project.godot +++ b/project/project.godot @@ -8,15 +8,9 @@ config_version=4 -_global_script_classes=[ ] -_global_script_class_icons={ - -} - [application] config/name="New Game Project" -run/main_scene="res://smooth_terrain/main.tscn" config/icon="res://icon.png" [autoload] diff --git a/project/smooth_terrain/main.tscn b/project/smooth_terrain/main.tscn index bfbc092..9db0112 100644 --- a/project/smooth_terrain/main.tscn +++ b/project/smooth_terrain/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://smooth_terrain/main.gd" type="Script" id=1] [ext_resource path="res://smooth_terrain/transvoxel_terrain_material.tres" type="Material" id=2] @@ -18,13 +18,16 @@ background_sky = SubResource( 1 ) background_color = Color( 1, 1, 1, 1 ) ambient_light_energy = 0.1 ambient_light_sky_contribution = 0.5 +fog_enabled = true fog_color = Color( 0.552734, 0.818359, 0.908691, 1 ) fog_depth_begin = 100.0 -fog_depth_end = 1600.0 +fog_depth_end = 2000.0 fog_height_min = -100.0 fog_height_max = -50.0 fog_height_curve = 0.965937 +[sub_resource type="VoxelMesherTransvoxel" id=3] + [node name="Node" type="Node"] script = ExtResource( 1 ) @@ -54,8 +57,9 @@ omni_range = 100.462 script = ExtResource( 6 ) [node name="VoxelTerrain" type="VoxelLodTerrain" parent="."] -stream = ExtResource( 7 ) -view_distance = 2048 +generator = ExtResource( 7 ) +mesher = SubResource( 3 ) +view_distance = 1024 lod_count = 6 material = ExtResource( 2 ) generate_collisions = false