Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 raja-bala · Feb 07, 2015 at 12:58 AM · renderingrendertextureshaderlabonpostrender

Writing to RWTexture3D using a pixel shader without using Graphics.Blit

I'm almost certain that Unity 4.6.1.1f1 still doesn't support writing to RWTexture3D or RWTexture2D from a pixel shader without using OnRenderImage(..) and Graphics.Blit

It seems to me like Graphics.SetRandomWriteTarget(..) doesn't work when used from OnPostRender with either Graphics.DrawMeshNow or Graphics.Blit. I can't understand why though.

Here's a code snippet of the script:

 void OnPostRender()
     {       
         Graphics.SetRenderTarget(rtCam);
         Graphics.ClearRandomWriteTargets();
 
         Graphics.SetRandomWriteTarget(1, rtVol);
         Graphics.SetRandomWriteTarget(2, rtPlane);
 
         matWriteTextureOnPS.SetFloat("_volDepth", size);
         matWriteTextureOnPS.SetFloat("_time", Time.timeSinceLevelLoad);
         Graphics.DrawMeshNow(quadMesh, Vector3.zero, Quaternion.identity);
         // Graphics.Blit(src, src, matWriteTextureOnPS); // replace above line with this and try.
 
         Graphics.ClearRandomWriteTargets();
     }
 

matWriteTextureOnPS has a pixel shader that writes to rtVol and rtPlane which are used as textures for objects in my scene. If I move this code to OnRenderImage and use Graphics.Blit instead of DrawMeshNow and make the shader use vert_img as the VS, it works.

Here're the GPA API logs for the three scenarios I tried:

  1. OnPostRender with DrawMeshNow

  2. OnPostRender with Graphics.Blit

  3. OnRenderImage with Graphics.Blit

For 1 and 3, Unity binds the RT and UAVs correctly using OMSetRenderTargetsAndUnorderedAccessViews, but for 1, it resets the bindings using OMSetRenderTargets. As a result, the UAVs are no longer bound. For 2, Unity never binds the UAVs. I don't know why.

Links to similar questions:

  1. http://answers.unity3d.com/questions/566106/how-to-write-to-rwtexture3d-in-pixel-shader.html

  2. RWTexture writes are not supported in pixel shaders from camera drawing

  3. http://forum.unity3d.com/threads/rwtexture2d-shader-in-onpostrender-problems.173436/

Comment
Add comment · Show 3
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 Juho_Oravainen · Feb 11, 2015 at 08:39 AM 0
Share

Definitely sounds like a bug but I couldn't reproduce with a quick try. So please submit a bug with a $$anonymous$$imal repro project.

For the Draw$$anonymous$$eshNow case you could try out calling SetRenderTarget after the SetRandomWriteTarget calls to force the UAVs on that point (in case the Draw$$anonymous$$eshNow does not set them due to some bug).

avatar image raja-bala · Feb 12, 2015 at 08:57 AM 0
Share

Thanks, I submitted the bug with a simple test scene. Apparently, Graphics.Blit works fine in OnPostRender/OnRenderObject for UAV writes. The problem ins$$anonymous$$d is: When multiple UAV writes are done in any of these functions (via, say a loop), only the first one has the UAVs bound and successfully written to. Everything else doesn't.

avatar image raja-bala · Feb 12, 2015 at 08:58 AM 0
Share

Also I tried what you suggested, didn't fix :(

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

21 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

Related Questions

Prevent Unity from reordering DrawMeshNow calls 1 Answer

Best way to access RenderTexture immediately after camera render 0 Answers

Speeding up reading from a RenderTexture 3 Answers

Image-Based Lighting refreshing 0 Answers

OnpostRender is not called 4 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