Texture Generation

With texture generation you produce a tileable wall, floor, path, staircase or roof material from a small set of models. One layout gives an albedo map, a lit albedo map, a normal map and an ambient occlusion map at the same time. The result is a normal Unity material.

A texture definition is the asset that drives the process. PolyBash arranges its block prefabs into a layout, renders that layout through an orthographic capture, and writes one image per capture type. The process creates no scene object.

This page explains the four texture definitions and every section of their inspector. The page Surface Variants explains the color variation that a capture applies.

Concepts

  • Texture definition: the asset that holds every setting. It describes the layout, the capture and the output.
  • Block: one instance of a prefab in the layout. A layout contains many blocks.
  • Layout: the arrangement of blocks that PolyBash generates from the placement settings and a random seed.
  • Capture: one render of the layout into one image. Each capture type produces its own image.
  • Preview: a live render into RenderTexture assets. A preview never writes an image file.
  • Finalized textures: the PNG files that PolyBash writes when you capture to disk.

Create a texture definition

  1. In the Project window, select the folder that must contain the asset.
  2. Select Assets → Create → Snowtop → PolyBash, and then select one texture definition.
  3. Name the asset.
Asset Menu entry Layout
Wall texture definition Wall Texture Definition Rows of blocks that fill a width and a total height.
Path texture definition Path Texture Definition Rows of blocks that fill a width and a total length.
Stair texture definition Stair Texture Definition Steps that fill a total height and a total depth.
Roof tile texture definition Roof Tile Texture Definition Rows of tiles that hang from the top of each row.

All four texture definitions share the same capture settings, and they differ only in the Layout section. The stair texture definition renders the staircase along its slope. PolyBash rotates the layout by 45 degrees for the capture, so that the treads and the risers fill the image.

Included block prefabs

PolyBash includes the block prefabs of every texture definition. The prefabs are in the folder Assets/Snowtop/PolyBash/Texture Generation/Prefabs, with one subfolder per set.

Folder Content Texture definitions
Blocks-1m-Beveled 9 brick blocks and 9 worn stone blocks, one meter wide. Wall, path and stair texture definitions.
Boards 3 wooden boards, 15 centimeters wide, and 1.25, 2.5 and 5 meters long. Wall and roof tile texture definitions.
RoofTiles-50cm 9 beveled tiles and 9 jagged tiles, 50 centimeters wide. Roof tile texture definition.

Each prefab holds one mesh and one Normal Texture Config component. The component references the normal map beside the prefabs, such as Blocks-1m-Brick_Normal.png. As a result, a Normal capture shows the surface detail of the blocks without any texture from you.

Drag a whole folder into the Prefabs list to add every prefab of one set at the same time.

You can edit the included prefabs. Copy a prefab before you edit it, so that an update of PolyBash does not overwrite your changes. Then add the copy to the Prefabs list.

Included texture definitions

PolyBash includes nine texture definitions of three types in the folder Assets/Snowtop/PolyBash/Texture Definitions. The sample scene uses the textures that these texture definitions produce.

  • Wall texture definitions: WallTextureDefinition, FloorTextureDefinition, TrimTextureDefinition and WoodPathTextureDefinition.
  • Roof tile texture definitions: RoofTileTextureDefinition, RoofTileTextureDefinition2, WoodBlueSidingTextureDefinition and WoodRedSidingTextureDefinition.
  • Stair texture definition: StairTextureDefinition.

Every included texture definition writes its images into the folder Assets/Snowtop/PolyBash Samples/GeneratedTextures. As a result, a capture of an included texture definition replaces the textures of the sample.

To keep the sample unchanged, duplicate the texture definition, and change the Output Folder of the copy. Then select Recreate assets at canonical path in the copy, so that the copy creates its own material.

Workflow

  1. Prepare the block prefabs. Each prefab needs one mesh on its root GameObject, and the section Included block prefabs describes the included prefabs.
  2. Create the texture definition.
  3. Add the prefabs to the Prefabs list in the Layout section.
  4. Configure the row count, the dimensions and the block sizes.
  5. Select Capture Preview, and then inspect each tab of the Preview section.
  6. Add at least one surface variant in the Texture Generation foldout, because the included prefabs carry no material of their own.
  7. Configure the resolution, the padding and the output folder.
  8. Select Capture to Disk.

PolyBash writes the images, imports them, and points the material at them, so you can assign that material to any renderer.

Layout

