AI Asset Generation Overview
The most distinctive feature of Medieval Deck is its AI-powered asset generation pipeline. Instead of relying on manually created art, the game uses Stable Diffusion XL (SDXL), a powerful text-to-image model, to generate all visual assets. This includes backgrounds, hero sprites, and even UI elements.
This automated approach ensures a cohesive and unique visual style that aligns perfectly with the game's gothic medieval theme.
Key Components
The pipeline is located in the /gen_assets
directory and is composed of three main parts:
- Art Direction (
art_direction.py
): A module that translates high-level artistic goals into detailed, structured text prompts for the AI model. It acts as the creative director for the AI. - Asset Generator (
generate_backgrounds.py
): The core engine of the pipeline. It takes prompts from the Art Direction module, interfaces with the SDXL model via thediffusers
library, generates images, applies post-processing, and caches the results. - RTX 5070 Optimizer (
rtx_optimizer.py
): An advanced performance layer specifically designed to optimize the generation process for high-end NVIDIA GPUs (like the RTX 5070). It manages VRAM, enables hardware-specific accelerations, and ensures maximum quality with reasonable performance.
The Workflow
- A game screen (e.g.,
SelectionScreen
) needs an asset. - It calls a method on the
AssetGenerator
class (e.g.,generate_hero_background('knight')
). - The
AssetGenerator
first checks if the asset has already been generated and cached on disk. - If not, it requests a detailed prompt from the
ArtDirection
module. - It configures the generation parameters using the
RTX5070Optimizer
. - It runs the SDXL pipeline to generate the raw image.
- It applies post-processing effects (like sharpening and contrast enhancement) to match the game's aesthetic.
- It saves the final image to the
/assets
directory and returns the file path.
This entire process is decoupled from the main game logic, meaning the game simply requests and loads images, unaware of the complex generation process behind the scenes.