Hey Team,
I’ve happened across something breaking to my project with regards to both URP and HDRP.
A quick summary of my process;
Bullets travel in a level, causing a glowing light. Rather than using lights since there may be over 3 000 bullets, i’m opting to build a texture, and use the emissive property of the grid.
Generating the texture at runtime, either in Start, Awake or Update is successful, and applies to the material correctly, but won’t be reflected in the Game or Scene views, unless the material is unfurled in the inspector.
This seems to only able to be rendered by inspecting the material, and the same issue happens in Standalone builds, leading to the texture never being rendered (since there’s no inspector)
I’ve attempted recalculating the DynamicGI, and requested the renderer update its GI materials, all to no avail.
I’ve reproduced this in a contained environment on Unity 2019.4.13f1 (LTS) here; GitHub - UserAnon91/UnityEmissionBug: Repository to host the Unity emission bug i've encountered in my original project
This bug is still present on the newest version of unity, with the latest version of HDRP
A demonstration of the perceived bug is here;
The code used to reproduce is simplified here;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EmissionBugReproduce : MonoBehaviour
{
public Material newNewGridMaterial;
public Texture2D gridTexture;
public Renderer ourRenderer;
// I've originally split this into awake or start,
// then update the texture every 0.1 seconds with the same result
void Awake()
{
gridTexture = new Texture2D(100, 100);
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
if (i % 2 == 0 && j % 2 == 0)
{
gridTexture.SetPixel(i, j, Color.magenta);
}
else
{
gridTexture.SetPixel(i, j, Color.black);
}
}
}
gridTexture.filterMode = FilterMode.Point;
gridTexture.Apply();
ourRenderer.material.SetTexture("_EmissiveColorMap", gridTexture);
/*******************************/
/*
Additionally, i've attempted to use:
newNewGridMaterial.EnableKeyword("_EMISSION");
newNewGridMaterial.EnableKeyword("_Emission");
newNewGridMaterial.EnableKeyword("_Emissive");
newNewGridMaterial.SetTexture("_BaseColorMap", gridTexture);
ourRenderer.material = newNewGridMaterial;
DynamicGI.SetEmissive(ourRenderer, Color.white);
ourRenderer.UpdateGIMaterials();
*/
}
}