diff --git a/modules/terrain/terrain.cpp b/modules/terrain/terrain.cpp index a0d96d56..f8d4eada 100644 --- a/modules/terrain/terrain.cpp +++ b/modules/terrain/terrain.cpp @@ -3,6 +3,7 @@ #include "terrain/terrain_modifier.h" void Terrain::_bind_methods() { + BIND_HPROPERTY(Variant::OBJECT, mesh_material, PROPERTY_HINT_RESOURCE_TYPE, "Material"); BIND_PROPERTY(Variant::INT, side_length); BIND_PROPERTY(Variant::INT, chunk_size); BIND_PROPERTY(Variant::INT, detail); @@ -136,6 +137,7 @@ void Terrain::construct_chunk_grid() { chunk->set_size(this->chunk_size); chunk->set_detail(this->detail); chunk->set_terrain(this); + chunk->set_material_override(this->mesh_material); chunk->set_position(origin + Vector3{ (float)this->chunk_size * (float)x, 0.f, (float)this->chunk_size * (float)y }); add_child(chunk); chunk->set_owner(this); @@ -179,6 +181,17 @@ void Terrain::mesh_dirty(TerrainChunkMesh *mesh) { this->dirty_meshes_lock.unlock(); } +void Terrain::set_mesh_material(Ref material) { + this->mesh_material = material; + for (TerrainChunkMesh *mesh : this->meshes) { + mesh->set_material_override(material); + } +} + +Ref Terrain::get_mesh_material() const { + return this->mesh_material; +} + void Terrain::set_side_length(size_t length) { this->side_length = length; if (is_inside_tree()) { diff --git a/modules/terrain/terrain.h b/modules/terrain/terrain.h index 50cdea6b..64b79a06 100644 --- a/modules/terrain/terrain.h +++ b/modules/terrain/terrain.h @@ -5,6 +5,7 @@ #include "core/os/thread.h" #include "core/templates/vector.h" #include "scene/main/node.h" +#include "scene/resources/material.h" class TerrainChunkMesh; class TerrainModifier; @@ -26,6 +27,7 @@ public: void mesh_dirty(TerrainChunkMesh *mesh); private: + Ref mesh_material{}; Vector workload{}; bool threads_stop{ false }; Mutex workload_lock; @@ -42,6 +44,8 @@ private: size_t detail{ 1 }; public: + void set_mesh_material(Ref material); + Ref get_mesh_material() const; void set_side_length(size_t length); size_t get_side_length() const; void set_chunk_size(size_t size); diff --git a/project/scenes/terrain_test.tscn b/project/scenes/terrain_test.tscn index 865bc6b3..725c8a9f 100644 --- a/project/scenes/terrain_test.tscn +++ b/project/scenes/terrain_test.tscn @@ -1,25 +1,16 @@ [gd_scene format=3 uid="uid://d2w73ie2k01xg"] -[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_kbmr5"] -sky_horizon_color = Color(0.6590071, 0.7017287, 0.7452071, 1) -ground_bottom_color = Color(0.110199995, 0.21208663, 0.29, 1) -ground_horizon_color = Color(0.6590071, 0.7017287, 0.7452071, 1) - -[sub_resource type="Sky" id="Sky_w3uoq"] -sky_material = SubResource("ProceduralSkyMaterial_kbmr5") - -[sub_resource type="Environment" id="Environment_o3i6r"] -background_mode = 2 -sky = SubResource("Sky_w3uoq") +[ext_resource type="Material" uid="uid://b2gybv8h8h0u0" path="res://assets/style/terrain_material.tres" id="1_w3uoq"] +[ext_resource type="PackedScene" uid="uid://bedet0our63p0" path="res://objects/player_vehicle.tscn" id="2_o3i6r"] [sub_resource type="Curve" id="Curve_o3i6r"] _limits = [0.0, 1.0, 0.0, 250.0] -_data = [Vector2(0, 1), 0.0, -0.000564178, 0, 0, Vector2(36.114555, 0.69882035), -0.011034669, -0.011034669, 0, 0, Vector2(213.41736, 0), 0.0, 0.0, 0, 0] +_data = [Vector2(0, 1), 0.0, -0.000564178, 0, 0, Vector2(80.44058, 0.53876877), -0.0053130123, -0.0053130123, 0, 0, Vector2(195.52763, 0), 0.0, 0.0, 0, 0] point_count = 3 [sub_resource type="Curve" id="Curve_kbmr5"] _limits = [0.0, 1.0, 0.0, 250.0] -_data = [Vector2(0, 1), 0.0, -0.0016743571, 0, 0, Vector2(9.812563, 0.89780456), -0.01826421, -0.01826421, 0, 0, Vector2(81.50829, 0), 0.0, 0.0, 0, 0] +_data = [Vector2(0, 1), 0.0, -0.011454834, 0, 0, Vector2(27.836594, 0.57186484), -0.01826421, -0.01826421, 0, 0, Vector2(81.50829, 0), 0.0, 0.0, 0, 0] point_count = 3 [sub_resource type="Curve" id="Curve_w3uoq"] @@ -27,14 +18,75 @@ _limits = [0.0, 1.0, 0.0, 400.0] _data = [Vector2(0, 1), 0.0, -0.013602988, 0, 0, Vector2(134.90071, 0.27425534), -0.002175283, -0.002175283, 0, 0, Vector2(400, 0), 0.0, 0.0, 0, 0] point_count = 3 +[sub_resource type="Curve" id="Curve_chm2y"] +_limits = [0.0, 1.0, 0.0, 10.0] +_data = [Vector2(1.4088161, 1), 0.0, 0.0, 0, 0, Vector2(5.6569343, 0), 0.0, 0.0, 0, 0] +point_count = 2 + [sub_resource type="BoxMesh" id="BoxMesh_kbmr5"] +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_8mrfl"] +sky_top_color = Color(0.28, 0.33600003, 0.56, 1) +sky_horizon_color = Color(0.6590071, 0.7017287, 0.7452071, 1) +ground_bottom_color = Color(0.18026966, 0.32224965, 0.43171933, 1) +ground_horizon_color = Color(0.6590071, 0.7017287, 0.7452071, 1) + +[sub_resource type="Sky" id="Sky_m8orc"] +sky_material = SubResource("ProceduralSkyMaterial_8mrfl") + +[sub_resource type="Environment" id="Environment_1b7vx"] +background_mode = 4 +sky = SubResource("Sky_m8orc") +ambient_light_source = 2 +ambient_light_color = Color(1, 1, 1, 1) +ambient_light_energy = 0.77 +reflected_light_source = 1 +tonemap_mode = 2 +ssao_radius = 16.0 +ssao_intensity = 9.65 +ssao_power = 0.21446471 +ssao_detail = 0.0 +ssao_horizon = 0.57 +ssil_radius = 16.0 +ssil_intensity = 0.65 +fog_enabled = true +fog_mode = 1 +fog_light_color = Color(0.49139997, 0.60203, 0.78, 1) +fog_light_energy = 0.5 +fog_density = 0.0403 +fog_sky_affect = 0.0 +fog_depth_curve = 16.856052 +fog_depth_begin = 20.0 +fog_depth_end = 300.0 + +[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_7eqww"] +dof_blur_far_enabled = true +dof_blur_far_distance = 1000.0 +dof_blur_far_transition = 250.0 +dof_blur_near_enabled = true +dof_blur_near_distance = 1.0 +dof_blur_amount = 0.15 + +[sub_resource type="Compositor" id="Compositor_n0ica"] + +[sub_resource type="SphereMesh" id="SphereMesh_o3i6r"] +flip_faces = true +radius = 1000.0 +height = 2000.0 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_chm2y"] +shading_mode = 0 +diffuse_mode = 3 +specular_mode = 2 +disable_ambient_light = true +disable_fog = true +disable_specular_occlusion = true +albedo_color = Color(0.3, 0.42, 0.6, 1) + [node name="Node3D" type="Node3D" unique_id=289500437] -[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=212607290] -environment = SubResource("Environment_o3i6r") - [node name="Terrain" type="Terrain" parent="." unique_id=1169843565] +mesh_material = ExtResource("1_w3uoq") side_length = 1000 chunk_size = 100 thread_count = 5 @@ -49,15 +101,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 10.727768, 27.24585) gizmo_extents = 50.0 [node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=1155422457] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.40332, -107.40279, 208.53348) -gizmo_extents = 50.0 - -[node name="TerrainModifierPathPoint4" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=1540732620] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.40332, -54.31201, 351.9941) -gizmo_extents = 50.0 - -[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=128158102] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -77.91501, 525.431) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.40332, -148.00479, 208.53348) gizmo_extents = 50.0 [node name="TerrainModifierPath2" type="TerrainModifierPath" parent="Terrain" unique_id=1550750060] @@ -181,7 +225,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.9073486e-06, -33.455353, 26 gizmo_extents = 50.0 [node name="TerrainModifierPath7" type="TerrainModifierPath" parent="Terrain" unique_id=1148491436] -transform = Transform3D(-0.37851927, 0, 0.9255935, 0, 1, 0, -0.9255935, 0, -0.37851927, 688.9682, 63.767326, 790.53827) +transform = Transform3D(-0.34930798, 0, 0.937008, 0, 1, 0, -0.937008, 0, -0.34930798, 713.9996, 63.767326, 803.5471) gizmo_extents = 75.0 curve_left = SubResource("Curve_kbmr5") @@ -193,8 +237,21 @@ gizmo_extents = 50.0 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.9073486e-06, -14.427307, 51.337883) gizmo_extents = 50.0 +[node name="TerrainModifierPath15" type="TerrainModifierPath" parent="Terrain" unique_id=377100977] +transform = Transform3D(0.87613845, 0, -0.48205972, 0, 1, 0, 0.48205972, 0, 0.87613845, 442.01587, 63.767326, 873.5542) +gizmo_extents = 75.0 +curve_left = SubResource("Curve_kbmr5") + +[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath15" unique_id=860393786] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 39.996162, -95.40727) +gizmo_extents = 50.0 + +[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath15" unique_id=719904782] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.9073486e-06, -14.427307, 51.337883) +gizmo_extents = 50.0 + [node name="TerrainModifierPath8" type="TerrainModifierPath" parent="Terrain" unique_id=1073067074] -transform = Transform3D(0.578641, 0, 0.81558245, 0, 1, 0, -0.81558245, 0, 0.578641, 664.5993, 63.767326, 912.3901) +transform = Transform3D(0.6039318, 0, 0.7970361, 0, 1, 0, -0.7970361, 0, 0.6039318, 652.0465, 63.767326, 849.7488) gizmo_extents = 75.0 curve_left = SubResource("Curve_kbmr5") @@ -207,7 +264,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.861023e-06, -14.427307, 76. gizmo_extents = 50.0 [node name="TerrainModifierPath9" type="TerrainModifierPath" parent="Terrain" unique_id=1532428883] -transform = Transform3D(0.37180507, 0, -0.92831093, 0, 1, 0, 0.92831093, 0, 0.37180507, 421.96786, 63.767326, 884.214) +transform = Transform3D(0.54822, 0, -0.83633435, 0, 1, 0, 0.83633435, 0, 0.54822, 414.27563, 63.767326, 819.8631) gizmo_extents = 75.0 curve_left = SubResource("Curve_kbmr5") @@ -219,13 +276,26 @@ gizmo_extents = 50.0 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.33786e-06, -17.280014, 97.858795) gizmo_extents = 50.0 +[node name="TerrainModifierPath14" type="TerrainModifierPath" parent="Terrain" unique_id=1197467315] +transform = Transform3D(0.974878, 0, -0.22274008, 0, 1, 0, 0.22274008, 0, 0.974878, 496.87747, 63.767357, 874.8403) +gizmo_extents = 75.0 +curve_left = SubResource("Curve_kbmr5") + +[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath14" unique_id=296467374] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 39.996162, -95.40727) +gizmo_extents = 50.0 + +[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath14" unique_id=287839679] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 11.463013, -17.280014, 57.301163) +gizmo_extents = 50.0 + [node name="TerrainModifierDistance" type="TerrainModifierDistance" parent="Terrain" unique_id=507842097] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 531.6211, 245.74374, 478.07803) gizmo_extents = 75.0 distance_weight_curve = SubResource("Curve_w3uoq") [node name="TerrainModifierDistance2" type="TerrainModifierDistance" parent="Terrain" unique_id=1864390718] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 537.7046, 176.6785, 842.98895) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 537.7046, 188.42305, 771.08997) gizmo_extents = 75.0 distance_weight_curve = SubResource("Curve_w3uoq") @@ -234,6 +304,112 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 700.02527, 176.67853, 537.683 gizmo_extents = 75.0 distance_weight_curve = SubResource("Curve_w3uoq") +[node name="TerrainModifierPath16" type="TerrainModifierPath" parent="Terrain" unique_id=1875937017] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 547.91394, 106.24594, 693.14124) +gizmo_extents = 20.0 +curve_left = SubResource("Curve_chm2y") + +[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=562094010] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -303.76883, -97.199524, -5.4735107) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1863250736] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -284.15442, -93.65699, 34.196472) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=864150694] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -247.59616, -84.66494, 48.93695) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint5" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1637444898] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -206.18097, -70.56267, 51.2735) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint10" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=2022133395] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -181.71814, -63.68791, 52.104675) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint24" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=505093150] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -180.73126, -62.707283, 33.844666) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint6" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1966961396] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -173.5473, -58.34855, -4.132263) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint9" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=475858004] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -169.73807, -57.761765, -4.765808) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint7" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=880871439] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -149.44589, -53.4385, 45.383667) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint23" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=456417269] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -143.76874, -53.4385, 44.936096) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint8" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=761332021] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -157.52213, -50.949875, -18.348328) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint12" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=531935564] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -152.0875, -49.370678, -20.80951) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint13" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=2002262826] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -131.25415, -45.985725, 36.05304) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint14" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1870007874] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -126.23575, -44.252758, 31.061035) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint15" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=237721263] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -139.04211, -38.793854, -23.744812) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint16" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=827030367] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -132.65558, -37.5054, -25.265686) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint17" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=6521522] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -114.23233, -32.729584, 27.190308) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint18" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1050433045] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -108.55231, -31.790009, 23.808716) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint19" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1215262532] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -121.06961, -28.868042, -28.335022) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint20" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1063799896] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -110.28763, -26.27871, -30.755127) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint21" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=1468145253] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -94.210754, -20.814926, -10.506348) +gizmo_extents = 5.0 + +[node name="TerrainModifierPathPoint22" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath16" unique_id=2009466072] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -59.93094, -11.840431, 3.4630127) +gizmo_extents = 5.0 + [node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1089775425] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 302.4072, 24.064295, 526.4531) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 554.2005, 73.86937, 671.10297) mesh = SubResource("BoxMesh_kbmr5") + +[node name="PlayerVehicle" parent="." unique_id=2037675333 instance=ExtResource("2_o3i6r")] +transform = Transform3D(0.99808544, -0.061849874, 0, 0.061849874, 0.99808544, 0, 0, 0, 1, 554.14685, 73.2292, 676.39417) + +[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=1509403058] +environment = SubResource("Environment_1b7vx") +camera_attributes = SubResource("CameraAttributesPractical_7eqww") +compositor = SubResource("Compositor_n0ica") + +[node name="SkySphere" type="MeshInstance3D" parent="." unique_id=56834935] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 482.60254, 3.9775167, 432.92352) +mesh = SubResource("SphereMesh_o3i6r") +surface_material_override/0 = SubResource("StandardMaterial3D_chm2y")