The Layout section holds the placement settings of the texture definition. These fields control the arrangement of the blocks, and never the capture itself. Every texture definition shares these fields:

Field Description
Prefabs The block templates. PolyBash selects one prefab per block at random. When the list is empty, a capture covers the layout with one surface variant of the Surface Variants list, or shows only the background.
Width The width of the layout along the X axis, in meters.
Min Blocks Per Row The smallest number of blocks in one row.
Max Blocks Per Row The largest number of blocks in one row.
Min Block Width The smallest relative width of one block. PolyBash scales the blocks of each row so that the row fills Width.
Max Block Width The largest relative width of one block. PolyBash scales the blocks of each row so that the row fills Width.
Random Seed The seed of the layout. A different value produces a different arrangement.
Use Center Positioning Positions each block at its center. Clear this checkbox for prefabs with a corner pivot.

The wall texture definition and the path texture definition add these fields:

Field Description
Row Count The number of rows.
Total Height The height of the wall, or the length of the path, in meters.
Min Next Row Offset The smallest horizontal shift between two rows, in meters.
Max Next Row Offset The largest horizontal shift between two rows, in meters.

The stair texture definition adds these fields:

Field Description
Step Count The number of steps.
Total Height The height of the staircase, in meters.
Total Depth The depth of the staircase, in meters.
Min Next Step Offset The smallest horizontal shift between two steps, in meters.
Max Next Step Offset The largest horizontal shift between two steps, in meters.

The roof tile texture definition adds these fields:

Field Description
Row Count The number of tile rows.
Total Height The height of the roof layout, in meters. The row pitch is the height divided by the row count.
Tile Tilt The tilt of each tile about the X axis, in degrees. A positive value moves the lower edge of each tile toward the viewer, and the upper edge away from the viewer.
Min Tile Height The smallest height of one tile, in meters.
Max Tile Height The largest height of one tile, in meters.
Min Tile Depth The smallest thickness of one tile, in meters.
Max Tile Depth The largest thickness of one tile, in meters.
Min Next Row Offset The smallest horizontal shift between two rows, in meters.
Max Next Row Offset The largest horizontal shift between two rows, in meters.

Row offsets accumulate with alternating signs, and PolyBash wraps each row at the edge of the layout, so that the result still tiles horizontally. Each tile of the roof texture definition hangs from the top of its row. As a result, a tile that is taller than the row pitch covers the row below.

Texture Generation

The Texture Generation foldout controls the appearance of the captures, and it contains five groups.

Lighting (AlbedoLit)

These fields apply only to the AlbedoLit capture, which bakes one directional light into the color.

Field Description
Light Color The color of the baked light.
Light Intensity The intensity of the baked light.
Indirect Multiplier The multiplier of the ambient color.
Light Rotation The rotation of the baked light, as Euler angles.
Ambient Color The ambient color, which the indirect multiplier scales.
Lit Model Soft Knee blends the ambient color and the baked light by the angle of each face to the light. Additive adds the baked light to the ambient color, so bright faces saturate.

Background Textures

When you assign a background texture, PolyBash draws a quad behind the blocks, and the quad fills the areas where no block covers the image.

Field Description
Albedo Background The texture behind the blocks in the Albedo and AlbedoLit captures.
Albedo Tint The color that tints the albedo background.
Normal Background The texture behind the blocks in the Normal capture.
Normal Strength The strength of the background normal map.

When you assign no background texture, the background color of the Background section fills the area instead.

Normal Capture

Field Description
Include Geometry Folds the facing of each block into the normal map, so that angled faces tilt their patch of the map.
Geometry Strength How much of the facing to fold in. A value of 0 is flat, and 1 is the full tilt. This field is available only when Include Geometry is selected.
Level Block Tilt Ignores the placement rotation of each block. The shape of each block survives, although the layout looks flat overall. This field is available only when Include Geometry is selected.

For a layout that tilts every block in the same direction, such as a roof, select Include Geometry, and then select Level Block Tilt. The roof then looks like a flat surface, and the shape of each tile stays visible.

Ambient Occlusion

