From 4b153bb6b5f9ba6bff59da2fe94ae93ae4a53f07 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 10 Jun 2023 17:09:24 +0200 Subject: [PATCH] Fixed world height and color texture lookup. --- assets/4x4checkerPattern.png | Bin 0 -> 5149 bytes assets/4x4checkerPattern.png.import | 35 +++++++ assets/5x5checkerColor.png | Bin 0 -> 8876 bytes assets/5x5checkerColor.png.import | 35 +++++++ assets/5x5checkerPattern.png | Bin 0 -> 8626 bytes assets/5x5checkerPattern.png.import | 35 +++++++ materials/HexTileTextureLookup.tres | 2 +- materials/shader/CoordToTexture.gdshader | 79 +++++++++++++++ materials/shader/HexToTexture.gdshader | 13 ++- project.godot | 1 + scenes/Game.cs | 16 ++- scenes/Game.tscn | 77 +++++++------- scenes/HexTile3D.tscn | 2 +- scenes/HexTile3DPatch.tscn | 3 + scenes/TileWorld.cs | 124 ++++++++--------------- scenes/tests/FragmentShaderHexTile.tres | 15 +-- scenes/tests/FragmentShaderHexTile.tscn | 15 ++- ui/WorldGeneratorUI.gd | 14 +++ 18 files changed, 316 insertions(+), 150 deletions(-) create mode 100644 assets/4x4checkerPattern.png create mode 100644 assets/4x4checkerPattern.png.import create mode 100644 assets/5x5checkerColor.png create mode 100644 assets/5x5checkerColor.png.import create mode 100644 assets/5x5checkerPattern.png create mode 100644 assets/5x5checkerPattern.png.import create mode 100644 materials/shader/CoordToTexture.gdshader create mode 100644 ui/WorldGeneratorUI.gd diff --git a/assets/4x4checkerPattern.png b/assets/4x4checkerPattern.png new file mode 100644 index 0000000000000000000000000000000000000000..3596b9093a2a0734e9572d4ac37d236ad7627ba8 GIT binary patch literal 5149 zcmeHKX;>5I7LI^`3dkyo6hqjTB$I?C83~9$AxIDb0TG4CWCE#VpO6?t5H5-p6-o=T zDB@O%6sb!q*A)?=)};a}MNzMSD2hr2sUmtO0k`M&kI!@a&pgj0lk>gjJ?FgNneY2% zV?=nc;dHC%I2_K96%rVU{pzSMeJ$+Uv1pnLcE3v%9f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&VQF0PZbl|kD5Y6Oq;#{ANN==ZD2&JpS6fFZu$za`Y~cI zfav$jMx0)VvlaA@>FPJlj%EBWetsK^|6&V7>VF&gNBaIN*S~W8BL)5u_}}dMSFV4g zz&`^2n_d5Ja?$*`;la2OS3y3+?M!M(kQ#9-M2Whhp?b0@0_>>N-5{1uxocj>0{{@7 zv%b5 z7J7!62qLbim5iweNU(s^BND=}#ZfgNAD|bL2H=s21YDq(29O>bC;@(eo0(X^&XE^j zVRZ-qAnocrB6=Ske~#~YnA9TxpFq~pW!$pr7XlEKub+ewM^MI?0*1DK?>gh literal 0 HcmV?d00001 diff --git a/assets/5x5checkerColor.png.import b/assets/5x5checkerColor.png.import new file mode 100644 index 0000000..9b86466 --- /dev/null +++ b/assets/5x5checkerColor.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/5x5checkerColor.png-0b102dcaa34ad617f92db40e12de058f.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/5x5checkerColor.png" +dest_files=[ "res://.import/5x5checkerColor.png-0b102dcaa34ad617f92db40e12de058f.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=1 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=1 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/5x5checkerPattern.png b/assets/5x5checkerPattern.png new file mode 100644 index 0000000000000000000000000000000000000000..c2f904bab5670aec6d764f36f56d438096a98af4 GIT binary patch literal 8626 zcmeHLXH-*7yQMejieQ5fdPyOnCDJn$3890EbU^_Hq$y2M5ftfF6p)T| z0Ra_hBE2b!+<fL#7Z!l^$2n6__>VtH$0dD2CR{(* zJVBuG7Pb~*GK3QRQP0L(c-+#pI_J=lk*vp+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rM9kt z(H{|q61d>-UPn=6vHyl7;++2!>u+N_>^UmuuLB{6|H1n=^zXGFfypQX1Ehv0+V^mH zx*CeW!~95$CmM%A9$m^~vBB>4Qg+ zrxS-qxnLn)9xg{6hk_$jjdT@(Fz~OeM=eI~D55htKoO{q^YHcm6KaOTV@-*uLp8~% zWnl<;IVrdd3@#@v^C!q0>q8(r@sLvr3WopUJ)9OKxfrsrs6(HU363JjwIJ1fuqdLZ zkC~^ZyCU##0D!~DBYOiBeocxFjzC5P96J6t&zoYsf8G6h1l(~)T>!w5ZILMSuOtK% z3HwU}a@?;j^ktNX3zqzR|7NJ)+j0M4vS2a@ggnd%4MI!HqsR)wr9e(HPEe4O6dVCZ z$s^?DF|eaD{$M9~Iurd+K3G*3a;4;I$Oby91|WJQrP$xmewVR_IzeG@5L6ZfMVLXM zNEs=lw2TB4hJ-?akpF&(2x(a;6hn5Qw45B-k1!`VxkPCUNE(a9!k`FgCwA1UyU!2i1IU%CE~0{;m7ue<)=^9-Y$#ZH=RSAH_HIx-jw;qnC~qfr0`oaQLP4FHk0t8|jI<2AcHqbc_s~{A{L7 z5#***L`_Sgx+nf{Yd~@I#)`!N{BXp}fWtRdi>s{MWRR(@hN>CEC~dPUQ#ka5N^|P1 z_=1mWG!}|hKi8?7&xpp9!reovwpydT%0CXWnl8pYh4seuhw4L$IH(>`X)LI{f>cGheAM2tXJG!YHW8^c1?9h8iVmj@SMN7w2TC literal 0 HcmV?d00001 diff --git a/assets/5x5checkerPattern.png.import b/assets/5x5checkerPattern.png.import new file mode 100644 index 0000000..b76bfe2 --- /dev/null +++ b/assets/5x5checkerPattern.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/5x5checkerPattern.png-1235e6d8801ed94a1c7fab425cf83b94.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/5x5checkerPattern.png" +dest_files=[ "res://.import/5x5checkerPattern.png-1235e6d8801ed94a1c7fab425cf83b94.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=1 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/materials/HexTileTextureLookup.tres b/materials/HexTileTextureLookup.tres index 589442b..23fdb6c 100644 --- a/materials/HexTileTextureLookup.tres +++ b/materials/HexTileTextureLookup.tres @@ -1,6 +1,6 @@ [gd_resource type="ShaderMaterial" load_steps=3 format=2] -[ext_resource path="res://assets/4x4checkerColor.png" type="Texture" id=1] +[ext_resource path="res://assets/4x4checkerPattern.png" type="Texture" id=1] [ext_resource path="res://materials/shader/HexToTexture.gdshader" type="Shader" id=2] [resource] diff --git a/materials/shader/CoordToTexture.gdshader b/materials/shader/CoordToTexture.gdshader new file mode 100644 index 0000000..755f0a6 --- /dev/null +++ b/materials/shader/CoordToTexture.gdshader @@ -0,0 +1,79 @@ +shader_type spatial; +render_mode specular_schlick_ggx, async_visible; + +uniform sampler2D MapAlbedoTexture : hint_black_albedo; +uniform int TextureSize: hint_range(0, 1024, 4); +varying vec2 map_coord; +varying vec3 obj_coord; + +const mat2 _HexAffineInverse = mat2(vec2(1.333333, -0.6666667), vec2(0, -1.154701)); + +vec3 axial_to_cube(vec2 axial) { + return vec3(axial.x, axial.y, -axial.x - axial.y); +} + +ivec3 round_cube_coords(vec3 cube) { + ivec3 rounded = ivec3(round(cube)); + + vec3 diffs = abs(vec3(rounded) - cube); + + if (diffs.x > diffs.y && diffs.x > diffs.z) { + rounded.x = -rounded.y - rounded.z; + } else if (diffs.y > diffs.z) { + rounded.y = -rounded.x - rounded.z; + } else { + rounded.z = -rounded.x - rounded.y; + } + + return rounded; +} + +vec2 axial_to_offset(vec2 axial) { + ivec3 cubeCoords = round_cube_coords(axial_to_cube(axial)); + int x = cubeCoords.x; + int y = cubeCoords.y; + int off_y = y + (x - (x & 1)) / 2; + return vec2(float(x), float(off_y)); +} + +void vertex() { +// Input:2 + mat4 model_matrix = WORLD_MATRIX; + + vec3 origin = vec4(WORLD_MATRIX * vec4(0, 0, 0, 1)).xyz; + vec3 axial_coords = vec3(_HexAffineInverse * origin.xz, 0); + + vec2 offset_coords = axial_to_offset(axial_coords.xy); + //map_coord = mod(axial_to_offset(axial_coords.xy), vec2(float(TextureSize))); + map_coord = offset_coords; + map_coord.y = -map_coord.y; + + + float map_size = 4.0; + map_coord = mod(origin.xz, map_size) / (map_size); + //map_coord = mod((round(origin.xz * map_size)) / (map_size) , map_size); + +// if (map_coord.x > map_size) { +// map_coord.x = map_coord.x - (map_size + 1.0); +// } + +// map_coord.x = map_coord.x / map_size; +// map_coord.x = (mod (map_coord.x, map_size) / (map_size + 1.0)); +// map_coord.y = (mod (map_coord.y, map_size) / (map_size + 1.0)); + +// ivec2 map_coord_i = ivec2(map_coord); +// map_coord_i.x = map_coord_i.x % TextureSize; +// map_coord_i.y = map_coord_i.y % TextureSize; +// map_coord = vec2(map_coord_i) / float(TextureSize); + obj_coord = origin; +} + +void fragment() { + //ALBEDO = pow(texture(MapAlbedoTexture, map_coord).rgb, vec3(2.4)); + ALBEDO = texture(MapAlbedoTexture, map_coord).rgb; +} + +void light() { +// Output:0 + +} diff --git a/materials/shader/HexToTexture.gdshader b/materials/shader/HexToTexture.gdshader index a6d2f19..517277a 100644 --- a/materials/shader/HexToTexture.gdshader +++ b/materials/shader/HexToTexture.gdshader @@ -31,23 +31,26 @@ vec2 axial_to_offset(vec2 axial) { ivec3 cubeCoords = round_cube_coords(axial_to_cube(axial)); int x = cubeCoords.x; int y = cubeCoords.y; - int off_y = y + (x - (x % 2)) / 2; + int off_y = y + (x - (x & 1)) / 2; return vec2(float(x), float(off_y)); } void vertex() { -// Input:2 mat4 model_matrix = WORLD_MATRIX; vec3 origin = vec4(WORLD_MATRIX * vec4(0, 0, 0, 1)).xyz; vec3 axial_coords = vec3(_HexAffineInverse * origin.xz, 0); - map_coord = origin.xz * 1. / float(TextureSize); - map_coord = axial_to_offset(axial_coords.xy) / float(TextureSize) - vec2(0.5); + map_coord = axial_to_offset(axial_coords.xy); } void fragment() { - ALBEDO = pow(texture(MapAlbedoTexture, map_coord).rgb, vec3(2.4)); + float size = float(TextureSize); + vec2 texel_offset = vec2(ceil(size / 2.0)); + ivec2 texel_coord = ivec2(mod(map_coord.xy - texel_offset, vec2(size))); + vec4 texel_value = texelFetch(MapAlbedoTexture, texel_coord, 0); + + ALBEDO = texelFetch(MapAlbedoTexture, texel_coord, 0).rgb; } void light() { diff --git a/project.godot b/project.godot index afb22bb..f9b6e9d 100644 --- a/project.godot +++ b/project.godot @@ -90,6 +90,7 @@ window/stretch/aspect="expand" [global] collision=false +srgb=false [input] diff --git a/scenes/Game.cs b/scenes/Game.cs index 2b069a8..be2a6cb 100644 --- a/scenes/Game.cs +++ b/scenes/Game.cs @@ -65,7 +65,7 @@ public class Game : Spatial _player = GetNode("Player"); _chest = GetNode("Entities/Chest"); _tileWorld = GetNode("TileWorld"); - _camera = GetNode("Camera"); + _camera = GetNode("StreamContainer/Camera"); _cameraOffset = _camera.GlobalTranslation - _player.GlobalTranslation; Debug.Assert(_tileWorld != null); @@ -114,7 +114,7 @@ public class Game : Spatial worldInfoComponent.SetWorld(_tileWorld); } - _tileWorld.Generate(); + _tileWorld.Generate(_tileWorld.Size); UpdateCurrentTile(); _streamContainer.SetCenterTile(_currentTile); } @@ -177,15 +177,21 @@ public class Game : Spatial Transform cameraTransform = _camera.Transform; cameraTransform.origin = _player.GlobalTranslation + _cameraOffset; - _camera.Transform = cameraTransform; +// _camera.Transform = cameraTransform; } public void OnGenerateButton() { GD.Print("Generating"); + Slider worldSizeSlider = (Slider)FindNode("WorldSizeSlider"); + if (worldSizeSlider == null) + { + GD.PrintErr("Could not find WorldSizeSlider!"); + return; + } _tileWorld.Seed = _tileWorld.Seed + 1; - _tileWorld.Generate(); + _tileWorld.Generate((int)worldSizeSlider.Value); } @@ -266,7 +272,7 @@ public class Game : Spatial public void OnWorldGenerated() { - GD.Print("Using new map"); + GD.Print("Using new map. Size: " + (int)_tileWorld.Colormap.GetSize().x); ImageTexture newWorldTexture = new ImageTexture(); newWorldTexture.CreateFromImage(_tileWorld.Colormap, (uint) (Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat)); diff --git a/scenes/Game.tscn b/scenes/Game.tscn index d31c926..615b338 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://scenes/StreamContainer.cs" type="Script" id=1] [ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2] @@ -11,6 +11,7 @@ [ext_resource path="res://scenes/Game.cs" type="Script" id=9] [ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=10] [ext_resource path="res://assets/CreatusPiratePack/Models/Characters/gltf/Pirate1final.glb" type="PackedScene" id=11] +[ext_resource path="res://ui/WorldGeneratorUI.gd" type="Script" id=12] [sub_resource type="CubeMesh" id=1] size = Vector3( 1, 1, 1 ) @@ -26,19 +27,6 @@ extents = Vector3( 20, 1, 20 ) radius = 0.3 height = 0.2 -[sub_resource type="SpatialMaterial" id=20] -albedo_color = Color( 0.741176, 0.529412, 0.32549, 1 ) - -[sub_resource type="CapsuleMesh" id=8] -material = SubResource( 20 ) -radius = 0.2 -mid_height = 0.5 -radial_segments = 16 - -[sub_resource type="CubeMesh" id=14] - -[sub_resource type="PrismMesh" id=15] - [sub_resource type="CylinderShape" id=24] height = 0.2 @@ -68,19 +56,20 @@ margin_bottom = 158.0 mouse_filter = 2 alignment = 2 -[node name="VBoxContainer" type="VBoxContainer" parent="Control/HBoxContainer"] +[node name="WorldGeneratorUI" type="VBoxContainer" parent="Control/HBoxContainer"] margin_right = 100.0 -margin_bottom = 228.0 +margin_bottom = 248.0 alignment = 2 +script = ExtResource( 12 ) -[node name="WorldTextureRect" type="TextureRect" parent="Control/HBoxContainer/VBoxContainer"] +[node name="WorldTextureRect" type="TextureRect" parent="Control/HBoxContainer/WorldGeneratorUI"] margin_right = 100.0 margin_bottom = 100.0 rect_min_size = Vector2( 100, 100 ) stretch_mode = 1 flip_v = true -[node name="HeightTextureRect" type="TextureRect" parent="Control/HBoxContainer/VBoxContainer"] +[node name="HeightTextureRect" type="TextureRect" parent="Control/HBoxContainer/WorldGeneratorUI"] margin_top = 104.0 margin_right = 100.0 margin_bottom = 204.0 @@ -88,16 +77,36 @@ rect_min_size = Vector2( 100, 100 ) stretch_mode = 1 flip_v = true -[node name="WorldGenerateButton" type="Button" parent="Control/HBoxContainer/VBoxContainer"] +[node name="WorldGenerateButton" type="Button" parent="Control/HBoxContainer/WorldGeneratorUI"] margin_top = 208.0 margin_right = 100.0 margin_bottom = 228.0 text = "Generate" +[node name="HBoxContainer" type="HBoxContainer" parent="Control/HBoxContainer/WorldGeneratorUI"] +margin_top = 232.0 +margin_right = 100.0 +margin_bottom = 248.0 + +[node name="WorldSizeSlider" type="HSlider" parent="Control/HBoxContainer/WorldGeneratorUI/HBoxContainer"] +margin_right = 88.0 +margin_bottom = 16.0 +size_flags_horizontal = 3 +min_value = 1.0 +max_value = 512.0 +value = 1.0 + +[node name="WorldSizeLabel" type="Label" parent="Control/HBoxContainer/WorldGeneratorUI/HBoxContainer"] +margin_left = 92.0 +margin_top = 1.0 +margin_right = 100.0 +margin_bottom = 15.0 +text = "4" + [node name="GridContainer" type="GridContainer" parent="Control/HBoxContainer"] margin_left = 104.0 margin_right = 231.0 -margin_bottom = 228.0 +margin_bottom = 248.0 mouse_filter = 2 columns = 2 @@ -222,7 +231,7 @@ text = "0" [node name="StreamContainer" type="Spatial" parent="."] script = ExtResource( 1 ) -Dimensions = Vector2( 18, 17 ) +Dimensions = Vector2( 30, 30 ) World = NodePath("../TileWorld") [node name="ActiveTiles" type="Spatial" parent="StreamContainer"] @@ -240,8 +249,8 @@ material/0 = SubResource( 2 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 ) shape = SubResource( 9 ) -[node name="Camera" type="Camera" parent="."] -transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, -4.76837e-07, 4.79787, 2.99071 ) +[node name="Camera" type="Camera" parent="StreamContainer"] +transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, 1.7053e-13, 10.6428, 6.65615 ) current = true fov = 60.0 script = ExtResource( 10 ) @@ -256,26 +265,6 @@ script = ExtResource( 3 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) shape = SubResource( 7 ) -[node name="MeshInstance" type="MeshInstance" parent="Player"] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) -mesh = SubResource( 8 ) - -[node name="Arrow" type="Spatial" parent="Player/MeshInstance"] -transform = Transform( 3, -1.51264e-15, -9.91796e-22, 0, -8.74228e-09, 3, -2.26897e-14, -0.2, -1.31134e-07, 0, -0.253289, 0.32602 ) -visible = false - -[node name="MeshInstance" type="MeshInstance" parent="Player/MeshInstance/Arrow"] -transform = Transform( 0.1, 0, 3.72529e-09, 0, 0.1, 0, -3.72529e-09, 0, 0.1, 0, 0, 0 ) -visible = false -mesh = SubResource( 14 ) -skeleton = NodePath("../../..") - -[node name="MeshInstance2" type="MeshInstance" parent="Player/MeshInstance/Arrow"] -transform = Transform( 0.1, 3.72529e-09, -1.62838e-16, 0, -4.37114e-09, -0.1, -3.72529e-09, 0.1, -4.37114e-09, 0, 0, 0.191322 ) -visible = false -mesh = SubResource( 15 ) -skeleton = NodePath("../../..") - [node name="Movable" parent="Player" instance=ExtResource( 4 )] [node name="Geometry" type="Spatial" parent="Player"] @@ -318,4 +307,6 @@ transform = Transform( 0.550568, 0, -0.83479, 0, 1, 0, 0.83479, 0, 0.550568, 4.8 [node name="Chest2" parent="Entities" instance=ExtResource( 7 )] transform = Transform( 0.793576, 0, -0.608471, 0, 1, 0, 0.608471, 0, 0.793576, 2.79265, 0, -5.36551 ) +[connection signal="value_changed" from="Control/HBoxContainer/WorldGeneratorUI/HBoxContainer/WorldSizeSlider" to="Control/HBoxContainer/WorldGeneratorUI" method="_on_HSlider_value_changed"] + [editable path="Entities/Chest"] diff --git a/scenes/HexTile3D.tscn b/scenes/HexTile3D.tscn index 857f640..c8c2fa4 100644 --- a/scenes/HexTile3D.tscn +++ b/scenes/HexTile3D.tscn @@ -19,7 +19,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0096302, 0, 0 ) script = ExtResource( 1 ) [node name="Mesh" type="MeshInstance" parent="."] -transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.00399733, -5, 0 ) +transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.0325004, -5, -0.0786072 ) mesh = SubResource( 6 ) material/0 = ExtResource( 2 ) diff --git a/scenes/HexTile3DPatch.tscn b/scenes/HexTile3DPatch.tscn index 65b733d..57f2235 100644 --- a/scenes/HexTile3DPatch.tscn +++ b/scenes/HexTile3DPatch.tscn @@ -1203,3 +1203,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.762809, 0, -1.31108 ) [node name="HexTile3D400" parent="." instance=ExtResource( 1 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.762809, 0, -9.08685 ) + +[node name="Camera" type="Camera" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20, 0 ) diff --git a/scenes/TileWorld.cs b/scenes/TileWorld.cs index 7a1a6d9..c982483 100644 --- a/scenes/TileWorld.cs +++ b/scenes/TileWorld.cs @@ -1,9 +1,7 @@ using Godot; using System; using System.Linq; -using System.Numerics; using System.Diagnostics; -using GoDotLog; using Vector2 = Godot.Vector2; using Vector3 = Godot.Vector3; @@ -16,15 +14,15 @@ public class TileWorld : Spatial Done } - private GenerationState CurrentGenerationState = GenerationState.Heightmap; + private GenerationState _currentGenerationState = GenerationState.Heightmap; // signals [Signal] delegate void WorldGenerated(); // public members - public float Size = 100; - public float HeightScale = 10.0f; + public int Size = 11; + public float HeightScale = 2.0f; public Image Heightmap; public Image Colormap; public int Seed = 0; @@ -58,72 +56,54 @@ public class TileWorld : Spatial Debug.Assert(_heightmapOffscreenTextureRect != null); _heightmapOffscreenTextureRect.SetSize(new Vector2(Size, Size)); - Generate(); + Generate(Size); } - public void Generate() + public void Generate(int size) { + GD.Print("Triggering generation for size: " + size); + Size = size; + _worldOffscreenViewport.Size = new Vector2(size, size); + _heightmapOffscreenViewport.Size = new Vector2(size, size); + GenerateNoiseMap(); - //GenerateDebugMap(); +// GenerateDebugMap(); } private void GenerateDebugMap() { Colormap = new Image(); - Colormap.Create((int)Size, (int)Size, false, Image.Format.Rgba8); + Colormap.Create(Size, Size, false, Image.Format.Rgba8); Heightmap = new Image(); - Heightmap.Create((int)Size, (int)Size, false, Image.Format.Rf); + Heightmap.Create(Size, Size, false, Image.Format.Rf); Heightmap.Lock(); Colormap.Lock(); - foreach (int coord_x in Enumerable.Range(0, (int)Size)) + + foreach (int coord_x in Enumerable.Range(0, Size)) { - foreach (int coord_y in Enumerable.Range(0, (int)Size)) + foreach (int coord_y in Enumerable.Range(0, Size)) { -// Colormap.SetPixel(coord_x, coord_y, new Color((float) coord_x, (float) coord_y, 0, 1)); - float coord_to_height = - (float)coord_y / Size * 0f; - - if (coord_x == 1 && coord_y == 4) - { - coord_to_height = 1; - } - - SetHeightAtOffset(new Vector2(coord_x, coord_y), coord_to_height); + Colormap.SetPixel(coord_x, coord_y, new Color((float) Mathf.Min(coord_x, coord_y) / Size, (float) 0, 0, 1)); + Heightmap.SetPixel(coord_x, coord_y, new Color((float) Mathf.Min(coord_x, coord_y) / Size, (float) 0, 0, 1)); } } + + Colormap.SetPixel(Size - 1, Size -1, new Color(1, 1, 1, 1)); Colormap.Unlock(); - - ImageTexture imageTexture = new ImageTexture(); - imageTexture.CreateFromImage(Heightmap); - imageTexture.Flags = 0; - _worldOffscreenTextureRect.Texture = imageTexture; - Colormap.CopyFrom(imageTexture.GetData()); + _currentGenerationState = GenerationState.Done;; + + EmitSignal("WorldGenerated"); } - private void GenerateSimpleMap() - { - Heightmap = new Image(); - Heightmap.Create((int)Size, (int)Size, false, Image.Format.Rf); - Heightmap.Lock(); - - foreach (int coord_x in Enumerable.Range(-(int)Size / 2, (int)Size)) - { - foreach (int coord_y in Enumerable.Range(-(int)Size / 2, (int)Size)) - { - SetHeightAtOffset(new Vector2(coord_x, coord_y), 5f); - } - } - } - - + private void GenerateNoiseMap() { Heightmap = new Image(); - Heightmap.Create((int)Size, (int)Size, false, Image.Format.Rgba8); + Heightmap.Create(Size, Size, false, Image.Format.Rgba8); OpenSimplexNoise noiseGenerator = new OpenSimplexNoise(); @@ -134,54 +114,38 @@ public class TileWorld : Spatial noiseGenerator.Lacunarity = 4; ImageTexture heightmapTexture = new ImageTexture(); - // heightmapTexture.CreateFromImage(noiseGenerator.GetImage((int)Size, (int)Size)); heightmapTexture.CreateFromImage(noiseGenerator.GetSeamlessImage((int) Size)); heightmapTexture.Flags = 0; _heightmapOffscreenTextureRect.Texture = heightmapTexture; Heightmap.CopyFrom(_heightmapOffscreenViewport.GetTexture().GetData()); - CurrentGenerationState = GenerationState.Heightmap; + _currentGenerationState = GenerationState.Heightmap; } public override void _Process(float delta) { - if (CurrentGenerationState == GenerationState.Heightmap) + if (_currentGenerationState == GenerationState.Heightmap) { - CurrentGenerationState = GenerationState.Color; + _currentGenerationState = GenerationState.Color; ImageTexture imageTexture = new ImageTexture(); imageTexture.CreateFromImage(Heightmap); imageTexture.Flags = 0; _worldOffscreenTextureRect.Texture = imageTexture; } - else if (CurrentGenerationState == GenerationState.Color) + else if (_currentGenerationState == GenerationState.Color) { Colormap = new Image(); - Colormap.Create((int)Size, (int)Size, false, Image.Format.Rgba8); - + Colormap.Create(Size, Size, false, Image.Format.Rgba8); Colormap.CopyFrom(_worldOffscreenViewport.GetTexture().GetData()); Heightmap.Lock(); - CurrentGenerationState = GenerationState.Done; - + _currentGenerationState = GenerationState.Done; + EmitSignal("WorldGenerated"); } } - public void ApplyHeightmap(Image heightmap) - { - foreach (int coord_x in Enumerable.Range(-(int)Size / 2, (int)Size)) - { - foreach (int coord_y in Enumerable.Range(-(int)Size / 2, (int)Size)) - { - Vector2 textureCoord = OffsetToTextureCoord(new Vector2(coord_x, coord_y)); - float height = heightmap.GetPixel((int)textureCoord.x, (int)textureCoord.y).r; - SetHeightAtOffset(new Vector2(coord_x, coord_y), height); - } - } - } - - public bool IsOffsetCoordValid(Vector2 offsetCoord) { return ((int)Math.Clamp(offsetCoord.x, -Size / 2, Size / 2 - 1) == (int)offsetCoord.x @@ -202,17 +166,9 @@ public class TileWorld : Spatial public Vector2 OffsetToTextureCoord(Vector2 offsetCoord) { - Vector2 textureCoord = (offsetCoord - Vector2.One * (Mathf.Floor(Size / 2) + 1)) % (Vector2.One * Size); - if (textureCoord[0] < 0) - { - textureCoord[0] += Size; - } - - if (textureCoord[1] < 0) - { - textureCoord[1] += Size; - } - +// Vector2 textureCoord = (offsetCoord - Vector2.One * (Mathf.Floor(Size / 2))) % (Vector2.One * Size); + Vector2 mapSize = Vector2.One * Size; + Vector2 textureCoord = (offsetCoord + mapSize / 2).PosMod(mapSize); return textureCoord; } @@ -225,14 +181,20 @@ public class TileWorld : Spatial public float GetHeightAtOffset(Vector2 offsetCoord) { - if (CurrentGenerationState != GenerationState.Done) + if (_currentGenerationState != GenerationState.Done) { return 0f; } Vector2 textureCoord = OffsetToTextureCoord(offsetCoord); - return Heightmap.GetPixel((int)textureCoord.x, (int)(textureCoord.y)).r * HeightScale; + float heightmapHeight = Heightmap.GetPixel((int)textureCoord.x, (int)(textureCoord.y)).r * HeightScale; + +// heightmapHeight = Mathf.Floor(heightmapHeight); +// heightmapHeight = heightmapHeight * 10) +// heightmapHeight = Mathf.Clamp(heightmapHeight, -1f, 5); + + return heightmapHeight; } diff --git a/scenes/tests/FragmentShaderHexTile.tres b/scenes/tests/FragmentShaderHexTile.tres index c2270c1..b2b935a 100644 --- a/scenes/tests/FragmentShaderHexTile.tres +++ b/scenes/tests/FragmentShaderHexTile.tres @@ -35,7 +35,7 @@ ivec2 axial_to_offset(vec2 axial) { ivec3 cubeCoords = round_cube_coords(axial_to_cube(axial)); int x = cubeCoords.x; int y = cubeCoords.y; - int off_y = y + (x - (x % 2)) / 2; + int off_y = y + (x - (x & 1)) / 2; return ivec2(x, off_y); } @@ -72,20 +72,23 @@ vec3 vertex_world_to_color(vec3 vertex_world) { vec3 vertex_world_to_hex_center(vec3 vertex_world) { vec3 axial_coords_f = vec3(_HexAffineInverse * vertex_world.xz, 0); -// Output:0 ivec2 offset_coord_f = axial_to_offset(axial_coords_f.xy); + vec2 mod_result = mod (vec2(offset_coord_f), vec2(2.0)); vec3 result_color = vec3(0); - if (offset_coord_f.x % 2 == 0) { + if (mod_result.x == 0.0) { result_color.r = 1.0; } - if (offset_coord_f.y % 2 == 0) { + if (mod_result.y == 0.0) { result_color.b = 1.0; } - return result_color; + result_color = vec3(float(offset_coord_f.x), float(offset_coord_f.y), 0.); + result_color.x = result_color.y; + + return mod(result_color / 4.0, vec3(1.0)); } ivec2 cube_to_axial(ivec3 hex_i) { @@ -125,7 +128,7 @@ vec3 vertex_world_to_hex_center_amid (vec3 vertex_world) { void fragment() { ALBEDO = vertex_world_to_hex_center(vertex_coord); - ALBEDO = vertex_world_to_hex_center_amid(vertex_coord); +// ALBEDO = vertex_world_to_hex_center_amid(vertex_coord); } void light() { diff --git a/scenes/tests/FragmentShaderHexTile.tscn b/scenes/tests/FragmentShaderHexTile.tscn index 07ffcc4..1d97a7b 100644 --- a/scenes/tests/FragmentShaderHexTile.tscn +++ b/scenes/tests/FragmentShaderHexTile.tscn @@ -1,8 +1,12 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://scenes/tests/FragmentShaderHexTile.tres" type="Shader" id=1] +[sub_resource type="ShaderMaterial" id=5] +shader = ExtResource( 1 ) + [sub_resource type="PlaneMesh" id=1] +material = SubResource( 5 ) [sub_resource type="ShaderMaterial" id=2] shader = ExtResource( 1 ) @@ -12,7 +16,6 @@ radius = 0.1 height = 0.2 [sub_resource type="SpatialMaterial" id=4] -albedo_color = Color( 1, 0, 0, 1 ) [node name="Spatial" type="Spatial"] @@ -20,7 +23,7 @@ albedo_color = Color( 1, 0, 0, 1 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 3.34454, 0 ) [node name="MeshInstance" type="MeshInstance" parent="."] -transform = Transform( 50, 0, 0, 0, 50, 0, 0, 0, 50, -0.00971127, 0, -0.00242263 ) +transform = Transform( 50, 0, 0, 0, 50, 0, 0, 0, 50, -0.00971127, 3.65894, -0.00242263 ) mesh = SubResource( 1 ) material/0 = SubResource( 2 ) @@ -34,11 +37,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.08117 ) visible = false mesh = SubResource( 1 ) -[node name="MeshInstance4" type="MeshInstance" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.07165, 0, 2.08117 ) -visible = false -mesh = SubResource( 1 ) - [node name="Center" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.60949, 0 ) mesh = SubResource( 3 ) material/0 = SubResource( 4 ) diff --git a/ui/WorldGeneratorUI.gd b/ui/WorldGeneratorUI.gd new file mode 100644 index 0000000..faa2c86 --- /dev/null +++ b/ui/WorldGeneratorUI.gd @@ -0,0 +1,14 @@ +extends VBoxContainer + +var world_size_label = null +var world_size_slider = null + +# Called when the node enters the scene tree for the first time. +func _ready(): + world_size_label = find_node("WorldSizeLabel") + world_size_slider = find_node("WorldSizeSlider"); + + world_size_slider.value = 4 + +func _on_HSlider_value_changed(value): + world_size_label.text = str(value)