# Texture Generation

### Overview

Texture Studio & Material Converter includes **automatic texture generation** for missing texture maps during or after material conversion. This solves the common problem where certain pipelines require textures that don't exist in the source material.

<figure><img src="https://2080991436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAxFe6yMczyZLonx7Gw3A%2Fuploads%2FEqmzMwBDLF2y3BOwRtT7%2Fimage.png?alt=media&#x26;token=7e854716-5814-49df-8a87-b7a440894634" alt=""><figcaption></figcaption></figure>

### Access

The texture generation options are in the **Texture Studio & Material Converter** window under:

* **Texture Generation Options** (foldout section)

For custom shaders, configure property name aliases in **Project Settings → Texture Studio** so generated maps auto-assign to your shader's texture slots. Use presets (URP Lit, HDRP Lit) as a starting point.

### Two Modes of Operation

#### 1. **During Conversion** (Automatic)

Enable "Auto-Generate Missing Textures" before clicking "Convert Shaders"

* Textures are generated automatically as materials are converted
* Only missing textures are generated
* Seamless integration with conversion workflow

#### 2. **After Conversion** (Standalone)

Use the "Generate Textures for Existing Materials" button

* Works on already-converted materials
* No shader conversion happens
* Perfect for materials that were converted earlier

### Supported Generated Textures

#### ✅ Normal Map

**Generated from:** Base texture luminance\
**Settings:** Strength (1-10) controls bump intensity

#### ✅ Metallic/Smoothness/Mask Map (pipeline-aware)

**Generated from:** Uniform values\
**Settings:** Metallic Value, Smoothness Value\
**Format:**

* **HDRP:** R=Metallic, G=AO (uses source AO if available, else base luminance), B=Detail/Coat, A=Smoothness
* **URP/Built-in:** RGB=Metallic grayscale, A=Smoothness

#### ✅ Height Map (HDRP optional)

**Generated from:** Base texture grayscale\
**Settings:** Height Scale

#### ✅ Occlusion Map (HDRP optional)

**Generated from:** Base texture darkening\
**Settings:** AO Strength

#### ✅ Emission Map (HDRP optional)

**Generated from:** Base texture chroma + luminance accents\
**Settings:** Color, Coverage, Mask Only, Edge Feather (feather visible only when Mask Only is on)

#### ✅ Coat Mask (HDRP optional)

**Generated from:** Base texture luminance; coverage + feather\
**Behavior:** Saves a separate coat mask texture and also writes coat into Mask B when present; sets `_CoatMask` float to 1.

#### ✅ Bent Normal Map (HDRP optional)

**Generated from:** Base gradients, bent toward occlusion (uses AO if present)\
**Settings:** Bent Normal Strength

#### ✅ Detail Map (HDRP optional)

**Generated from:** DoG-style high-pass of base texture to keep meaningful micro detail\
**Settings:** Detail Strength

### Quick Workflow Examples

#### Example 1: Converting Built-in to HDRP with Auto-Generation

```
1. Select Built-in materials
2. Source: Built-in, Target: HDRP
3. Enable "Auto-Generate Missing Textures"
4. Check: Normal Map, Metallic Map, Occlusion Map
5. Adjust settings (Normal Strength = 5, etc.)
6. Click "Convert Shaders"
7. ✓ Materials converted AND textures generated!
```

#### Example 2: Adding Textures to Already-Converted Materials

```
Scenario: You converted URP materials to HDRP yesterday, 
but now realize they need normal maps.

1. Select those materials
2. Enable "Auto-Generate Missing Textures"
3. Check only "Normal Map"
4. Set Normal Strength = 7
5. Click "Generate Textures for Existing Materials"
6. ✓ Normal maps created and assigned!
```

#### Example 3: Selective Texture Generation

```
You only need Metallic and Height maps:

1. Select materials
2. Enable "Auto-Generate Missing Textures"
3. ☑ Metallic/Smoothness Map
4. ☑ Height Map
5. ☐ Normal Map (unchecked)
6. ☐ Occlusion Map (unchecked)
7. ☐ Emission Map (unchecked)
 8. (HDRP) Optional: Coat Mask, Bent Normal, Detail (enable only if your shader uses them)
9. Generate
```

