# Texture Atlas System

This folder contains the texture assets for the voxel blocks in Surviving Day.

## Structure

```
Textures/
├── Blocks/               # SVG source textures (16x16)
│   ├── grass_top.svg
│   ├── grass_side.svg
│   ├── dirt.svg
│   ├── stone.svg
│   ├── wood.svg
│   ├── wood_top.svg
│   ├── leaves.svg
│   ├── sand.svg
│   └── water.svg
├── Generated/            # Auto-generated files
│   ├── block_atlas.png   # Compiled texture atlas (256x256)
│   ├── block_uvs.json    # UV mapping data
│   └── *.png             # Individual PNG tiles
├── generate_atlas.py     # Atlas generator script
└── README.md             # This file
```

## Adding New Textures

### 1. Create SVG Files

Create 16x16 pixel SVG files in the `Blocks/` folder. Each block type can have:
- **Single texture**: Use one SVG for all faces (e.g., `stone.svg`)
- **Separate faces**: Use different textures for top/bottom/sides (e.g., `grass_top.svg`, `grass_side.svg`)

SVG Guidelines:
- Size: 16x16 pixels
- Simple, pixelated style (voxel aesthetic)
- Use solid colors and patterns
- Avoid complex gradients or effects

### 2. Update `generate_atlas.py`

Add your new block to the `TEXTURE_DEFS` dictionary:

```python
TEXTURE_DEFS = {
    "your_block": {
        "all": "your_texture.svg"  # Same texture for all faces
    },
    # OR for different faces:
    "your_block": {
        "top": "your_top.svg",
        "bottom": "your_bottom.svg",
        "sides": "your_sides.svg"
    }
}
```

### 3. Run the Generator

```bash
cd Textures
py generate_atlas.py
```

This will:
- Convert SVGs to PNGs
- Compile them into a 256x256 texture atlas
- Generate UV mapping data
- Create Godot import files

### 4. Update Code

1. **Add to VoxelType enum** (Scripts/VoxelEngine/VoxelData.cs):
   ```csharp
   public enum VoxelType : byte
   {
       // ...
       YourBlock = 9
   }
   ```

2. **Add texture mapping** (Scripts/VoxelEngine/VoxelData.cs):
   ```csharp
   private static int GetTileIndex(VoxelType type, int faceIndex)
   {
       return type switch
       {
           // ...
           VoxelType.YourBlock => 9, // Tile index from atlas
           _ => 0
       };
   }
   ```

3. **Add biome/generation logic** if needed

4. **Rebuild**: `dotnet build` or press Ctrl+B in Godot

## Texture Atlas

The atlas is a 256x256 PNG file containing a 16x16 grid of textures (256 tiles total).

- **Each tile**: 16x16 pixels
- **UV size**: 1/16 = 0.0625
- **Format**: RGBA PNG
- **Filter**: Nearest (pixel-perfect)

### Current Atlas Layout

| Tile | Block        | Texture       |
|------|--------------|---------------|
| 0    | Grass        | grass_top.svg |
| 1    | Dirt/Grass   | dirt.svg      |
| 2    | Grass        | grass_side.svg|
| 3    | Stone        | stone.svg     |
| 4    | Wood         | wood_top.svg  |
| 5    | Wood         | wood.svg      |
| 6    | Leaves       | leaves.svg    |
| 7    | Sand         | sand.svg      |
| 8    | Water        | water.svg     |
| 9-255 | (Available)  |               |

## Dependencies

### Required
- **Python 3.x**
- **Pillow (PIL)**: `pip install Pillow`

### Optional (for better quality)
- **cairosvg**: `pip install cairosvg` (used for SVG to PNG conversion)
- **Inkscape**: Better quality conversion (auto-detected if installed)

## Troubleshooting

### "Cannot find module 'PIL'"
```bash
pip install Pillow
```

### "Failed to convert SVG"
Install cairosvg or Inkscape:
```bash
pip install cairosvg
```

### Texture appears blurry in-game
Make sure the material is set to `Nearest` filtering (already configured in Chunk.cs)

### UV coordinates wrong
- Check tile index in `GetTileIndex()` matches the atlas layout
- Verify SVGs were converted correctly
- Re-run `generate_atlas.py` to regenerate

### Atlas full (256 tiles)
- Optimize: Combine similar textures
- Rotate textures in code instead of creating separate tiles
- Create a second atlas (requires code changes)

## Tips

1. **Test textures**: View `Generated/block_atlas.png` directly to verify appearance
2. **Pixel art style**: Keep SVGs simple with hard edges for authentic voxel look
3. **Consistency**: Match the color palette and style of existing textures
4. **Performance**: 256x256 atlas is optimal for most GPUs
5. **Reusability**: The same texture can be used by multiple block types

## Credits

Textures created procedurally using SVG for the Surviving Day voxel game.
Generator script inspired by Minecraft's texture atlas system.
