Replace the content of the Hololens 2 screen with a precomputed texture

Requirement : The texture generated by my own renderer is A, and the texture generated by the virtual camera in Unity is B. Normally, what I see in the glasses is B. I want to replace B with A directly.

Understand the life cycle of Unity rendering scripts:
For our needs, the key is the content of Scene Rendering . What we have to do is to change OnRenderImagethe content, cut it off, and prevent it from transferring the original texture content to the next step.
insert image description here

solution:

    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
    
    
        //获取自己写的Main脚本中的buffer数据
        byte[] Texbuffer = root.GetComponent<Main>().buffer;
        Texture2D tex2d = new Texture2D(width, height, TextureFormat.RGBA32, false);
        tex2d.LoadRawTextureData(Texbuffer);
        tex2d.Apply();
        RenderTexture out_renderTexture = new RenderTexture(width, height, 0);

        //将buffer数据替换到相机最终的显示纹理
        RenderTexture.active = out_renderTexture;
        Graphics.Blit(tex2d, out_renderTexture);
        Graphics.Blit(out_renderTexture, dest);

    }

Guess you like

Origin blog.csdn.net/qq_41598072/article/details/131381192