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
0
Question by Starlight · Mar 11, 2013 at 03:14 PM · shadertextureprocedural

How to create texture in shader

Hello!

I have searched a lot and I have found no answer. If I make a shader, and make a texture2d variable in it, it is supposed that I then drag-n-drop some png/psd/whatever file there.

But how can I make this texture inside shader proceduraly? For example, I want it to be 256x256 and I want every pixel just to be random color. And the random color of each pixel should be calculated only once when the object is instantiated. So it's like a pregeneration of a texture on program start or object instantiation.

Thank you!

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
1

Answer by Steven-1 · Mar 11, 2013 at 03:17 PM

don't do this in a shader (not even possible as far as I know), do this in a script at startup. Use the Texture2D class: http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.html

Use SetPixels()

It's all fairly straightforward

Comment
Add comment · Show 2 · 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 fafase · Mar 11, 2013 at 03:43 PM 0
Share

If you even feel like going lower in program$$anonymous$$g you can use the GL class: http://docs.unity3d.com/Documentation/ScriptReference/GL.html

but the answer above is dealing with Texture which is what you ask for.

avatar image zachanima · May 02, 2013 at 01:06 AM 1
Share

Generating a texture in a shader is actually very possible, although I don't know specifically how to do it in Unity.

When generating data for huge terrains procedurally in realtime, you will often want to perform these computations on the GPU.

As an example, here I am generating a normal map procedurally in realtime in a GLSL shader.

This allows for much greater detail locally than would be achievable by pregenerating data (unless you have a ton of memory to store the amount of data required for this detail level).

Sadly, as said, I don't know how to do this in Unity yet. However, I have made the source code for the application shown in the video above available online: http://github.com/zachanima/shader

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

13 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

Related Questions

How to create an procedural texture in shader graph for many objects, and save it? 0 Answers

is there a way to make a gradient material, white to black, in Unity3D? 2 Answers

Mapping a texture to a meshes normals? 0 Answers

Merging, Transitioning, or Blending from one texture to the other based upon Height Maps 0 Answers

How to avoid Texture.Apply() 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