Field Description
Capture Occlusion Captures an ambient occlusion image beside the other capture types.
Radius The sampling radius, in meters. A larger value darkens wider gaps.
Intensity The strength multiplier. A value of 1 is the raw sampled occlusion.
Power The exponent on the result. A value above 1 deepens the darkening.
Sample Count The number of samples per pixel, from 4 to 32. More samples produce a smoother result, and a slower capture.
Blur Radius The radius of the depth-aware blur, in pixels. A value of 0 disables the blur.
Use Normal Maps Lets the normal maps of the layout drive the occlusion, and not only the geometry.
Cavity Strength How much the occlusion of the normal maps darkens the result. A value of 0 disables this pass.
Cavity Radius How far the occlusion of the normal maps reaches, in meters.
Wrap Horizontal Samples across the left edge and the right edge, so that the occlusion continues over the seam.
Wrap Vertical Samples across the top edge and the bottom edge, so that the occlusion continues over the seam.
Bake Into Albedo Multiplies the occlusion into the Albedo and AlbedoLit captures before PolyBash saves them.

Use Normal Maps reads the surface directions from the finished normal capture, and not from the geometry. That capture contains the facing of the blocks only when Include Geometry is selected and Geometry Strength is above 0. Otherwise the occlusion treats every face as if it looks straight at the viewer, and only the detail of the normal maps remains.

The wrap options assume that the padding on the matching axis is 0. For a stylized surface that uses no lighting at run time, select Bake Into Albedo.

Surface Variants

This group recolors the blocks. The page Surface Variants documents the list, the entry fields and the Random Seed field below the list.

Resolution

Resolution sets the size of the longer side of the image, from 256 to 4096 pixels. PolyBash derives the shorter side from the proportions of the layout, plus the padding. A wide layout produces a wide image, and no capture distorts the blocks.

Background

Field Description
Albedo Background The color behind the blocks in the Albedo and AlbedoLit captures.
Normal Background The color behind the blocks in the Normal capture. The default value is flat normal blue.

Change Normal Background only when you understand the encoding of a normal map, because the default value describes a flat surface.

Padding

Padding adds empty space around the layout, in meters. The four fields are Padding Left, Padding Right, Padding Top and Padding Bottom.

Keep every padding value at 0 for a texture that must tile. Any padding places a border in the image, and that border breaks the repetition.

Output

Field Description
Output Folder The destination folder, relative to Assets, such as Captures.
Browse... Opens a dialog to select the folder. The folder must be inside Assets.
File Name The base name of every file. Leave it empty to use the name of the texture definition asset.

Material

Field Description
Material The material that this capture drives. PolyBash creates one when the field is empty.
Base Map Source The capture that feeds the base map of the material, either Albedo or Albedo Lit (the AlbedoLit capture). The normal map always comes from the Normal capture.
Preview Points the material at the live preview RenderTextures.
Finalized Points the material at the saved images. This button stays disabled until the images exist.
Recreate assets at canonical path Forgets the current material and RenderTextures, so that the next capture creates new ones from the current File Name and Output Folder.

PolyBash creates the material with the default lit shader of the active render pipeline. You can also assign a material that you already use, and the capture then drives that material instead.

Use Recreate assets at canonical path after you rename the texture definition or change the output folder. The previous files stay on disk, and every reference to them stops receiving updates.

Preview

The Preview section shows the live captures, with one tab per capture type. The Occlusion tab appears after the first occlusion capture.

Field Description
Capture Preview Builds the layout again, and renders every preview image now.

PolyBash captures the preview again after you change a field of the Layout section or of the Texture Generation foldout. After a change in another section, select Capture Preview.

When the Material field holds a material, an edit of a surface variant asset that the texture definition uses also triggers a new capture.

Lifetime of the preview textures

Unity discards the preview RenderTextures when you save the scene, and when the scripts recompile. The preview tabs then appear empty, and a material in Preview mode loses its textures. The loss is never permanent: select Capture Preview, and then select Preview in the Material section, and the live preview returns.

Use the preview while you adjust the settings, and select Capture to Disk after you finish. The saved images are permanent files in your project, and the material then reports the mode Finalized.

Capture Actions

Capture to Disk renders every capture type, writes the images to the output folder, and points the material at them. The Material section then reports the mode Finalized.

Capture Info

This section reports the size and the center of the layout, in meters. Use these values to verify the dimensions before a capture.

The values come from the moment when the inspector opened, and a change of the layout does not update them. To update the values, select another asset, and then select the texture definition again.

Capture types

Every capture of a texture definition renders all of these capture types, although the Occlusion capture type needs Capture Occlusion.

Type Content File suffix
Albedo The colors of the blocks, without lighting. -Albedo
AlbedoLit The colors of the blocks, with the baked light. -AlbedoLit
Normal The surface direction of the blocks, as a tangent-space normal map. -Normal
Occlusion The ambient occlusion of the layout. -AO

