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 draco_nite · Sep 20, 2017 at 12:51 AM · shaderstexture2dprocedural-generationnoiseaddon

How do I get the noise from a shader generated from an addon to apply to a Texture2d?

I'm probably asking this question wrong. I'm using Turbulence Library to generate noise as shaders. What I want to do is take the noise generated by these shaders and apply them to Texture2Ds that I'm procedurally generating.

What I want to do is take the value of each pixel, then while procedurally generating a texture, use to determine how much I put another color "on top of" another color in a procedurally generated mesh. E.G. This

Solid color becomes this Solid color with noise overlay

I strongly suspect that I will just have to write my own shader from scratch, but is there no way to just take noise from a shader and apply it to a Texture2D so I can continue to use the Standard shader?

exampletex.png (1.9 kB)
exampletex2.png (144.2 kB)
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
0

Answer by IndievdB · Sep 20, 2017 at 05:36 AM

If you want to turn the shader into a texture, create a material from the noise shader. Next, create a custom texture by "Create > Custom Texture". Set the Intialization Mode to "OnLoad", set the Source to "Material" and set the Material to the noise shader material you just created. You might need to switch the UpdateMode off and on of "OnLoad" to get this to work. This will get you a texture from your shader, but it is a little unstable. Unfortunately, you can't use Graphics.Blit to get your texture because Turbulence uses surface shaders rather than fragment shaders.

I actually suggest modifying their shader or writing your own though. Things to keep in mind when you are modifying their shaders:

1) Add a property for Base Texture and Color Overlay in the shader properties. This will allow you to set these variables in the inspector or through code:

 Properties 
 {
     _Base ("Base Texture", 2D) = "" {}
     _Overlay ("Overlay Color", Color) = (1, 1, 1, 1)
 
     _Octaves ("Octaves", Float) = 8.0
     _Frequency ("Frequency", Float) = 1.0
     _Amplitude ("Amplitude", Float) = 1.0
     _Lacunarity ("Lacunarity", Float) = 1.92
     _Persistence ("Persistence", Float) = 0.8
     _Offset ("Offset", Vector) = (0.0, 0.0, 0.0, 0.0)
 }

2) Further in the shader, you will find a SubShader section where the variable names are repeated. Add your variables to this. This is so that Unity knows to send the inspector variables to the CG program:

 sampler2D _Base;
 fixed4 _Overlay;
 
 fixed _Octaves;
 float _Frequency;
 float _Amplitude;
 float2 _Offset;
 float _Lacunarity;
 float _Persistence;

Lastly you'll need to modify the surf function. This function takes any UVs or data you need as input, and fills in output structure SurfaceOutput. It is called for every pixel that you see. Here is how an example on their Perlin shader:

 void surf (Input IN, inout SurfaceOutput o) 
 {
     // h is a randomly generated noise value for this pixel.
     // Normally, turbulance uses h as the color value of the pixel.
     float h = PerlinNormal(IN.pos.xy, _Octaves, _Offset, _Frequency, _Amplitude, _Lacunarity, _Persistence);
             
     // We will use h as the blend value between our base texture and our overlay color
     // tex2D (_Base, IN.pos) gets the color of our texture at this pixel
     // lerp interpolates for us
     float4 c = lerp( tex2D (_Base, IN.pos), _Overlay, h);
 
     o.Albedo = c.rgb;
     o.Alpha = 1.0;
 }

This got me something like this:

alt text


example.png (101.1 kB)
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

80 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

Related Questions

Compute Shader Outputting Black 0 Answers

What is the best way to draw a 2D sine wave? 3 Answers

2D sprite - jelly, squeeze, squash 0 Answers

Sample Texture2dArray in vertex shader 1 Answer

How can I access a texture created through C# code (using Texture2D) in a unity shader as a sampler2D? 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