Search Unity

I need Help With Shaders

Discussion in 'Scripting' started by Mortalanimal, Dec 31, 2019.

  1. Mortalanimal

    Mortalanimal

    Joined:
    Jun 7, 2014
    Posts:
    567
    Hi guys, So I wanted to make a Dial on my tank to show the CD, I didnt want to use GUI for a reason I dont really want to get into atm. So what was Suggested to me, was to use shaders and use alpha masking to make part of my material Selection Dial invisible.

    After 1-2 weeks of me banging my head against the wall, I finally made this work with the help of an asset named "Advanced Dissolve". I use one of its shaders along side a material of my own to mask the dial.

    It finally worked and I was so happy, Only to notice that this was getting applied to all my RTS units using the same shader....



    Now I have come across this before with a different asset, however, that asset also came with a script to manipulate the alpha (no masking), and it only effected that individual Shader that had the script attached to it and not all the other units, ofc, even in that case, if i had manipulated the shader directly, it would have effected all the units with that shader.

    So I did some research and I cam across this post:
    http://thomasmountainborn.com/2016/05/25/materialpropertyblocks/

    This suggests that if I use [PerRendererData] before the shader properties, it would do exactly what I need. and just to be sure, I added this to every single property. but it didnt work.

    Code (CSharp):
    1. Properties
    2.     {
    3.      
    4.         _MainTex ("Sprite Texture", 2D) = "white" {}
    5.         _Color ("Tint", Color) = (1,1,1,1)
    6.      
    7.         _StencilComp ("Stencil Comparison", Float) = 8
    8.         _Stencil ("Stencil ID", Float) = 0
    9.         _StencilOp ("Stencil Operation", Float) = 0
    10.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    11.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    12.  
    13.         _ColorMask ("Color Mask", Float) = 15
    14.         _ClipRect ("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
    15.  
    16.         [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
    17.  
    18.  
    19.  
    20.         //[HideInInspector] _DissolveCutoff("Dissolve", Range(0,1)) = 0.25 //why is there 2 of these here? //this one is tottally here in error
    21.                
    22.            
    23.         //Advanced Dissolve
    24.         [PerRendererData] _DissolveCutoff("Dissolve", Range(0,1)) = 0.25 // I should probabaly [PerRendererData], however this isnt working
    25.      
    26.         //Mask
    27.         [PerRendererData][KeywordEnum(None, XYZ Axis, Plane, Sphere, Box, Cylinder, Cone)]  _DissolveMask("Mak", Float) = 0
    28.         [PerRendererData][Enum(X,0,Y,1,Z,2)]                                                _DissolveMaskAxis("Axis", Float) = 0
    29.         [PerRendererData][Enum(World,0,Local,1)]                                            _DissolveMaskSpace("Space", Float) = 0  
    30.         [PerRendererData]                                                                   _DissolveMaskOffset("Offset", Float) = 0
    31.         [PerRendererData]                                                                   _DissolveMaskInvert("Invert", Float) = 1      
    32.         [PerRendererData][KeywordEnum(One, Two, Three, Four)]                               _DissolveMaskCount("Count", Float) = 0      
    33.  
    34.         [PerRendererData]  _DissolveMaskPosition("", Vector) = (0,0,0,0)
    35.         [PerRendererData]  _DissolveMaskNormal("", Vector) = (1,0,0,0)
    36.         [PerRendererData]  _DissolveMaskRadius("", Float) = 1
    37.  
    38.         //Alpha Source   //What I want to change is here
    39.         [PerRendererData] [KeywordEnum(Main Map Alpha, Custom Map, Two Custom Maps, Three Custom Maps)] _DissolveAlphaSource("Alpha Source", Float) = 0
    40.         [PerRendererData] _DissolveMap1("", 2D) = "white" { }
    41.         [PerRendererData] [UVScroll] _DissolveMap1_Scroll("", Vector) = (0,0,0,0)
    42.         [PerRendererData] _DissolveMap1Intensity("", Range(0, 1)) = 1
    43.         [PerRendererData] [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)] _DissolveMap1Channel("", INT) = 3
    44.         [PerRendererData] _DissolveMap2("", 2D) = "white" { }
    45.         [PerRendererData] [UVScroll] _DissolveMap2_Scroll("", Vector) = (0,0,0,0)
    46.         [PerRendererData] _DissolveMap2Intensity("", Range(0, 1)) = 1
    47.         [PerRendererData] [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)] _DissolveMap2Channel("", INT) = 3
    48.         [PerRendererData] _DissolveMap3("", 2D) = "white" { }
    49.         [PerRendererData] [UVScroll] _DissolveMap3_Scroll("", Vector) = (0,0,0,0)
    50.         [PerRendererData] _DissolveMap3Intensity("", Range(0, 1)) = 1
    51.         [PerRendererData] [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)] _DissolveMap3Channel("", INT) = 3
    52.  
    53.         [PerRendererData][Enum(Multiply, 0, Add, 1)]  _DissolveSourceAlphaTexturesBlend("Texture Blend", Float) = 0
    54.         [PerRendererData]                              _DissolveNoiseStrength("Noise", Float) = 0.1
    55.         [PerRendererData][Enum(UV0,0,UV1,1)]          _DissolveAlphaSourceTexturesUVSet("UV Set", Float) = 0
    56.  
    57.         [PerRendererData][KeywordEnum(Normal, Triplanar, Screen Space)] _DissolveMappingType("Triplanar", Float) = 0
    58.         [PerRendererData][Enum(World,0,Local,1)]                        _DissolveTriplanarMappingSpace("Mapping", Float) = 0  
    59.         [PerRendererData]                                               _DissolveMainMapTiling("", FLOAT) = 1  
    60.  
    61.         //Edge
    62.         [PerRendererData]                                       _DissolveEdgeWidth("Edge Size", Range(0,1)) = 0.25
    63.         [PerRendererData][Enum(Cutout Source,0,Main Map,1)]     _DissolveEdgeDistortionSource("Distortion Source", Float) = 0
    64.         [PerRendererData]                                       _DissolveEdgeDistortionStrength("Distortion Strength", Range(0, 2)) = 0
    65.  
    66.         //Color
    67.         [PerRendererData]                _DissolveEdgeColor("Edge Color", Color) = (0,1,0,1)
    68.         [PerRendererData][PositiveFloat] _DissolveEdgeColorIntensity("Intensity", FLOAT) = 0
    69.         [PerRendererData][Enum(Solid,0,Smooth,1, Smooth Squared,2)]      _DissolveEdgeShape("Shape", INT) = 0
    70.  
    71.         [PerRendererData][KeywordEnum(None, Gradient, Main Map, Custom)] _DissolveEdgeTextureSource("", Float) = 0
    72.         [PerRendererData][NoScaleOffset]                                 _DissolveEdgeTexture("Edge Texture", 2D) = "white" { }
    73.         [PerRendererData][Toggle]                                         _DissolveEdgeTextureReverse("Reverse", FLOAT) = 0
    74.         [PerRendererData]                                                 _DissolveEdgeTexturePhaseOffset("Offset", FLOAT) = 0
    75.         [PerRendererData]                                                 _DissolveEdgeTextureAlphaOffset("Offset", Range(-1, 1)) = 0  
    76.         [PerRendererData]                                                 _DissolveEdgeTextureMipmap("", Range(0, 10)) = 1      
    77.         [PerRendererData][Toggle]                                         _DissolveEdgeTextureIsDynamic("", Float) = 0
    78.  
    79.         [PerRendererData][PositiveFloat] _DissolveGIMultiplier("GI Strength", Float) = 1  
    80.      
    81.         //Global
    82.         [PerRendererData][KeywordEnum(None, Mask Only, Mask And Edge, All)] _DissolveGlobalControl("Global Controll", Float) = 0
    83.  
    84.         //Meta
    85.         [PerRendererData] _Dissolve_ObjectWorldPos("", Vector) = (0,0,0,0)      
    86.     }

    please help, I only started programming about 3 months ago, and shaders is just too much for me lol