Answer the question
In order to leave comments, you need to log in
How to create depth texture in unity?
I want to generate a depth texture in a compute shader. How can I do that? here from c#:
Camera camera = CameraManager.cam;
resultTexture = new RenderTexture(1024, 768, 32)
{
enableRandomWrite = true
};
resultTexture.Create();
debugImage.texture = resultTexture;
kernelIndex = shader.FindKernel("CSMain");
shader.SetTexture(kernelIndex, "Result", resultTexture);
shader.SetTextureFromGlobal(kernelIndex, "_DepthTexture", "_CameraDepthTexture");
shader.Dispatch(kernelIndex, camera.pixelWidth / 8, camera.pixelHeight / 8, 1);
#pragma kernel CSMain
RWTexture2D<float4> Result;
Texture2D<float4> _DepthTexture;
[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
float depth = _DepthTexture[id.xy].r;
Result[id.xy] = float4(depth, 0, 0, 0);
}
Result[id.xy] = float4(0, 0, 0, 0);
for example, then everything is fine
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question