• 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
Question by $$anonymous$$ · 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 w$$anonymous$$ch 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 t$$anonymous$$s 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 w$$anonymous$$ch uses my custom shader because since its Queue is set to "Overlay" it should be considered an image effect and rendered right after, w$$anonymous$$ch will give my custom shader access to the RenderTexture I just made w$$anonymous$$ch is necessary for my shader to work.

UNFORTUNATELY for some reason t$$anonymous$$s 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, t$$anonymous$$s only works when the camera is using Forward rendering where I need it to work in any rendering path.

Is t$$anonymous$$s a defect or am I missing somet$$anonymous$$ng?

Comment

People who like this

0 Show 0
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

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 w$$anonymous$$ch 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

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there a delay when setting properties on a material. 0 Answers

Render object with different shader depending on the camera 2 Answers

Is there a way to render a single object with a unique color per active camera? 1 Answer

Render group of objects in front? 0 Answers

How can I make a quad render below absolutely everything else? 1 Answer


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