Skip to content

Instantly share code, notes, and snippets.

@ChrisPritchard
Created October 7, 2025 00:18
Show Gist options
  • Select an option

  • Save ChrisPritchard/54683caa1460f47856981669dbb0e028 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisPritchard/54683caa1460f47856981669dbb0e028 to your computer and use it in GitHub Desktop.
A Godot script that can generate a sprite atlas from 3D noise, to reduce runtime computation needs
using Godot;
[Tool]
public partial class NoiseAtlasGenerator : Node
{
[Export]
public NoiseTexture3D NoiseGenerator { get; set; }
[Export(PropertyHint.SaveFile, hintString: "*.png")]
public string SavePath { get; set; }
[Export(PropertyHint.ToolButton, hintString: "Generate")]
public Callable Generate { get => Callable.From(GenerateTexture); set { } }
private void GenerateTexture()
{
if (NoiseGenerator == null || string.IsNullOrEmpty(SavePath))
{
GD.PrintErr($"{nameof(NoiseGenerator)} and {nameof(SavePath)} must be set");
return;
}
var images = NoiseGenerator.GetData();
var layers = NoiseGenerator.Depth;
var frame_width = NoiseGenerator.Width;
var frame_height = NoiseGenerator.Height;
var atlas_dim = (int)Mathf.Ceil(Mathf.Sqrt(layers));
GD.Print("started generating atlas");
var atlas = Image.CreateEmpty(frame_width * atlas_dim, frame_height * atlas_dim, false, Image.Format.Rgb8);
for (var i = 0; i < atlas_dim; i++)
for (var j = 0; j < atlas_dim; j++)
{
var layer = i * atlas_dim + j;
if (layer >= layers)
continue;
var pos = new Vector2I(j * frame_width, i * frame_height);
var image = images[layer];
for (var x = 0; x < frame_width; x++)
for (var y = 0; y < frame_height; y++)
{
var noise_val = image.GetPixel(x, y);
atlas.SetPixel(pos.X + x, pos.Y + y, noise_val);
}
}
atlas.SavePng(SavePath);
GD.Print("finished");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment