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 YoYoooooooo · Dec 15, 2015 at 09:53 AM · rendertexturedirectxshader-replacement

Is RenderTexture simultaneous writing and sampling possible?

Hi,

I've been struggling with this one for a while: I have a camera rendering a scene into a render texture. This rendering uses Unity's shader replacement mechanism to render objects with a custom shader. This pixel shader first samples this render texture (the very same texture the camera is rendering to) and then modulate the sampled pixel color (paint application). This results in kind of an incremental modification of the render texture. Everything works as expected with OpenGL, but D3D(11) seems a little bit more picky: looks like the texture sampled is... just another arbitrary texture.

Hope this makes sense, kinda difficult to explain.

I of course can provide source code if relevant.

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
2
Best Answer

Answer by wibble82 · Dec 15, 2015 at 11:55 AM

Short answer: not really!

Longer answer: The behavior is probably undefined. You almost certainly won't be simultaneously reading/writing, even if it appears to work. However depending on the underlying implementation you may be getting away with reading from last-frame's result while writing to this frame's one.

To do this correctly, look into how post effect shaders work in unity. It is entirely possible to define extra buffers and explicitly manage the saving of last frame's result to be sampled from this frame. Here's a great tutorial on the subject:

http://www.alanzucconi.com/2015/07/08/screen-shaders-and-postprocessing-effects-in-unity3d/

Comment
Add comment · Show 5 · 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
avatar image YoYoooooooo · Dec 15, 2015 at 04:51 PM 0
Share

Thanks for your answer. "Simultaneous" is indeed incorrect, "sampling the render texture currently being rendered" might be more relevant.

I read through the link you provided but I could not find any mention of frame buffers management, did I miss something??

avatar image wibble82 YoYoooooooo · Dec 15, 2015 at 05:12 PM 0
Share

Hmmm - it doesn't actually show the saving of frame buffers now I think about it - just the use of the OnRenderImage function (which is the key bit).

If you look at that tutorial, you will notice that what they're doing is:

  • Taking 2 render textures as inputs to the function

  • The source is what the camera generates through rendering

  • The destination is what will be output (either to the screen, or the next camera)

  • They then 'blit' the image from source to destination, using a shader to apply extra effects

If you have a script like they do, you can just as easily define your own extra 'RenderTextures', literally by just creating them as needed. In your case you'd probably want some code that went:

  • Have an extra buffer called 'previous'

  • Write a shader that takes the source and the previous as input, and uses them to blit to the destination

  • Blit the source to previous (or maybe the destination to previous), so you can use it next frame

Check out the post effects shaders that come with unity for extra examples - the motion blur post effect scripts do exactly this stuff.

-Chris

avatar image YoYoooooooo wibble82 · Dec 15, 2015 at 11:02 PM 0
Share

Ok, Graphics.Blit() seems to be the key. Will try asap. Thanks!

Show more comments
Show more comments

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

Why is it that when I set my XRay shader as Camera's replacementShader , all gameobjects disappear ?? 0 Answers

unity 3 Render Texture limitations on IOS (cant set bigger then 512 - bug?) 2 Answers

Problem using RenderTexture 1 Answer

Vuforia QCAR : RenderTexture are black 0 Answers

Vectrosity: SetCamera(), aspect, resolution and rendertextures 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