diff --git a/.forgejo/hypsographic-curve.jpg b/.forgejo/hypsographic-curve.jpg new file mode 100644 index 0000000..3e1efb9 --- /dev/null +++ b/.forgejo/hypsographic-curve.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41b3a3cb6ccb59cf3a3eb40809ddbc1c7090eb5a7010854527e96d76da83b3d7 +size 56070 diff --git a/resources/planet_gradient.tres b/resources/planet_gradient.tres index a7d0a93..b5198ff 100644 --- a/resources/planet_gradient.tres +++ b/resources/planet_gradient.tres @@ -1,5 +1,5 @@ [gd_resource type="Gradient" format=3 uid="uid://b5l44rktieewe"] [resource] -offsets = PackedFloat32Array(0.020102732, 0.21077614, 0.4361486, 0.4835682, 0.49508524, 0.49909908, 0.52932715, 0.5585736, 0.6065243, 0.65517426, 1) +offsets = PackedFloat32Array(0.020102732, 0.21077614, 0.4361486, 0.4835682, 0.49508524, 0.49909908, 0.51515174, 0.5367887, 0.5766606, 0.7845561, 1) colors = PackedColorArray(2.5268645e-07, 3.128499e-07, 0.274243, 1, 8.904189e-07, 2.4065375e-07, 0.42930406, 1, 0.20772403, 0.34871656, 0.66512626, 1, 0.3622311, 0.6195445, 0.94423914, 1, 0.10825918, 0.3611443, 0.64106447, 1, 0.61873, 0.8132518, 0.40761396, 1, 0.35594854, 0.5452644, 0.23284999, 1, 0.77351433, 0.7971149, 0.5667908, 1, 0.7397217, 0.59494364, 0.46294695, 1, 0.3225033, 0.42213485, 0.47578907, 1, 1, 1, 1, 1) diff --git a/resources/remapcurve.tres b/resources/remapcurve.tres new file mode 100644 index 0000000..4cfeec3 --- /dev/null +++ b/resources/remapcurve.tres @@ -0,0 +1,5 @@ +[gd_resource type="Curve" format=3 uid="uid://d3jm8hqn6hf6v"] + +[resource] +_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.03899879, 0.2597651), 0.0, 0.0, 0, 0, Vector2(0.4429419, 0.37015414), 0.47422996, 0.47422996, 0, 0, Vector2(0.5, 0.5), 0.39357203, 0.39357203, 0, 0, Vector2(0.94081944, 0.64621437), 0.80014014, 0.80014014, 0, 0, Vector2(1, 1), 5.804001, 0.0, 0, 0] +point_count = 6 diff --git a/scenes/MainScene.tscn b/scenes/MainScene.tscn index 3b74cc3..cfb06e6 100644 --- a/scenes/MainScene.tscn +++ b/scenes/MainScene.tscn @@ -3,6 +3,7 @@ [ext_resource type="Script" uid="uid://bhpic251bgvgk" path="res://src/Main.cs" id="1_611at"] [ext_resource type="ArrayMesh" uid="uid://65modei4jwaj" path="res://assets/PlanetBase.obj" id="2_k24pf"] [ext_resource type="Gradient" uid="uid://b5l44rktieewe" path="res://resources/planet_gradient.tres" id="2_ygjfp"] +[ext_resource type="Curve" uid="uid://d3jm8hqn6hf6v" path="res://resources/remapcurve.tres" id="3_1wiy7"] [ext_resource type="Material" uid="uid://c55st036tapeo" path="res://shaders/planet.tres" id="3_ygjfp"] [ext_resource type="Material" uid="uid://k3teblrpopsb" path="res://shaders/map.tres" id="4_1wiy7"] [ext_resource type="Texture2D" uid="uid://n56csi5ekat" path="res://icon.svg" id="5_ygjfp"] @@ -45,6 +46,7 @@ _meshInstance = NodePath("TabContainer/Planet/VBoxContainer/SubViewportContainer World = NodePath("TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo") _textureRect = NodePath("TabContainer/Projection") _gradient = ExtResource("2_ygjfp") +_remapCurve = ExtResource("3_1wiy7") [node name="TabContainer" type="TabContainer" parent="." unique_id=1586027287] layout_mode = 1 @@ -73,7 +75,7 @@ stretch = true [node name="SubViewport" type="SubViewport" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer" unique_id=1257998631] handle_input_locally = false -size = Vector2i(677, 554) +size = Vector2i(677, 499) render_target_update_mode = 4 [node name="ZaWarudo" type="Node3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport" unique_id=937719505] @@ -95,6 +97,12 @@ surface_material_override/0 = ExtResource("3_ygjfp") transform = Transform3D(100, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0, 0) mesh = SubResource("CylinderMesh_ygjfp") +[node name="Pointer" type="Sprite3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo/Icosphere" unique_id=1498529325] +unique_name_in_owner = true +modulate = Color(1, 0, 0, 1) +billboard = 1 +texture = ExtResource("5_ygjfp") + [node name="Yaw" type="Node3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo" unique_id=2073443785] [node name="Pitch" type="Node3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo/Yaw" unique_id=98015529] @@ -108,13 +116,6 @@ fov = 5.0 [node name="CollisionShape3D" type="CollisionShape3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo/StaticBody3D" unique_id=299495076] shape = SubResource("SphereShape3D_rpqi1") -[node name="Pointer" type="Sprite3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo" unique_id=1498529325] -unique_name_in_owner = true -transform = Transform3D(0.01, 0, 0, 0, 0.01, 0, 0, 0, 0.01, 0, 0, 0) -modulate = Color(1, 0, 0, 1) -billboard = 1 -texture = ExtResource("5_ygjfp") - [node name="MarginContainer" type="MarginContainer" parent="TabContainer/Planet/VBoxContainer" unique_id=1706135009] layout_mode = 2 theme_override_constants/margin_left = 8 @@ -135,6 +136,19 @@ unique_name_in_owner = true layout_mode = 2 max_value = 360.0 +[node name="HSeparator" type="HSeparator" parent="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer" unique_id=1053749080] +layout_mode = 2 + +[node name="Label2" type="Label" parent="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer" unique_id=473804807] +layout_mode = 2 +text = "Planet Rotation" +horizontal_alignment = 1 + +[node name="PlanetAngle" type="HSlider" parent="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer" unique_id=1574475714] +unique_name_in_owner = true +layout_mode = 2 +max_value = 360.0 + [node name="PanelContainer" type="PanelContainer" parent="TabContainer/Planet" unique_id=716838825] layout_mode = 2 size_flags_horizontal = 3 @@ -317,6 +331,8 @@ metadata/_tab_index = 1 [connection signal="mouse_exited" from="TabContainer/Planet/VBoxContainer/SubViewportContainer" to="." method="MouseLeftViewport"] [connection signal="drag_ended" from="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer/SunAngle" to="." method="SunAngleStop"] [connection signal="drag_started" from="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer/SunAngle" to="." method="SunAngleStart"] +[connection signal="drag_ended" from="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer/PlanetAngle" to="." method="PlanetAngleStop"] +[connection signal="drag_started" from="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer/PlanetAngle" to="." method="PlanetAngleStart"] [connection signal="text_changed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer2/HBoxContainer/AxialTilt" to="." method="AxialTiltChanged"] [connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer3/Reset" to="." method="MakeGo"] [connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer3/Advance" to="." method="Advance"] diff --git a/shaders/planet.gdshader b/shaders/planet.gdshader index 7530787..36376be 100644 --- a/shaders/planet.gdshader +++ b/shaders/planet.gdshader @@ -8,7 +8,7 @@ void vertex() { // Called for every vertex the material is visible on. world_position = VERTEX; color = COLOR.r; - VERTEX += VERTEX * COLOR.q * 0.1f; + VERTEX += VERTEX * COLOR.q * 0.03f; } void fragment() { diff --git a/src/Main.cs b/src/Main.cs index 361faf9..2f58cc4 100644 --- a/src/Main.cs +++ b/src/Main.cs @@ -31,9 +31,10 @@ public partial class Main : Control private int _resolution = 512; private PlanetHelper _planetHelper; + [Export] private Curve _remapCurve; public override void _Ready() { - _planetHelper = new PlanetHelper(_meshInstance, _textureRect); + _planetHelper = new PlanetHelper(_meshInstance, _textureRect, _remapCurve); UpdateStats(); Projector.GatherPoints(_planetHelper, int.Parse(GetNode("%Resolution").Text)); AxialTiltChanged(GetNode("%AxialTilt").Text); @@ -109,7 +110,8 @@ public partial class Main : Control UpdateStats(); Vector3 vertexPos = _planetHelper.Mdt.GetVertex(_vertex.Id) * 0.01f; vertexPos *= _meshInstance.Transform.Basis.Inverse().Orthonormalized(); - _pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.1f); // vertexPos * 1.01f; + _pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.03f); // vertexPos * 1.01f; + GetNode("%Pointer").GlobalPosition = _pointerPosition; } } @@ -124,12 +126,17 @@ public partial class Main : Control _planetHelper.AutoRun = true; } _planetHelper.Process(); - GetNode("%Pointer").GlobalPosition = _pointerPosition; if (_sunRotating) { GetNode("%Sun").Rotation -= GetNode("%Sun").Rotation; GetNode("%Sun").Rotation += new Vector3(0, (float)Mathf.DegToRad(GetNode("%SunAngle").Value), 0); } + if (_planetRotating) + { + _meshInstance.Rotation = Vector3.Zero; + _meshInstance.RotateY((float)Mathf.DegToRad(GetNode("%PlanetAngle").Value)); + _meshInstance.RotateZ(Mathf.DegToRad(_axialTilt)); + } } public void UpdateStats() { @@ -160,7 +167,7 @@ public partial class Main : Control public void MakeGo() { - _planetHelper = new PlanetHelper(_meshInstance, _textureRect); + _planetHelper = new PlanetHelper(_meshInstance, _textureRect, _remapCurve); } public void Advance() @@ -218,7 +225,7 @@ public partial class Main : Control { change = new string(change.Where(c => char.IsDigit(c)).ToArray()); _resolution = Int32.Parse(change); - _resolution = Math.Clamp(_resolution, 64, 2048); + _resolution = Math.Clamp(_resolution, 4, 2048); } public void AxialTiltChanged(string value) @@ -242,4 +249,15 @@ public partial class Main : Control { _sunRotating = false; } + private bool _planetRotating = false; + private float _planetRotation = 0f; + public void PlanetAngleStart() + { + _planetRotating = true; + } + + public void PlanetAngleStop(bool changed) + { + _planetRotating = false; + } } diff --git a/src/PlanetHelper.cs b/src/PlanetHelper.cs index 6756490..34122b5 100644 --- a/src/PlanetHelper.cs +++ b/src/PlanetHelper.cs @@ -99,12 +99,14 @@ public class PlanetHelper public MeshDataTool Mdt; public Oct Octree = new Oct(); - - public PlanetHelper(MeshInstance3D meshInstance, TextureRect textureRect) + + private Curve _remapCurve; + public PlanetHelper(MeshInstance3D meshInstance, TextureRect textureRect, Curve remapCurve) { _meshInstance = meshInstance; _arrayMesh = meshInstance.Mesh as ArrayMesh; _textureRect = textureRect; + _remapCurve = remapCurve; _continentalNoise = new FastNoiseLite(); _mountainNoise = new FastNoiseLite(); @@ -502,7 +504,7 @@ public class PlanetHelper height = (height + 0.5f * mult) / (1f + mult); height += edgeDistance * 0.25f; height = (height + 0.5f * mult) / (1f + mult); - height += normalRate * 0.35f; + height += normalRate * 0.5f; height = Mathf.Clamp(height, 0.01f, 0.99f); ColorVertex(vertexData.Id, Colors.White * height); vertexData.StageComplete = true; @@ -513,8 +515,12 @@ public class PlanetHelper { GD.Print($"Heights - min:'{Vertices.Min(v => v.Height)}' - max:'{Vertices.Max(v => v.Height)}' - average:'{Vertices.Average(v => v.Height)}'"); ScaleValues(Vertices); + foreach (VertexData vertexData in Vertices) + { + vertexData.Height = _remapCurve.Sample(vertexData.Height); ColorVertex(vertexData.Id, Colors.White * vertexData.Height); + } float oceanPercentage = Vertices.Count(v => v.Height < 0.5f) / (float)Vertices.Count; GD.Print($"Ocean Percentage:'{oceanPercentage}'"); CompleteStage();