The capture shaders Snowtop/PolyBash/Capture/* appear in the Shader menu of every material. PolyBash uses them only to capture, preview and bake textures, so do not assign them to a material.

Generated files

A capture creates these assets, where <name> is the File Name, or the name of the texture definition asset:

Asset Path
Images Assets/<Output Folder>/<name>-Albedo.png, and one file per capture type
Preview RenderTextures Assets/<Output Folder>/<name>-RT-Albedo.renderTexture, and one asset per capture type
Material Assets/<Output Folder>/<name>.mat

PolyBash applies the import settings for you: it imports the normal map as a Normal Map texture, and it disables sRGB on the occlusion map. On the High Definition Render Pipeline, PolyBash writes the occlusion into the green channel of a mask map.

Capture works only in the Unity Editor, so a player build cannot run it.

To assign the material to a spline generator, use the Texture Definition Applier component. The section Texture Definition Applier of the overview page describes that component.

Normal maps of the blocks

The Normal capture combines three contributions, and each one is optional, so a block can use any combination.

  1. The normal maps of the prefab, from a Normal Texture Config component.
  2. The normal that is paired with a surface variant, from the Target Normal field of the asset.
  3. The facing of the block itself, from Include Geometry.

For the first contribution, add a Normal Texture Config component to the root GameObject of the block prefab, next to its Mesh Renderer. The component provides these fields:

Field Description
Normal Maps Up to 8 normal maps. Each block uses one map, which PolyBash selects at random.
Detail Normal Map An optional normal map for extra surface detail.
Detail Tiling The tiling of the detail normal map.
Normal Strength The strength of the selected normal map. A negative value inverts it.
Detail Normal Strength The strength of the detail normal map.
Flip Normal Inverts the X component and the Y component of the result.

Seeds

A texture definition holds two independent seeds:

  • Random Seed in the Layout section controls the arrangement, the normal map of each block, and the random per-block offset of the target texture.
  • Random Seed below the Surface Variants list controls the colors.

You can change the colors without a change of the arrangement. The same pair of seeds always reproduces the same result.

Tileable results

Follow these rules for a texture that repeats without a visible seam:

  1. Keep every padding value at 0.
  2. When you capture occlusion, select Wrap Horizontal and Wrap Vertical.
  3. Verify that each texture of a surface variant uses the wrap mode Repeat.

All four texture definitions wrap their row offsets or step offsets at the layout edge, so the rows still align across the seam.

Troubleshooting

Problem Cause and solution
The preview shows no blocks. The Prefabs list is empty, or every entry is missing, so the capture shows only the background or one surface variant. Add at least one prefab from the folder Assets/Snowtop/PolyBash/Texture Generation/Prefabs.
Only the Normal tab shows the blocks. The prefabs carry no material, like the included prefabs, and the Surface Variants list holds no usable entry. Add a surface variant in the Texture Generation foldout.
The console reports zero bounds. A stair texture definition has a Width, a Total Height and a Total Depth of 0. Enter a value above 0 in each field.
The material shows no textures. No capture ran. Select Capture Preview, and then select Capture to Disk.
The Finalized button stays disabled. The images do not exist yet. Select Capture to Disk.
The normal map has no effect. The prefabs carry no Normal Texture Config component, and the surface variants carry no Target Normal. Add one of them, or select Include Geometry.
The texture does not tile. A padding value is above 0, or a source texture uses a wrap mode other than Repeat. Set the padding to 0, and set the wrap mode to Repeat.
The occlusion map is noisy. The sample count is too low. Raise Sample Count, or raise Blur Radius.
The occlusion ignores the normal maps. Use Normal Maps is cleared, which is the default. Select Use Normal Maps, and keep Cavity Strength above 0.
The occlusion treats angled faces as flat. Use Normal Maps is selected, and Include Geometry is cleared or Geometry Strength is 0. Select Include Geometry, and raise Geometry Strength above 0.
The material and the preview RenderTextures keep the previous name after a rename. The texture definition still references the previous assets. Select Recreate assets at canonical path.
The blocks keep the colors of their prefabs. The Surface Variants list is empty, or no entry is usable. Read the page Surface Variants.
The material appears magenta after a change of render pipeline. PolyBash reuses the existing material, which keeps the lit shader of the previous render pipeline. Delete the generated .mat file, and select Capture to Disk.