menu_bookDocumentation
Texture Generators - s&box Editor Documentation
Texture Generators
Create procedural textures in code. Generate textures from shapes, gradients, text, or any algorithm.
Creating a Generator
Inherit from TextureGenerator:
CSHARP
[Title( "Circle" )]
[Icon( "palette" )]
public class CircleTextureGenerator : TextureGenerator
{
[KeyProperty]
public Color Color { get; set; } = Color.Magenta;
public Color BackgroundColor { get; set; } = Color.White;
[Hide, JsonIgnore]
public override bool CacheToDisk => true;
protected override ValueTask<Texture> CreateTexture(
Options options,
CancellationToken ct )
{
var bitmap = new Bitmap( 128, 128 );
bitmap.Clear( BackgroundColor );
bitmap.SetFill( Color );
bitmap.DrawCircle( 64, 64, 40 );
return ValueTask.FromResult( bitmap.ToTexture() );
}
}Properties
Mark properties with attributes:
- [KeyProperty] — Main property shown in UI
- [Range] — Numeric slider
- [Color] — Color picker
Cache To Disk
CSHARP
public override bool CacheToDisk => true;Cached textures save to disk and persist. Disable for runtime-only generators.
Code Location
Put texture generators in:
- Game code — If needed at runtime
- Editor project — If only for editor use
Usage
- Create texture in Asset Browser
- Select your generator
- Adjust properties
- Use in materials
Was this helpful?