2.9 KiB
Godot 4.3 does not include a built-in automated texture atlas generator for runtime use, but provides tools and workflows for manual atlas creation and optimization:
Manual Atlas Creation
-
AtlasTexture Resource
Use theAtlasTextureclass to define sub-regions of a larger texture manually[1][4]. This involves:- Setting the
atlasproperty to the base texture - Defining the
region(coordinates and size) for each sub-texture - Adjusting
marginandfilter_clipto prevent bleeding[4]
- Setting the
-
TileSetAtlasSource
For tilemaps, useTileSetAtlasSourceto define grid-based atlases:- Configure
texture,margins, andseparationproperties[3] - Expose tiles via
create_tile()with grid coordinates[3]
- Configure
Runtime Atlas Generation
To dynamically pack textures at runtime:
- Use
Imageclass to create a blank texture - Copy pixels from individual textures using
get_pixel()/set_pixel()with calculated offsets[5] - Convert the final
Imageto aTexture2Dfor rendering
# Example pseudocode for runtime atlas generation
var atlas_image = Image.create(atlas_width, atlas_height, false, Image.FORMAT_RGBA8)
for texture in textures:
var img = texture.get_image()
atlas_image.blit_rect(img, img.get_used_rect(), offset)
var atlas_texture = ImageTexture.create_from_image(atlas_image)
Editor Workflow
-
Static Atlas Preparation
Use external tools (TexturePacker, Kenney NL) to create pre-packed atlases, then import them asTexture2Dresources. -
Texture Atlas Importer
Godot'sResourceImporterTextureAtlascan split a single texture into multipleAtlasTextureresources during import[6], but requires manually created source images.
Performance Considerations
While texture atlases reduce draw calls, modern hardware often minimizes their impact[2]. Prioritize optimization in areas like:
- 2D lighting
- Particle systems
- Overdraw from transparent textures[2]
For most use cases, manually prepared atlases combined with AtlasTexture or TileSetAtlasSource provide sufficient optimization without runtime generation[1][3][6].
Citations: [1] https://docs.godotengine.org/de/stable/classes/class_atlastexture.html [2] https://www.reddit.com/r/godot/comments/1215i6i/does_godot_automatically_make_texture_atlases/ [3] https://docs.godotengine.org/en/4.3/classes/class_tilesetatlassource.html [4] https://docs.godotengine.org/en/4.3/classes/class_atlastexture.html [5] https://forum.godotengine.org/t/how-to-generate-a-texture-atlas-from-multiple-images/64985 [6] https://docs.godotengine.org/en/4.3/classes/class_resourceimportertextureatlas.html [7] https://github.com/godotengine/godot/issues/92671 [8] https://www.youtube.com/watch?v=oEBUXW674dc
Answer from Perplexity: https://www.perplexity.ai/search/godot-4-3-texture-atlas-genera-40o0HDS7TciDehf23JYCew?utm_source=copy_output