Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to make gradient editor for shader?

Discussion in 'Shaders' started by dreamerflyer, May 28, 2014.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Hi all, particle system can not get the color life time by code,So I want to add gradient editor value for shader ,How can get it?
    Thanks advance!
     

    Attached Files:

    • $col.png
      $col.png
      File size:
      125.8 KB
      Views:
      1,318
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Shaders don't take gradients as inputs. You might be able to get a MaterialPropertyDrawer to do what you want, but I don't have experience with those and I assume it's a lot of work.
     
  3. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    yes ,i want to know how make the gradient in MaterialPropertyDrawer
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,447
    There is no API exposed to render such gradient UI. You could use Reflection though, the internal methods are called EditorGUI.GradientField and EditorGUILayout.GradientField .
     
  5. ryo0ka

    ryo0ka

    Joined:
    Sep 27, 2015
    Posts:
    37
    Hello, this is an old thread but just in case someone came across:

    You can (kind of) achieve your workflow: using a Gradient as a shader parameter -- by generating a one-pixel-height 2D texture asset out of your Gradient and passing it to your material's texture property, which you can automate by creating your own script as either MonoBehavior or ScriptableObject.

    I don't have a code here, but I've made a script like that before. Essentially you need to know how to (1) read a Gradient and convert it into a 2D texture, (2) create a 2D texture asset in the project, (3) hook the asset into the material's texture property and (4) write a Editor script to show a button in the script's inspector to do that.

    My point is that the workflow is definitely possible with some overhead in setting up the tool to do so. I hope this helps.
     
  6. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    245

    Attached Files:

    FardinHaque likes this.
  7. B33bo_Astro

    B33bo_Astro

    Joined:
    May 10, 2020
    Posts:
    4
    Stuff like this should just be a thing anyway why do I have to write it myself