hypsographic curve

This commit is contained in:
Aada 2026-03-03 22:05:17 +02:00
parent edffc76e05
commit 9a3be12f0f
7 changed files with 66 additions and 18 deletions

BIN
.forgejo/hypsographic-curve.jpg (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -1,5 +1,5 @@
[gd_resource type="Gradient" format=3 uid="uid://b5l44rktieewe"] [gd_resource type="Gradient" format=3 uid="uid://b5l44rktieewe"]
[resource] [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) 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)

View file

@ -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

View file

@ -3,6 +3,7 @@
[ext_resource type="Script" uid="uid://bhpic251bgvgk" path="res://src/Main.cs" id="1_611at"] [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="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="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://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="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"] [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") World = NodePath("TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo")
_textureRect = NodePath("TabContainer/Projection") _textureRect = NodePath("TabContainer/Projection")
_gradient = ExtResource("2_ygjfp") _gradient = ExtResource("2_ygjfp")
_remapCurve = ExtResource("3_1wiy7")
[node name="TabContainer" type="TabContainer" parent="." unique_id=1586027287] [node name="TabContainer" type="TabContainer" parent="." unique_id=1586027287]
layout_mode = 1 layout_mode = 1
@ -73,7 +75,7 @@ stretch = true
[node name="SubViewport" type="SubViewport" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer" unique_id=1257998631] [node name="SubViewport" type="SubViewport" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer" unique_id=1257998631]
handle_input_locally = false handle_input_locally = false
size = Vector2i(677, 554) size = Vector2i(677, 499)
render_target_update_mode = 4 render_target_update_mode = 4
[node name="ZaWarudo" type="Node3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport" unique_id=937719505] [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) transform = Transform3D(100, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0, 0)
mesh = SubResource("CylinderMesh_ygjfp") 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="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] [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] [node name="CollisionShape3D" type="CollisionShape3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo/StaticBody3D" unique_id=299495076]
shape = SubResource("SphereShape3D_rpqi1") 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] [node name="MarginContainer" type="MarginContainer" parent="TabContainer/Planet/VBoxContainer" unique_id=1706135009]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 8 theme_override_constants/margin_left = 8
@ -135,6 +136,19 @@ unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
max_value = 360.0 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] [node name="PanelContainer" type="PanelContainer" parent="TabContainer/Planet" unique_id=716838825]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 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="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_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_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="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/Reset" to="." method="MakeGo"]
[connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer3/Advance" to="." method="Advance"] [connection signal="pressed" from="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer3/Advance" to="." method="Advance"]

View file

@ -8,7 +8,7 @@ void vertex() {
// Called for every vertex the material is visible on. // Called for every vertex the material is visible on.
world_position = VERTEX; world_position = VERTEX;
color = COLOR.r; color = COLOR.r;
VERTEX += VERTEX * COLOR.q * 0.1f; VERTEX += VERTEX * COLOR.q * 0.03f;
} }
void fragment() { void fragment() {

View file

@ -31,9 +31,10 @@ public partial class Main : Control
private int _resolution = 512; private int _resolution = 512;
private PlanetHelper _planetHelper; private PlanetHelper _planetHelper;
[Export] private Curve _remapCurve;
public override void _Ready() public override void _Ready()
{ {
_planetHelper = new PlanetHelper(_meshInstance, _textureRect); _planetHelper = new PlanetHelper(_meshInstance, _textureRect, _remapCurve);
UpdateStats(); UpdateStats();
Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text)); Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text));
AxialTiltChanged(GetNode<LineEdit>("%AxialTilt").Text); AxialTiltChanged(GetNode<LineEdit>("%AxialTilt").Text);
@ -109,7 +110,8 @@ public partial class Main : Control
UpdateStats(); UpdateStats();
Vector3 vertexPos = _planetHelper.Mdt.GetVertex(_vertex.Id) * 0.01f; Vector3 vertexPos = _planetHelper.Mdt.GetVertex(_vertex.Id) * 0.01f;
vertexPos *= _meshInstance.Transform.Basis.Inverse().Orthonormalized(); 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<Node3D>("%Pointer").GlobalPosition = _pointerPosition;
} }
} }
@ -124,12 +126,17 @@ public partial class Main : Control
_planetHelper.AutoRun = true; _planetHelper.AutoRun = true;
} }
_planetHelper.Process(); _planetHelper.Process();
GetNode<Node3D>("%Pointer").GlobalPosition = _pointerPosition;
if (_sunRotating) if (_sunRotating)
{ {
GetNode<Node3D>("%Sun").Rotation -= GetNode<Node3D>("%Sun").Rotation; GetNode<Node3D>("%Sun").Rotation -= GetNode<Node3D>("%Sun").Rotation;
GetNode<Node3D>("%Sun").Rotation += new Vector3(0, (float)Mathf.DegToRad(GetNode<HSlider>("%SunAngle").Value), 0); GetNode<Node3D>("%Sun").Rotation += new Vector3(0, (float)Mathf.DegToRad(GetNode<HSlider>("%SunAngle").Value), 0);
} }
if (_planetRotating)
{
_meshInstance.Rotation = Vector3.Zero;
_meshInstance.RotateY((float)Mathf.DegToRad(GetNode<HSlider>("%PlanetAngle").Value));
_meshInstance.RotateZ(Mathf.DegToRad(_axialTilt));
}
} }
public void UpdateStats() public void UpdateStats()
{ {
@ -160,7 +167,7 @@ public partial class Main : Control
public void MakeGo() public void MakeGo()
{ {
_planetHelper = new PlanetHelper(_meshInstance, _textureRect); _planetHelper = new PlanetHelper(_meshInstance, _textureRect, _remapCurve);
} }
public void Advance() public void Advance()
@ -218,7 +225,7 @@ public partial class Main : Control
{ {
change = new string(change.Where(c => char.IsDigit(c)).ToArray()); change = new string(change.Where(c => char.IsDigit(c)).ToArray());
_resolution = Int32.Parse(change); _resolution = Int32.Parse(change);
_resolution = Math.Clamp(_resolution, 64, 2048); _resolution = Math.Clamp(_resolution, 4, 2048);
} }
public void AxialTiltChanged(string value) public void AxialTiltChanged(string value)
@ -242,4 +249,15 @@ public partial class Main : Control
{ {
_sunRotating = false; _sunRotating = false;
} }
private bool _planetRotating = false;
private float _planetRotation = 0f;
public void PlanetAngleStart()
{
_planetRotating = true;
}
public void PlanetAngleStop(bool changed)
{
_planetRotating = false;
}
} }

