Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Assign RenderTextures to Materials' property

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

  1. Bluedoom


    Aug 31, 2020
    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):
    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();
    Last edited: Sep 29, 2022
  2. Bluedoom


    Aug 31, 2020