- Home /
 
 
               Question by 
               pporp · Feb 27, 2018 at 05:39 AM · 
                depth-bufferrender to texture  
              
 
              CommandBuffer.SetRenderTarget becomes strange with BuiltinRenderTextureType.Depth
I tried draw mesh on rendertexture using commandbuffer, and CommandBuffer.SetRenderTarget works good without another depth buffer. The left quad is rendertexture!
 {
 //...
 CommandBuffer commandBuffer = new CommandBuffer();
         commandBuffer.name = "downsample";
         int downsampleTexID = Shader.PropertyToID("_DownsampleTex");
         commandBuffer.GetTemporaryRT(downsampleTexID, (int)-1, (int)-1, 24);
         commandBuffer.SetRenderTarget(downsampleTexID/*, BuiltinRenderTextureType.Depth*/);
         commandBuffer.ClearRenderTarget(false, true, Color.red);
 
         Matrix4x4 planeTransform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * 0.05f);
         commandBuffer.DrawMesh(mesh, planeTransform, MaskStencilColorMat, 0, 0);
 
         commandBuffer.SetRenderTarget(null as RenderTexture);
         _camera.AddCommandBuffer(CameraEvent.AfterForwardAlpha, commandBuffer);
     }
 
               
But when i used BuiltinRenderTextureType.Depth, the mesh was rendered in the gameview (guessed render on the framebuffer)
 {
 //...
 commandBuffer.SetRenderTarget(downsampleTexID, BuiltinRenderTextureType.Depth);
 //...
 }
 
               
Tried BuiltinRenderTextureType.CameraTarget as depth buffer param also get the wrong result ! Did i miss sth. or I mistake the SetRenderTarget. I'm a newer for u3d and want to seek help here, wish somebody to help me.
 
                 
                tim图片20180227123300.png 
                (45.1 kB) 
               
 
                
                 
                tim图片20180227132823.png 
                (47.7 kB) 
               
 
              
               Comment
              
 
               
              Your answer