Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kvekos · May 10, 2017 at 01:34 PM · camerashaderrendering

CommandBuffer's CameraEvent ordering not in sync with shader rendering queue?

I'm trying to use a camera script to get my camera to render to a RenderTexture via CommandBuffers. I also have a custom shader which I specifically set its Render Queue to "Queue" = "Overlay" because I don't want it to render geometry until the RenderTexture has been written because I don't want objects with my shader to be captured in the RenderTexture.

I added my CommandBuffer to the camera with the CameraEvent.BeforeImageEffects; CameraEvent because I want my CommandBuffer actions to be executed before the camera renders my custom shader.

Now this makes sense in theory because according to Unity's documentation my CommandBuffer should be executed before image effects are rendered and so the RenderTexture my CommandBuffer tells the camera to write to should NOT contain any geometry which uses my custom shader because since its Queue is set to "Overlay" it should be considered an image effect and rendered right after, which will give my custom shader access to the RenderTexture I just made which is necessary for my shader to work.

UNFORTUNATELY for some reason this doesn't work at all - the camera is executing my CommandBuffer after rendering my custom shader geometry and so its being captured in the RenderTexture and giving me an unwanted hall of mirrors effect on my shader.

Additionally, for some reason the Scene View camera ,when in the editor's Scene tab, doesn't execute my CommandBuffer at all, it seems to work if I set the CameraEvent to CameraEvent.AfterForwardAlpha but of course, this only works when the camera is using Forward rendering where I need it to work in any rendering path.

Is this a defect or am I missing something?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by coldwarrior5 · Jun 01, 2020 at 10:24 AM

I had the same issue @kvekos. I have been playing with it for half an hour and I found the cause of the issue.

When it comes to logic, I agree that BeforeImageEffect should yield a texture with no effects applied. However, the way it is implemented you have to sort the command buffers manually in order to get it working which is confusing and is not mentioned in the documentation. Basically, the texture blit has to be the first command buffer in the list in order to execute before the effects get applied, again weird as you would expect it to work automatically given the Event is called BeforeImageEffects.


Here is an example that works for me:

 _sceneCapture = new CommandBuffer 
 {
     name = "Scene view"
 };
 RenderTargetIdentifier sceneViewID = new RenderTargetIdentifier(_sceneView);
 _sceneCapture.Blit(BuiltinRenderTextureType.CurrentActive, sceneViewID);
 
 var commandBuffers = _attachedCamera.GetCommandBuffers(CameraEvent.BeforeImageEffects);
 if (!commandBuffers.Contains(_sceneCapture))
 {
     _attachedCamera.RemoveCommandBuffers(CameraEvent.BeforeImageEffects);
     // First we add our effect
     _attachedCamera.AddCommandBuffer(CameraEvent.BeforeImageEffects, _sceneCapture);
     // And then we readd all of the others
     foreach(CommandBuffer buffer in commandBuffers)
         _attachedCamera.AddCommandBuffer(CameraEvent.BeforeImageEffects, buffer);
 }

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Uniform Texture, Rendering Problem 0 Answers

(Non-Euclidean) Overlapping Textures with Multiple Cameras Problem 0 Answers

Is particular object visible 1 Answer

object not rendered correctly when i take camera away from object in unity vuforia 0 Answers

stencil mesh,stencil mesh-how to i get a stencil mesh to a camra rendering pipe to cull the mesh behand the mesh. dimish the draw call count 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