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
1
Question by weltraumimport · Aug 26, 2020 at 11:06 AM · shaderstexture2dgradientcel shading

Shader Graph: how to convert gradient node into a texture

Is there a way to sample a gradient node into a texture? I want to use the Unity gradient editor to create a ramp texture for my cel shader somehow, but i can't figure out how to do it properly. Anyone has any idea? Thank you

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 BronsonBrad · Jan 19, 2021 at 09:26 PM 0
Share

Ah I figured it out, if you haven't cracked it yet. Are you using a custom lighting set up? If so, you can take the Diffuse output node from that (assu$$anonymous$$g there is one) and using the Colorspace Conversion node, turn it from RGB to HSV. Then, a split node. Plug the R and G channels in to a Combine node, but for the B channel plug in a Sample Gradient node (where you can edit the gradient instead of using a texture). Now use another Colorspace Conversion to chang from HSV back to RGB, multiply this with the custom lighting color. Do the same for specular.

Hope this helps!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Namey5 · Aug 26, 2020 at 12:02 PM

You could render straight into a texture, but rather than doing that you could also do the same with the regular gradient editor through script;

 using System.IO;
 
 ...
 
 [SerializeField] private string m_TextureName = "Gradient";
 [SerializeField] private Gradient m_Gradient = new Gradient ();
 [SerializeField] private int m_Resolution = 256;
 
 ...
 
 public void SaveGradient ()
 {
     Texture2D tex = new Texture2D (m_Resolution, 1);
     for (int i = 0; i < m_Resolution; i++)
         tex.SetPixel (i, 0, m_Gradient.Evaluate (i / (float)m_Resolution));
     tex.Apply ();
 
     byte[] data = tex.EncodeToPNG ();
     File.WriteAllBytes (string.Format ("{0}/{1}.png", Application.dataPath, m_TextureName), data);
 }

Something along those lines - this should save a texture called [m_TextureName].png in the assets folder.

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

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

How to create a shader for a dynamic linear gradient 0 Answers

Retrieving information from texture not working in shader graph 0 Answers

What vertex shader should I be using? 0 Answers

Is the Toon Lit Outline shader hard on mobile? 0 Answers

Texture coordinates in shader are negative 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