• 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 minimal 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Best way to access RenderTexture immediately after camera render 0 Answers

Prevent Unity from reordering DrawMeshNow calls 1 Answer

Can someone explain RenderTexture.SupportsStencil 0 Answers

RenderTexture and Readpixels android problem. 2 Answers

DrawTexture on RenderTexture without Camera 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges