Terrain to AI texture#
A complete procedural terrain -> diffusion model -> back onto the mesh chain. A noise height field is eroded and classified into five material layers; those layers become regional prompts and the height becomes a ControlNet depth image; SDXL paints a top-down texture that lines up pixel for pixel with the height field; the texture is put back into the terrain and turned into a coloured mesh.
Load it#
Drag example_workflows/pcg_terrain_to_ai_texture.json onto the ComfyUI canvas.
Requirements
| What | Default in the workflow | Notes |
|---|---|---|
| SDXL checkpoint | SDXL\RealVisXL_V4.0.safetensors | Pick your own SDXL checkpoint in CheckpointLoaderSimple. |
| SDXL ControlNet | SDXL\controlnet-union-sdxl-1_promax.safetensors | A union or a depth ControlNet for SDXL both work. SetUnionControlNetType is set to depth. |
| Custom nodes | none besides comfyui_pcg | The AI part uses ComfyUI core nodes only: CheckpointLoaderSimple, CLIPTextEncode, ControlNetLoader, SetUnionControlNetType, ControlNetApplyAdvanced, EmptyLatentImage, KSampler, VAEDecode, SaveImage, PreviewImage. |
The erosion runs at 512 x 512; the terrain is then upsampled to 1024 x 1024 (with a fine relief on top), the size the image is generated at, so masks, control image and texture line up pixel for pixel.
Step by step#
1. Terrain (left two columns)
- COP Noise (PCG): 512 x 512 simplex noise, standard fractal, frequency 3, 6 octaves, amplitude 0.06, seed 7.
- COP HeightField Stream Power Erosion (PCG): stream-power erosion (60 iterations,
rho8routing) cuts river valleys. - COP Erosion Filter (PCG): the erosion filter (amplitude 0.003, wavelength 40).
- COP HeightField Thermal Erosion (PCG): thermal erosion (talus angle 38, 12 iterations).
- COP HeightField Hydraulic Erosion (PCG): hydraulic erosion: gullies plus alluvium, accumulated into the
debrislayer. - COP Flow Accumulation (PCG): flow accumulation (
d8) for rivers and lakes. - COP HeightField Splat Map (PCG): splits the terrain into grass / sediment / rock / snow / water; the five layers sum to 1 everywhere (rock angle 42, snow line 0.78).
2. Prompts and control image
- Regional Prompt from COP (PCG) turns the splat layers into regional conditioning: a base prompt plus one line per layer (
layer: prompt); later lines take priority. Itspreviewoutput shows the regions. - Control Image (PCG) in
heightmode outputs a top-down depth map (high = white) for the ControlNet.
3. Generation
- SDXL with the union ControlNet in depth mode (strength 0.85, ending at 85% of the steps), a negative prompt against perspective, sky, text and similar, and KSampler (seed 7, 28 steps, CFG 5,
dpmpp_2m/karras) produce a top-down texture aligned with the height field. Save Image writes it aspcg/terrain_albedo.
4. Back to the mesh
- COP Import (PCG) reads the generated image back into a COPIMAGE (layer
albedo). - COP Composite (PCG) (mode
replace) puts it into the terrain image'salbedolayer. - COP HeightField to Mesh (PCG) (step 2, attributes
Cd=albedo) builds the mesh with the texture as point colour. - Geometry Preview (PCG) in the Studio look shows the textured terrain, and Export Mesh (PCG) writes
pcg/terrain_ai(glb) to the output folder.
Worth tweaking#
| Node | Parameter | Effect |
|---|---|---|
| COP Noise | rand_seed, frequency, amplitude | A different terrain. |
| Splat Map | rock_angle, snow_line | How much rock and snow the prompts get. |
| Regional Prompt | base_prompt, regions | The look of each material. |
ControlNetApplyAdvanced | strength, end_percent | How strictly the image follows the height. |
| KSampler | seed | A different texture for the same terrain. |
See also#
- Image to terrain: the opposite direction.
- Terrain maps: the same terrain chain without AI.
- Images (COP): COPIMAGE, layers, import and export.
- Example index.