View file

@ -99,12 +99,14 @@ public class PlanetHelper
public MeshDataTool Mdt; public MeshDataTool Mdt;
public Oct Octree = new Oct(); public Oct Octree = new Oct();
public PlanetHelper(MeshInstance3D meshInstance, TextureRect textureRect) private Curve _remapCurve;
public PlanetHelper(MeshInstance3D meshInstance, TextureRect textureRect, Curve remapCurve)
{ {
_meshInstance = meshInstance; _meshInstance = meshInstance;
_arrayMesh = meshInstance.Mesh as ArrayMesh; _arrayMesh = meshInstance.Mesh as ArrayMesh;
_textureRect = textureRect; _textureRect = textureRect;
_remapCurve = remapCurve;
_continentalNoise = new FastNoiseLite(); _continentalNoise = new FastNoiseLite();
_mountainNoise = new FastNoiseLite(); _mountainNoise = new FastNoiseLite();
@ -502,7 +504,7 @@ public class PlanetHelper
height = (height + 0.5f * mult) / (1f + mult); height = (height + 0.5f * mult) / (1f + mult);
height += edgeDistance * 0.25f; height += edgeDistance * 0.25f;
height = (height + 0.5f * mult) / (1f + mult); height = (height + 0.5f * mult) / (1f + mult);
height += normalRate * 0.35f; height += normalRate * 0.5f;
height = Mathf.Clamp(height, 0.01f, 0.99f); height = Mathf.Clamp(height, 0.01f, 0.99f);
ColorVertex(vertexData.Id, Colors.White * height); ColorVertex(vertexData.Id, Colors.White * height);
vertexData.StageComplete = true; 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)}'"); GD.Print($"Heights - min:'{Vertices.Min(v => v.Height)}' - max:'{Vertices.Max(v => v.Height)}' - average:'{Vertices.Average(v => v.Height)}'");
ScaleValues(Vertices); ScaleValues(Vertices);
foreach (VertexData vertexData in Vertices) foreach (VertexData vertexData in Vertices)
{
vertexData.Height = _remapCurve.Sample(vertexData.Height);
ColorVertex(vertexData.Id, Colors.White * vertexData.Height); ColorVertex(vertexData.Id, Colors.White * vertexData.Height);
}
float oceanPercentage = Vertices.Count(v => v.Height < 0.5f) / (float)Vertices.Count; float oceanPercentage = Vertices.Count(v => v.Height < 0.5f) / (float)Vertices.Count;
GD.Print($"Ocean Percentage:'{oceanPercentage}'"); GD.Print($"Ocean Percentage:'{oceanPercentage}'");
CompleteStage(); CompleteStage();