Search Unity

Question Assign RenderTextures to Materials' property

Discussion in 'Universal Render Pipeline' started by Bluedoom, Sep 16, 2022.

  1. Bluedoom

    Bluedoom

    Joined:
    Aug 31, 2020
    Posts:
    14
    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.
    Code (CSharp):
    1.  
    2. foreach(light of lights)
    3. {
    4.   var rt = RenderTexture.GetTemporary(desc);
    5.   _tempRTs.Add(rt);
    6.  //_cmd.GetTemporaryRT(propId, size, size, 0, FilterMode.Bilinear, RenderTextureFormat.R8);
    7.   _cmd.SetRenderTarget(rt, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
    8.   _cmd.ClearRenderTarget(false, true, Color.white);
    9.   _ctx.ExecuteCommandBuffer(_cmd);
    10.   _cmd.Clear();
    11.   _ctx.DrawRenderers(_cullingResults, ref _drawingSettings, ref _filteringSettings);
    12.   // i want to set the result to material
    13.   light.Renderer.sharedMaterial.SetTexture("_ShadowMap", rt);
    14. }
    15. ...
    16. /* Render Scene */
    17. _ctx.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
    18. ...
    19. for (int i = _tempRTs.Count - 1; i>=0;i--)
    20. {
    21.     //_cmd.ReleaseTemporaryRT(ShadowMapIDs[i]);
    22.     RenderTexture.ReleaseTemporary(_tempRTs[i]);
    23. }
    24. _tempRTs.Clear();
    25.  
     
    Last edited: Sep 29, 2022
  2. Bluedoom

    Bluedoom

    Joined:
    Aug 31, 2020
    Posts:
    14