Search Unity

(Solved) Modifying default shaders

Discussion in 'Universal Render Pipeline' started by Milgiray, Jan 25, 2021.

  1. Milgiray

    Milgiray

    Joined:
    Mar 11, 2017
    Posts:
    16
    Hello, I need to copy and modify default URP shader just to add some new properties.
    But there is one problem: default shaders use Custom Shader GUI, so I have trouble displaying the new properties.

    I tried to copy and modify Custom GUI scripts, but I can't use SavedBool class, seems like it is a part of the internal Unity API.

    Is there any other way to make it work? I just need to add some properties to the Unlit Particle shader while preserving default shader settings functionality, and it doesn't really matter how exactly these properties will be displayed.
     
  2. Milgiray

    Milgiray

    Joined:
    Mar 11, 2017
    Posts:
    16
    Okay, it was easier than I thought.
    Here is example how you can add properties to the default shaders by modifying their CustomGUI script.

    [These 3x //IMPORTANT lines are all what you need to display one property in Surface Inputs]
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEditor.Rendering.Universal.ShaderGUI;
    5. using UnityEngine;
    6.  
    7. namespace SomeNamespace
    8. {
    9.     internal class ParticlesUnlitShader : BaseShaderGUI
    10.     {
    11.         private BakedLitGUI.BakedLitProperties shadingModelProperties;
    12.         private ParticleGUI.ParticleProperties particleProps;
    13.  
    14.         private MaterialProperty SomeProperty; //IMPORTANT
    15.  
    16.         List<ParticleSystemRenderer> m_RenderersUsingThisMaterial = new List<ParticleSystemRenderer>();
    17.  
    18.         public override void FindProperties(MaterialProperty[] properties)
    19.         {
    20.             base.FindProperties(properties);
    21.             shadingModelProperties = new BakedLitGUI.BakedLitProperties(properties);
    22.             particleProps = new ParticleGUI.ParticleProperties(properties);
    23.  
    24.             SomeProperty = FindProperty("_SomeProperty", properties); //IMPORTANT
    25.         }
    26.  
    27.         //...
    28.         //MaterialChanged
    29.         //DrawSurfaceOptions
    30.         //...
    31.  
    32.         public override void DrawSurfaceInputs(Material material)
    33.         {
    34.             base.DrawSurfaceInputs(material);
    35.             BakedLitGUI.Inputs(shadingModelProperties, materialEditor);
    36.             DrawEmissionProperties(material, true);
    37.  
    38.             materialEditor.FloatProperty(SomeProperty, "Some Property Name Visible In Editor"); //IMPORTANT
    39.         }
    40.  
    41.         //...
    42.         //DrawAdvancedOptions
    43.         //OnOpenGUI
    44.         //CacheRenderersUsingThisMaterial
    45.     }
    46. }
     
  3. patrichuang

    patrichuang

    Joined:
    Dec 4, 2020
    Posts:
    1
    i have the same problem..
    So whats exactly the reason why we cant use SavedBool class?