### Generated File Naming

Textures are saved in the **same folder as the material** with names like:

```
MaterialName_Normal_Generated.png
MaterialName_Metallic_Generated.png
MaterialName_Height_Generated.png
MaterialName_Occlusion_Generated.png
MaterialName_Emission_Generated.png
MaterialName_CoatMask_Generated.png
MaterialName_BentNormal_Generated.png
MaterialName_Detail_Generated.png
```

### Texture Import Settings

Generated textures are automatically configured:

* **Normal Maps**: Set to "Normal Map" type
* **Emission Maps**: sRGB color space enabled
* **Other Maps**: Linear color space

### When Textures Are NOT Generated

Textures are skipped if:

* ✅ Material already has that texture assigned
* ✅ Material's shader doesn't support that texture property
* ❌ No base texture found (required for generation)
* ❌ Base texture is not readable (tool will try to make it readable)

### Settings Explained

#### Normal Map Strength (1-10)

* **1-3**: Subtle bumps, good for smooth surfaces
* **4-6**: Medium bumps, good for most materials (default: 5)
* **7-10**: Strong bumps, good for rough surfaces

#### Metallic Value (0-1)

* **0.0**: Non-metallic (default for most materials)
* **0.5**: Semi-metallic
* **1.0**: Fully metallic (mirrors, chrome)

#### Smoothness Value (0-1)

* **0.0**: Rough, matte surface
* **0.5**: Medium smoothness (default)
* **1.0**: Very smooth, glossy surface

#### Height Scale (0.01-0.2)

* **0.01-0.03**: Subtle parallax
* **0.05**: Medium parallax (default)
* **0.1-0.2**: Strong parallax (may look unrealistic)

#### AO Strength (0-1)

* **0.0**: No occlusion
* **0.5**: Moderate darkening
* **1.0**: Strong ambient occlusion (default)

### Best Practices

#### ✅ DO:

* Generate textures during initial conversion for consistency
* Test on 1-2 materials first to verify settings
* Adjust strength values based on your needs
* Use standalone generation for post-conversion fixes
* Keep base textures at good resolution (512+ recommended)
* For HDRP, treat Height/Occlusion/Emission/Coat/Bent/Detail as optional utilities—enable only when your shader actually uses them

#### ❌ DON'T:

* Generate all textures if you don't need them (bloats project)
* Use very high normal strength on smooth surfaces
* Generate emission maps unless specifically needed
* Rely solely on generated textures for hero assets (hand-craft those)
* Generate for materials without base textures

### Limitations

#### What Generated Textures CAN'T Do:

* **Normal Maps**: Won't be as detailed as properly authored maps
* **Metallic Maps**: Uniform values, no per-pixel variation
* **Height Maps**: Based on color, not actual geometry
* **Occlusion Maps**: Approximation, not true ambient occlusion
* **Emission Maps**: Solid color only, no patterns

#### Quality Expectations:

* ✅ **Good for**: Prototyping, background objects, testing
* ⚠️ **Acceptable for**: Mid-range assets with tweaking
* ❌ **Not suitable for**: Hero objects, close-up views, final art

### Troubleshooting

#### "No base texture found"

**Cause:** Material doesn't have \_MainTex, \_BaseMap, or \_BaseColorMap\
**Solution:** Assign a base texture to the material first

#### "Could not make texture readable"

**Cause:** Base texture import settings prevent reading\
**Solution:** Manually enable "Read/Write" in texture import settings

#### "Generated textures look wrong"

**Cause:** Settings don't match material type\
**Solution:** Adjust strength/value sliders and regenerate

#### "Textures not assigned after generation"

**Cause:** Shader doesn't have matching property names\
**Solution:** Manually assign textures in material inspector

#### "Performance impact from generation"

**Cause:** Generating textures for many large materials\
**Solution:** Process in smaller batches or reduce source texture resolution

