• 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
1
Question by Artaani · Nov 26, 2016 at 09:28 AM · shadertexture

How to save result of GPU Perlin Noise (from shader) to a regular Texture2D?

Not sure I am asking the question correctly.

Here is the asset, Turbulence Library. It generates various noises using a shader, but how can I convert the result into regular Texture2D?

So I be able to use it in other materials or save to file.

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 tanoshimi · Nov 26, 2016 at 02:05 PM

You'd first use Graphics.Blit to draw the material using the Turbulence Library onto a rendertexture, and then use ReadPixels to copy from there to a regular Texture2D. Something like this:

 // Create a temporary render texture 
 RenderTexture temp = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32);

 // Draw to the RT (Texture2D.whiteTexture is just a dummy src)
 // mat is a material with the Turbulence Shader applied to it
 Graphics.Blit(Texture2D.whiteTexture, temp, mat);

 // Copy the rendertexture to a regular texture
 Texture2D tex = new Texture2D(width, height);
 tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
 tex.Apply();
Comment
Add comment · Show 12 · 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 Artaani · Nov 26, 2016 at 03:41 PM 0
Share

Thanks for the reply! I copied the code, but for some reason, result texture is completely black. However if I select material in inspector - it displayed with turbulence.

avatar image tanoshimi Artaani · Nov 26, 2016 at 10:08 PM 0
Share

Is this a surface shader or a regular vert/frag shader? From memory surface shaders don't work well with Blit: https://forum.unity3d.com/threads/shaders-not-working-in-graphics-blit-when-using-my-own-rendertexture.98161/

avatar image Artaani tanoshimi · Dec 07, 2016 at 05:31 PM 0
Share

It took some time, but I figured out! Yes, it is surface shader, so it does not work, but it can be quite easily converted in fragment shader and it starts to work perfect!

Thanks you! :)

If someone will encounter the same problem - let me know, I will describe solution in more details.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

87 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Render scene depth to a texture 4 Answers

Global Rendering with a shader that uses a texture 1 Answer

How can i get mixed texture from one shader and set it for another object with another shader? 0 Answers

Open project from MAC at PC 2 Answers

Projected Texture Shader Issues 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