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 /
  • Help Room /
avatar image
1
Question by Rs · Oct 19, 2016 at 08:59 AM · shadershadersshader programminggpufloatingpoint

Read float values from RGBAFloat texture

It seems people aren't discussing much around floating point textures. I used them to do some computations and then forward the result to another surface shader (to obtain some specific deformations) and that's cool ,it always works for me if I digest the results in a shader but this time I need to get those values CPU side so I get a float[] array with the results (just after calling Graphics.Blit that fills the floating point texture). How can this be achieved?

On a side note: the only guy that I saw using this method so far is Keijiro, for example in his Kvant Wall; if you have other sources I'd be grateful if you let me know.

ps: please don't waste keyboard clicks saying there are compute shaders and OpenCL and CUDA. This is the method I need now.

Comment
Add comment · Show 1
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 Cherno · Oct 19, 2016 at 09:42 AM 0
Share

This seems to be a very specific question :) Perhaps it's better suited for the forums? If you already made a thread there, disregard please.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Oct 19, 2016 at 10:33 AM

Uhm, since you already mentioned that project, have you actually take a look at it? Especially the Wall.cs script?

The most important parts are that you create the RenderTexture as an ARGBFloat texture

 /*#292*/ var buffer = new RenderTexture(_columns, _rows, 0, RenderTextureFormat.ARGBFloat);

To read the content of a RenderTexture you have to use Texture2D.ReadPixels of an actual Texture2D with the same format. Finally just use GetPixels to read the Color array. "Color" is made of 4 float values, so you can directly access all 4 components of each "pixel".

Note: ReadPixels as well as GetPixels are quite heavy methods depending on the size of the image. In the project he actually doen't "read" the content at all on the CPU side. He just reuses them inside another shader by directly using the rendertexture as input for the shader, just like you're currently doing.

There's no way around ReadPixels and GetPixels. GPU buffers live on the GPU and you don't have direct access to it. You need to actually lock the buffer and copy the content over. That's what ReadPixels and finally GetPixels does.

Comment
Add comment · Show 3 · 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 Rs · Oct 19, 2016 at 10:45 AM 0
Share

Thank you Bunny83, I do know what you are talking about, I studied that project in depth and I know how to initialize a floating point texture. I am investigating methods to download the values. For now I think I found a solution using GetRawTextureData but I will definitely try to trust the GetPixels function as you suggest it doesn't break precision and test asap. Thanks

avatar image Rs · Oct 19, 2016 at 10:53 AM 0
Share

Well GetPixels just smoothly works! I didn't realize it would keep the floating point format intact. Thank you.

avatar image Bunny83 Rs · Oct 19, 2016 at 07:35 PM 0
Share

If your problem is solved, don't forget to accept an answer to mark the question as answered.

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

82 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 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 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 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

Creating a 3D portal effect using stencil buffer with a deferred shading setup? 1 Answer

Oculus Rift with LWRP shader problem 1 Answer

Add hard shadows to a Toon Shader 0 Answers

Operate the shader, rotate the material 90 degrees 0 Answers

How to map letters on mesh with shader? 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