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
2
Question by taoa · May 21, 2010 at 09:53 AM · shaderrendertexturerendertarget

Can I use a render target as a shader property when rendering to the same render target?

The title says it all:

I'd like to use a render target as an input texture to a shader, this shader being used to render into said render target.

What I'm mostly interested to know is if I do that, when I read pixels from the RT (tex2D(blahblah);) will those retrieved pixels be of the untouched original RT before any rendering, or will they be modified as pixels get rendered into the RT?

Or am I committing a crime against nature?

Thanks.

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 duck ♦♦ · May 21, 2010 at 11:05 AM 0
Share

I'm going with 'crime against nature'. I expect your computer will dissappear into a singularity too!

avatar image duck ♦♦ · May 21, 2010 at 11:05 AM 0
Share

seriously though, this sounds like the easiest way to answer your question would be to go ahead and just test it. be sure to post your own answer here if you find out. sounds interesting.

avatar image taoa · May 21, 2010 at 03:02 PM 0
Share

Hey Dock, thanks for answering. I indeed tested it. And I answered it :) Enjoy

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by taoa · May 21, 2010 at 03:11 PM

OK, I tested it and I can answer this ages-old question:

Yes, it's possible to do something like this:

        RenderTexture oldRT = RenderTexture.active;
        RenderTexture.active = RT;
        GL.PushMatrix( );
        Material mat = myMat;
        mat.SetTexture( "_MainTex", RT );
        for( int i = 0 ; i < mat.passCount ; i++ )
        {
            mat.SetPass( i );
            DrawQuad( rect, new Rect( 0.0f, 0.0f, 1.0f, 1.0f ) ); //some rectangle, with texture coords...
        }
        GL.PopMatrix( );
        RenderTexture.active = oldRT;

which uses the target texture as a normal texture in the shader. If it works for me, it might be because my hardware (GTX260) is capable of getting data from stuff it's rendering too, I don't know. But that definitely works.

I think I can also answer my second question, since I can see some bleeding from my blur shader: when I read from my render texture, it reads things that were already rendered for previous pixels.

In other words: I'm definitely reading what I'm writing into by doing that.

And I for one am happy of this. There are so many crazy things that can be done with this fact. Many will consider it horrible hack, I don't mind :)

But I still need to use an intermediate render texture for my blur, because of all the bleeding :p

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

No one has followed this question yet.

Related Questions

SetTargetBuffers for multiple color buffers 1 Answer

How to clean on RenderTexture to transparent with brush 0 Answers

Render to Texture artifacts 0 Answers

Writing from fragment shader into 3D render texture 1 Answer

My RenderTexture Can't see anything 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