| name | setup-material-texture |
| description | Create and configure URP materials from SDF material definitions or Assimp imports. Use when: setting up base color, emission, specular, or normal maps, switching transparency modes, debugging texture loading, converting materials to SpeedTree shader, customizing URP material properties. |
Setup Material and Texture Pipeline
Reference for creating and configuring Universal Render Pipeline (URP) materials in CLOiSim, covering both SDF-defined materials and Assimp-imported materials.
When to Use
- Creating a new URP material from SDF
<material> definitions
- Debugging missing or incorrect textures on imported models
- Adding transparency or emission to materials
- Converting vegetation materials to SpeedTree shader
- Understanding the Assimp material property → Unity material mapping
- Customizing the texture search path resolution
Architecture
Two material creation paths converge on the same URP property setters:
Path 1: SDF Material Path 2: Assimp Material
├─ <material> ├─ Assimp.Material properties
│ ├─ <diffuse> │ ├─ ColorDiffuse
│ ├─ <emissive> │ ├─ ColorEmissive
│ ├─ <specular> │ ├─ TextureDiffuse
│ └─ <normal_map> │ └─ TextureNormal
│ │
└─ SDF2Unity.Material.*() └─ sceneMaterials.ToUnity()
│ │
▼ ▼
CreateMaterial() ← base material creation
│
▼
Set*() extension methods
├─ SetBaseColor()
├─ SetEmission()
├─ SetSpecular()
├─ SetNormalMap()
├─ SetTransparent() / SetOpaque()
└─ ConvertToSpeedTree()
Base Material Creation
All materials start from SDF2Unity.CreateMaterial():
public static Material CreateMaterial(in string materialName = "")
Property Setters
Base Color
public static void SetBaseColor(this Material target, Color color)
Transparency
public static void SetTransparent(this Material target)
public static void SetOpaque(this Material target)
Emission
public static void SetEmission(this Material target, Color color)
Specular
public static void SetSpecular(this Material target, Color color)
Normal Map
public static void SetNormalMap(this Material target, in string normalMapPath)
SpeedTree Conversion (Vegetation)
public static void ConvertToSpeedTree(this Material target)
Assimp Material Property Mapping
When importing meshes via Assimp, material properties are mapped as follows:
HasColorDiffuse → SetBaseColor(diffuseColor)
HasOpacity → alpha = opacity; SetTransparent() if < 1.0
HasColorEmissive → SetEmission(emissiveColor)
HasColorSpecular → SetColor("_SpecColor", specularColor)
HasShininess → Smoothness = 1.0 - Clamp01(Shininess)
HasReflectivity → Smoothness = 1.0 - Clamp01(Reflectivity)
HasTextureDiffuse → _BaseMap texture
HasTextureNormal → _BumpMap + _NORMALMAP keyword
HasBumpScaling → _BumpScale (normal map strength)
HasTextureSpecular → _SpecGlossMap + _SPECGLOSSMAP keyword
HasTextureEmissive → _EmissionMap + _EMISSION keyword
HasTextureOpacity → logged only (not applied)
Texture Loading Pipeline
Search Path Resolution
Textures are resolved through a prioritized search:
""
"../"
"../../"
"textures/"
"../textures/"
"../materials/"
"materials/"
Format-Specific Loading
TextureUtil.LoadTGA(fileStream)
texture.LoadImage(File.ReadAllBytes(path))
Post-Load Optimization
texture.filterMode = FilterMode.Trilinear;
texture.anisoLevel = 4;
if (width % 4 == 0 && height % 4 == 0)
texture.Compress(true);
texture.Apply(false, true);
texture.hideFlags = HideFlags.DontUnloadUnusedAsset;
URP Shader Property Reference
| Property | Type | Default | Purpose |
|---|
_BaseColor | Color | White | Albedo/diffuse color |
_BaseMap | Texture2D | — | Albedo texture |
_BumpMap | Texture2D | — | Normal map |
_BumpScale | Float | 1.0 | Normal map strength |
_EmissionColor | Color | Black | Emission color |
_EmissionMap | Texture2D | — | Emission texture |
_SpecColor | Color | — | Specular color |
_SpecGlossMap | Texture2D | — | Specular/gloss map |
_Smoothness | Float | 0 | Surface smoothness (0=rough) |
_SmoothnessSource | Int | 0 | 0=specular alpha, 1=albedo alpha |
_Cull | Int | 2 (Back) | Face culling mode |
_Surface | Int | 0 | 0=opaque, 1=transparent |
_SrcBlend | Int | 1 | Source blend factor |
_DstBlend | Int | 0 | Destination blend factor |
_ZWrite | Int | 1 | Depth write enable |
Procedure: Adding a Custom Material Property
- Identify the URP shader property name (check
Custom/URP/Simple Lit shader source)
- Create an extension method in
SDF2Unity.Material.cs:
public static void SetMyProperty(this Material target, float value)
{
target.SetFloat("_MyProperty", value);
}
- Wire it into the Assimp material conversion or SDF material import path
Common Issues
| Symptom | Cause | Fix |
|---|
| Model is all white | Textures not found | Check texture search paths; verify file exists |
| Model is invisible | Alpha is 0 | Check HasOpacity; Blender FBX may export alpha=0 |
| Model is too shiny | Smoothness too high | Check Shininess / Reflectivity mapping (inverted) |
| Normal map looks flat | _NORMALMAP keyword not enabled | Ensure EnableKeyword("_NORMALMAP") is called |
| Transparent model has z-fighting | Wrong render queue | Verify SetTransparent() sets queue to Transparent |
| Vegetation renders single-sided | Not using SpeedTree shader | Call ConvertToSpeedTree() for tree/plant materials |
| Texture is blurry | Not compressed or wrong filter | Check filterMode and anisoLevel in post-load |
| TGA texture crashes | Unsupported TGA variant | Check TextureUtil.LoadTGA() format support |