- Home /
PLEASE DEAR GOD! ScriptableRenderContex.BeginScopedRenderPass
Ok I'm beginning to loose my mind here. I want to use the scoped render pass of unitys scriptable render context. But it almost seems like a unfinished function behind the scenes.
This is the simplest and straight forward scriptable renderpipeline i can think of:
If i use "buffer.SetRenderTarget(renderTargetBinding)" directly everything works. But with attachments nothing gets rendered and the store actions always read "DontCare". What am i missing here?
public class CustomRenderPipeline : RenderPipeline {
public CustomRenderPipeline( ) { }
public static ShaderTagId unlitShaderTagId = new ShaderTagId("CustomUnlit");
public static int bufferSizeId = Shader.PropertyToID("_Depth");
protected override void Render(ScriptableRenderContext context, Camera[] cameras) {
foreach (Camera camera in cameras) {
CullingResults cullResults;
if (!camera.TryGetCullingParameters(out ScriptableCullingParameters p)) {
Debug.LogError("Couldnt get culling parameters");
}
cullResults = context.Cull(ref p);
var sortingSettings = new SortingSettings(camera) { criteria = SortingCriteria.CommonOpaque };
var drawingSettings = new DrawingSettings(unlitShaderTagId, sortingSettings);
var filteringSettings = new FilteringSettings(RenderQueueRange.opaque);
context.SetupCameraProperties(camera);
CommandBuffer buffer = CommandBufferPool.Get();
var depthDescriptor = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight, RenderTextureFormat.Depth, 32);
var depthIdentifier = new RenderTargetIdentifier(Shader.PropertyToID("_Depth"));
buffer.GetTemporaryRT(Shader.PropertyToID("_Depth"), depthDescriptor);
context.ExecuteCommandBuffer(buffer); buffer.Clear();
if (Time.frameCount % 240 < 120) {//Switch between two approches every 120 Frames
//>>>>>>>>>>>>>>>> This works >>>>>>>>>>>>>>>>>>
var renderTargetBinding = new RenderTargetBinding(BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
depthIdentifier, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
buffer.SetRenderTarget(renderTargetBinding);
buffer.ClearRenderTarget(true, true, Color.clear);
context.ExecuteCommandBuffer(buffer); buffer.Clear();
context.DrawRenderers(cullResults, ref drawingSettings, ref filteringSettings);
context.DrawSkybox(camera);
//<<<<<<<<<<<<<<<<< This works <<<<<<<<<<<<<<<<<
} else {
//>>>>>>>>>>>>>>>> This doesnt >>>>>>>>>>>>>>>>>>
var attachments = new NativeArray<AttachmentDescriptor>(2, Allocator.Temp);
attachments[0] = new AttachmentDescriptor(RenderTextureFormat.Depth, depthIdentifier, false, true);
attachments[0].ConfigureTarget(depthIdentifier, false, true);
attachments[0].ConfigureClear(new Color(0, 0, 0, 0), 1);
attachments[1] = new AttachmentDescriptor(RenderTextureFormat.Default, BuiltinRenderTextureType.CameraTarget, false, true);
attachments[1].ConfigureTarget(BuiltinRenderTextureType.CameraTarget, false, true);
attachments[1].ConfigureClear(new Color(0, 0, 0, 0));
using (context.BeginScopedRenderPass(camera.pixelWidth, camera.pixelHeight, 1, attachments, 0)) {
attachments.Dispose();
var targets = new NativeArray<int>(1, Allocator.Temp);
targets[0] = 1;
using (context.BeginScopedSubPass(targets, false)) {
targets.Dispose();
context.DrawRenderers(cullResults, ref drawingSettings, ref filteringSettings);
context.DrawSkybox(camera);
}
}
//<<<<<<<<<<<<<<<<< This doesnt <<<<<<<<<<<<<<<<<
}
buffer.ReleaseTemporaryRT(Shader.PropertyToID("_Depth"));
context.ExecuteCommandBuffer(buffer); buffer.Clear();
CommandBufferPool.Release(buffer);
context.Submit();
}
}
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
}
}
Any input is appreciated!!
Hi. I am not familiar with the system(s) but I started poking at it a little bit. Don't you have to clear the depth and color textures? I might return to poke at it a bit more later, I am unfortunately a bit busy at the moment.
Your answer
Follow this Question
Related Questions
Complex Depth Shader 0 Answers
Masking elements with non-rendered layers? Culling masks, camera, render textures 0 Answers
Graphics.DrawTexture vs GUI.DrawTexture vs Graphics.Blit 0 Answers
The alpha value in the RenderTexture are not the same in Editor mode and Build mode. 2 Answers
OnRenderImage does not work in HDRP 0 Answers