I assign RT-A to material A, RT-B to material B, but i got RT-A on material B and RT-B on material-A (by frame debugger). I guess command buffer is execute async on rendering thread after a few frames. But texture is setted every frame on main thread. Then objects are rendered to a rt that was released to pool then get by another material.
I also tried to release tempRTs at next frame. but it didn’t change anything.
note: the ‘_ShadowMap’ temporary render texture below is a R8 mask,and light is a custom component.
foreach(light of lights)
{
var rt = RenderTexture.GetTemporary(desc);
_tempRTs.Add(rt);
//_cmd.GetTemporaryRT(propId, size, size, 0, FilterMode.Bilinear, RenderTextureFormat.R8);
_cmd.SetRenderTarget(rt, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
_cmd.ClearRenderTarget(false, true, Color.white);
_ctx.ExecuteCommandBuffer(_cmd);
_cmd.Clear();
_ctx.DrawRenderers(_cullingResults, ref _drawingSettings, ref _filteringSettings);
// i want to set the result to material
light.Renderer.sharedMaterial.SetTexture("_ShadowMap", rt);
}
...
/* Render Scene */
_ctx.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
...
for (int i = _tempRTs.Count - 1; i>=0;i--)
{
//_cmd.ReleaseTemporaryRT(ShadowMapIDs[i]);
RenderTexture.ReleaseTemporary(_tempRTs[i]);
}
_tempRTs.Clear();