Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by helioschromatic · Dec 14, 2021 at 01:12 PM · renderinggraphicsrendertexture

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!!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Dec 14, 2021 at 04:47 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

160 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges