WIP: fix for Colortexture and Heightmap mismatch

WorldChunkRefactoring
Martin Felis 2023-05-13 09:29:54 +02:00
parent d3a36f438b
commit 0bd4924cfe
5 changed files with 27 additions and 15 deletions

View File

@ -45,7 +45,7 @@ void vertex() {
// Output:0
map_coord = origin.xz * 1. / float(TextureSize);
map_coord = axial_to_offset(axial_coords.xy) / float(TextureSize);
map_coord = axial_to_offset(axial_coords.xy) / float(TextureSize) - vec2(0.5);
}
void fragment() {

View File

@ -9,17 +9,17 @@
config_version=4
_global_script_classes=[ {
"base": "Node",
"base": "Reference",
"class": "ClickableComponent",
"language": "GDScript",
"path": "res://components/ClickableComponent.gd"
}, {
"base": "KinematicBody2D",
"base": "Reference",
"class": "CollisionLine",
"language": "GDScript",
"path": "res://utils/CollisionLine.gd"
}, {
"base": "Node",
"base": "Reference",
"class": "ColorComponent",
"language": "GDScript",
"path": "res://components/ColorComponent.gd"
@ -54,7 +54,7 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://utils/SpringDamper.gd"
}, {
"base": "Sprite",
"base": "Reference",
"class": "TintedSpriteComponent",
"language": "GDScript",
"path": "res://components/TintedSpriteComponent.gd"

View File

@ -253,6 +253,7 @@ public class Game : Spatial
_tileMaterial.SetShaderParam("MapAlbedoTexture", new_world_texture);
_tileMaterial.SetShaderParam("TextureSize", (int)_tileWorld.Colormap.GetSize().x);
_streamContainer.SetTileMaterial(_tileMaterial);
_streamContainer.OnWorldGenerated();
//_streamContainer.SetTileMaterial(_tileMaterial);
}
}

View File

@ -235,4 +235,20 @@ public class StreamContainer : Spatial
GD.Print("Hovered on Tile at " + tile.OffsetCoords);
EmitSignal("TileHovered", tile);
}
public void OnWorldGenerated()
{
foreach (Spatial node in _activeTiles.GetChildren())
{
HexTile3D tile = (HexTile3D)node;
if (tile == null)
{
continue;
}
Transform tileTransform = tile.GlobalTransform;
tileTransform.origin.y = _tileWorld.GetHeightAtOffset(tile.OffsetCoords);
tile.GlobalTransform = tileTransform;
}
}
}

View File

@ -14,7 +14,7 @@ public class TileWorld : Spatial
delegate void WorldGenerated();
// public members
public Vector2 Size = new Vector2(100, 100);
public Vector2 Size = new Vector2(10, 10);
public float HeightScale = 2;
public Image Heightmap;
public Image Colormap;
@ -45,7 +45,7 @@ public class TileWorld : Spatial
public void Generate()
{
GenerateSimpleMap();
//GenerateSimpleMap();
// GenerateNoiseMap();
GenerateNoiseColorMap();
@ -103,7 +103,7 @@ public class TileWorld : Spatial
noise_generator.Lacunarity = 4;
ImageTexture imageTexture = new ImageTexture();
Heightmap.Unlock();
//Heightmap.Unlock();
Heightmap = noise_generator.GetSeamlessImage((int)Size.x);
imageTexture.CreateFromImage(Heightmap);
imageTexture.Flags = 0;
@ -113,11 +113,6 @@ public class TileWorld : Spatial
}
private void ApplyHeightMap()
{
}
public bool IsOffsetCoordValid(Vector2 offset_coord)
{
return ((int)Math.Clamp(offset_coord.x, -Size.x / 2, Size.x / 2 - 1) == (int)offset_coord.x