### Advanced: Technical Details

#### Generation Algorithms

**Normal Map:**

```
1. Convert base texture to grayscale
2. Apply Sobel operator for edge detection
3. Calculate surface gradients (dx, dy)
4. Construct normal vectors from gradients
5. Normalize and encode to 0-1 range
```

**Metallic/Smoothness:**

```
HDRP Format:
1. Create RGBA texture
2. R = Metallic value (uniform)
3. G = AO (1.0 default)
4. B = Detail (0.0)
5. A = Smoothness value (uniform)

URP/Built-in Format:
1. Create RGBA texture
2. R = Metallic value (grayscale)
3. G = Metallic value (grayscale)
4. B = Metallic value (grayscale)
5. A = Smoothness value (uniform)

Note: Tool auto-detects shader pipeline and uses correct format
```

**Height Map:**

```
1. Convert base texture to grayscale
2. Use luminance as height value
3. Brighter = Higher, Darker = Lower
```

**Occlusion Map:**

```
1. Convert base texture to grayscale
2. Lerp between white (1.0) and grayscale based on strength
3. Darker areas get more occlusion
```

**Emission Map:**

```
1. Build chroma + luminance histograms
2. Find cutoffs by coverage; detect colorful or bright accents
3. Mask-only option converts to grayscale; optional feather (only shown when Mask Only is on)
```

**Coat Mask (HDRP):**

```
1. Derive coat coverage from luminance with feather
2. Save separate coat mask texture
3. Also write coat into Mask B when present; set _CoatMask to 1
```

**Bent Normal (HDRP):**

```
1. Compute base gradients as normals
2. Bend toward occlusion (uses AO if available)
3. Encode to normal map format
```

**Detail Map (HDRP):**

```
1. Compute Difference-of-Gaussians (small vs large radius)
2. Noise gate and contrast curve to keep meaningful micro detail
3. Store as grayscale detail map
```

#### File Format

* All textures saved as **PNG** (lossless)
* RGBA32 format for most textures
* R8 format for height/occlusion (single channel)

### Comparison: Hand-Authored vs Generated

| Aspect          | Hand-Authored | Generated   |
| --------------- | ------------- | ----------- |
| **Quality**     | ⭐⭐⭐⭐⭐         | ⭐⭐⭐         |
| **Speed**       | Hours         | Seconds     |
| **Detail**      | High          | Medium      |
| **Cost**        | Artist time   | Free        |
| **Consistency** | Varies        | Consistent  |
| **Best For**    | Final art     | Prototyping |

### Integration with Conversion

The texture generation seamlessly integrates with shader conversion:

```
Conversion Flow:
1. Select materials
2. Configure conversion (Source → Target pipeline)
3. Enable texture generation
4. Select which maps to generate
5. Click "Convert Shaders"

What Happens:
1. Material shader converted
2. Properties mapped
3. Missing textures detected
4. Textures generated from base texture
5. Textures saved to disk
6. Textures imported with correct settings
7. Textures assigned to material
8. Material saved

Result: Fully converted material with all necessary textures!
```

### FAQ

**Q: Can I regenerate textures if I don't like them?**\
A: Yes! Just delete the generated texture files and run generation again with different settings.

**Q: Will this work if I have no textures at all?**\
A: No, you need at least a base/albedo texture for generation to work.

**Q: Can I edit generated textures?**\
A: Yes! They're standard PNG files. Edit in Photoshop/GIMP and reimport.

**Q: Does this slow down conversion?**\
A: Slightly. Adds \~0.5-2 seconds per material depending on texture resolution.

**Q: Can I use custom generation algorithms?**\
A: Yes! The code lives in the Texture Studio editor scripts (see `Assets/Arawn/TextureStudio/Editor/`) under the texture generation region.

**Q: What if generated textures don't match my art style?**\
A: Use them as placeholders, then replace with proper authored textures later.

***

**Pro Tip:** Generate textures during initial conversion for consistency, then fine-tune individual materials as needed!
