I am looking to assign a normal map to a runtime-created material that uses the HDRP/Lit shader. The assignment seems to work and the values can be seen in the editor, but the normal map isn’t applied to the object. What’s particularly strange about this is that if I expand or collapse any of the material sections in the editor, the normal map is suddenly applied to the object correctly. Am I missing something here? Is there something I failed to update/flag?
public GameObject TestObject;
public Texture2D NormalTexture;
void Start()
{
var newMaterial = new Material(Shader.Find(“HDRP/Lit”));
AssignNormalTexture(newMaterial, NormalTexture);
var renderers = TestObject.GetComponentsInChildren();
foreach (var renderer in renderers)
{
renderer.sharedMaterial = newMaterial;
}
}
void AssignNormalTexture(Material material, Texture2D normalMap)
{
//tangent space
material.SetTexture(“_NormalMap”, normalMap);
material.SetFloat(“_NormalMapSpace”, 0.0f);
material.SetFloat(“_NormalScale”, 1.0f);
material.EnableKeyword(“_NORMALMAP”);
}
After assignment (normal map not applied to object):
After collapsing the “Surface Inputs” section in the inspector: