Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sprite Shader with GreyScale

Discussion in 'Shaders' started by RChrispy, Jan 15, 2014.

  1. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    Hey Guys,

    I am new to shading but somehow managed to acomplish this for the new 2D Sprite system of Unity.
    You can use sliders to control the grayscalevalue :)

    If someone needs grayscale for his textures there you go: :)

    Code (csharp):
    1. Shader "Sprites/GrayScale"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    8.         _EffectAmount ("Effect Amount", Range (0, 1)) = 1.0
    9.     }
    10.  
    11.     SubShader
    12.     {
    13.         Tags
    14.         {
    15.             "Queue"="Transparent"
    16.             "IgnoreProjector"="True"
    17.             "RenderType"="Transparent"
    18.             "PreviewType"="Plane"
    19.             "CanUseSpriteAtlas"="True"
    20.         }
    21.  
    22.         Cull Off
    23.         Lighting Off
    24.         ZWrite Off
    25.         Fog { Mode Off }
    26.         Blend SrcAlpha OneMinusSrcAlpha
    27.  
    28.         Pass
    29.         {
    30.         CGPROGRAM
    31.             #pragma vertex vert
    32.             #pragma fragment frag
    33.             #pragma multi_compile DUMMY PIXELSNAP_ON
    34.             #include "UnityCG.cginc"
    35.            
    36.             struct appdata_t
    37.             {
    38.                 float4 vertex   : POSITION;
    39.                 float4 color    : COLOR;
    40.                 float2 texcoord : TEXCOORD0;
    41.             };
    42.  
    43.             struct v2f
    44.             {
    45.                 float4 vertex   : SV_POSITION;
    46.                 fixed4 color    : COLOR;
    47.                 half2 texcoord  : TEXCOORD0;
    48.             };
    49.            
    50.             fixed4 _Color;
    51.  
    52.             v2f vert(appdata_t IN)
    53.             {
    54.                 v2f OUT;
    55.                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    56.                 OUT.texcoord = IN.texcoord;
    57.                 OUT.color = IN.color * _Color;
    58.                 #ifdef PIXELSNAP_ON
    59.                 OUT.vertex = UnityPixelSnap (OUT.vertex);
    60.                 #endif
    61.  
    62.                 return OUT;
    63.             }
    64.  
    65.             sampler2D _MainTex;
    66.             uniform float _EffectAmount;
    67.  
    68.             fixed4 frag(v2f IN) : COLOR
    69.             {
    70.                 half4 texcol = tex2D (_MainTex, IN.texcoord);              
    71.                 texcol.rgb = lerp(texcol.rgb, dot(texcol.rgb, float3(0.3, 0.59, 0.11)), _EffectAmount);
    72.                 texcol = texcol * IN.color;
    73.                 return texcol;
    74.             }
    75.         ENDCG
    76.         }
    77.     }
    78.     Fallback "Sprites/Default"
    79. }
    80.  
    If you want to change things threw code use this:

    Code (csharp):
    1. _GAMEOBJECT_.renderer.material.SetFloat("_EffectAmount", 0.5f);
    Cheers :)
     
    Last edited: Jan 15, 2014
  2. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    ##EDIT##

    fixed it with:

    Code (csharp):
    1. texcol = texcol * IN.color;
     
    Last edited: Jan 15, 2014
    NguyenLuan likes this.
  3. xenonsin

    xenonsin

    Joined:
    Dec 12, 2013
    Posts:
    20
    This is great! I'm wondering though if it's possible to modify the code so that parts of the original color gets permanently revealed based on a circle around some coordinates? Similar to how a fog of war shader would work, I would imagine?


    Similar to this: http://codepen.io/cwolves/pen/prvnb
     
    RChrispy likes this.
  4. emisael-carrera

    emisael-carrera

    Joined:
    May 2, 2014
    Posts:
    6
    Thanks a lot Dev6_RC, I was using a shader that was working well on unity editor, but on android the shader was broken, I don't know why, but the yours worked really good! Thank you a lot! :)
     
    RChrispy likes this.
  5. mohhad

    mohhad

    Joined:
    Jul 30, 2014
    Posts:
    7
    Cheers Bro. Great work.
     
  6. kUr4m4

    kUr4m4

    Joined:
    May 14, 2013
    Posts:
    7
    This is really awesome! But I would like to have the same shader effect on regular textures but I'm really bad at shaders...anyone have any clue?
     
  7. azmundai

    azmundai

    Joined:
    Jun 21, 2010
    Posts:
    26
    This is very cool and works great, but it doesn't seem to work with masking in the UI. I applied a material with this shader to a sprite on my canvas with a mask on top of it .. and the grayscale texture doesnt get masked. If I change material to none it masks just fine. Is this something that can be added?
     
  8. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    I am sorry, but I have no time ATM. If i had to guess: this shader is based on the Unity sprites shader ( with some modifications ) You could try to look into the base shader of the unity UI system and add the required features into this one. If you do so feel free to post it here! :) Help the Community! :D
     
  9. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Wow! You are awesome!
     
  10. obilang

    obilang

    Joined:
    Feb 1, 2015
    Posts:
    5
    That helped me a lot~ Thank you!
     
  11. vinipc

    vinipc

    Joined:
    Jun 21, 2013
    Posts:
    8
    Thanks, this was really helpful.
    However, as noted by azmundai, it doesn't work with Unity UI's Image, so I used your shader to modify Unity's default shader and came up with this:


    Code (CSharp):
    1. Shader "Grayscale"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.      
    8.         _StencilComp ("Stencil Comparison", Float) = 8
    9.         _Stencil ("Stencil ID", Float) = 0
    10.         _StencilOp ("Stencil Operation", Float) = 0
    11.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    12.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    13.  
    14.         _ColorMask ("Color Mask", Float) = 15
    15.         _GrayscaleAmount ("Grayscale Amount", Range (0, 1)) = 1.0
    16.  
    17.         [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
    18.     }
    19.  
    20.     SubShader
    21.     {
    22.         Tags
    23.         {
    24.             "Queue"="Transparent"
    25.             "IgnoreProjector"="True"
    26.             "RenderType"="Transparent"
    27.             "PreviewType"="Plane"
    28.             "CanUseSpriteAtlas"="True"
    29.         }
    30.      
    31.         Stencil
    32.         {
    33.             Ref [_Stencil]
    34.             Comp [_StencilComp]
    35.             Pass [_StencilOp]
    36.             ReadMask [_StencilReadMask]
    37.             WriteMask [_StencilWriteMask]
    38.         }
    39.  
    40.         Cull Off
    41.         Lighting Off
    42.         ZWrite Off
    43.         ZTest [unity_GUIZTestMode]
    44.         Blend SrcAlpha OneMinusSrcAlpha
    45.         ColorMask [_ColorMask]
    46.  
    47.         Pass
    48.         {
    49.         CGPROGRAM
    50.             #pragma vertex vert
    51.             #pragma fragment frag
    52.  
    53.             #include "UnityCG.cginc"
    54.             #include "UnityUI.cginc"
    55.  
    56.             #pragma multi_compile __ UNITY_UI_ALPHACLIP
    57.          
    58.             struct appdata_t
    59.             {
    60.                 float4 vertex   : POSITION;
    61.                 float4 color    : COLOR;
    62.                 float2 texcoord : TEXCOORD0;
    63.             };
    64.  
    65.             struct v2f
    66.             {
    67.                 float4 vertex   : SV_POSITION;
    68.                 fixed4 color    : COLOR;
    69.                 half2 texcoord  : TEXCOORD0;
    70.                 float4 worldPosition : TEXCOORD1;
    71.             };
    72.          
    73.             fixed4 _Color;
    74.             fixed4 _TextureSampleAdd;
    75.             float4 _ClipRect;
    76.             uniform float _GrayscaleAmount;
    77.  
    78.             v2f vert(appdata_t IN)
    79.             {
    80.                 v2f OUT;
    81.                 OUT.worldPosition = IN.vertex;
    82.                 OUT.vertex = mul(UNITY_MATRIX_MVP, OUT.worldPosition);
    83.  
    84.                 OUT.texcoord = IN.texcoord;
    85.              
    86.                 #ifdef UNITY_HALF_TEXEL_OFFSET
    87.                 OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
    88.                 #endif
    89.              
    90.                 OUT.color = IN.color * _Color;
    91.                 return OUT;
    92.             }
    93.  
    94.             sampler2D _MainTex;
    95.  
    96.             fixed4 frag(v2f IN) : SV_Target
    97.             {
    98.                 half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
    99.              
    100.                 color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
    101.                 color.rgb = lerp(color.rgb, dot(color.rgb, float3(0.3, 0.59, 0.11)), _GrayscaleAmount);
    102.              
    103.                 #ifdef UNITY_UI_ALPHACLIP
    104.                 clip (color.a - 0.001);
    105.                 #endif
    106.  
    107.                 return color;
    108.             }
    109.         ENDCG
    110.         }
    111.     }
    112. }
    113.  
    Hope it helps!
     

    Attached Files:

  12. DungDajHjep

    DungDajHjep

    Joined:
    Mar 25, 2015
    Posts:
    201
    Thanks you it's Great !. Work on Android, tested !
     
  13. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    Nice! Everything that helps improving this shader and unity itself is appriciated! :)
     
  14. CtrlZzzz

    CtrlZzzz

    Joined:
    Aug 18, 2013
    Posts:
    2
    Waow guys, it's awesome ! Thank you very much for these two Grey Scale shader scripts.
    There are very useful !
     
  15. Cuisor

    Cuisor

    Joined:
    Feb 19, 2015
    Posts:
    4
    Thanks, this was really helpfull.
     
  16. harleywinks

    harleywinks

    Joined:
    Nov 14, 2014
    Posts:
    7
    Just what I needed! Thanks @Dev6_RC!

    FUN FACT: I was curious about the magic vector (0.3, 0.59, 0.11) in this line:

    Code (cg):
    1. color.rgb= lerp(color.rgb, dot(color.rgb, float3(0.3, 0.59, 0.11)), _GrayscaleAmount);
    ...they're saying something like "make the grayscale whiteness value of a color 0.3R + 0.59G + 0.11B" but where do those coefficients come from? I looked it up and it seems they come from the NTSC TV standard/the way human eyes work: ~60% of perceived luminosity comes from green, ~30% from red, ~10% from blue.
     
    SaturnusK1 likes this.
  17. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    Hey harleywinks :) Thanks for your kind reply!
    This happened a long time ago, but if I remember corectly this was the base Vector unity used in it's Sprite Shader. I used it to modify the color so the "real" Color and the "Grayscaled" Color look best :)
     
  18. sfilo

    sfilo

    Joined:
    Oct 23, 2012
    Posts:
    30
    I was just beginning to look into grayscale sprites. This made my life a lot easier. Thank you!
     
  19. dasm30

    dasm30

    Joined:
    Jun 27, 2013
    Posts:
    6
    Helloo, so no warnings, but GrayscaleAmount is not working, the image/sprite always looks gray.
     
  20. Link538

    Link538

    Joined:
    Jan 25, 2013
    Posts:
    15
    I made a Sprite/Diffuse version from the builtin shader & the grayscale version:

    Code (CSharp):
    1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
    2.  
    3. Shader "Sprites/GrayScale"
    4. {
    5.     Properties
    6.     {
    7.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    8.         _Color ("Tint", Color) = (1,1,1,1)
    9.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    10.         [HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
    11.         [HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
    12.         [PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
    13.         [PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
    14.         _EffectAmount ("Effect Amount", Range (0, 1)) = 1.0
    15.     }
    16.  
    17.     SubShader
    18.     {
    19.         Tags
    20.         {
    21.             "Queue"="Transparent"
    22.             "IgnoreProjector"="True"
    23.             "RenderType"="Transparent"
    24.             "PreviewType"="Plane"
    25.             "CanUseSpriteAtlas"="True"
    26.         }
    27.  
    28.         Cull Off
    29.         Lighting Off
    30.         ZWrite Off
    31.         Blend One OneMinusSrcAlpha
    32.  
    33.         CGPROGRAM
    34.         #pragma surface surf Lambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing
    35.         #pragma multi_compile _ PIXELSNAP_ON
    36.         #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
    37.         #include "UnitySprites.cginc"
    38.  
    39.         struct Input
    40.         {
    41.             float2 uv_MainTex;
    42.             fixed4 color;
    43.         };
    44.        
    45.         void vert (inout appdata_full v, out Input o)
    46.         {
    47.             v.vertex.xy *= _Flip.xy;
    48.  
    49.             #if defined(PIXELSNAP_ON)
    50.             v.vertex = UnityPixelSnap (v.vertex);
    51.             #endif
    52.            
    53.             UNITY_INITIALIZE_OUTPUT(Input, o);
    54.             o.color = v.color * _Color * _RendererColor;
    55.         }
    56.         uniform float _EffectAmount;
    57.  
    58.         void surf (Input IN, inout SurfaceOutput o)
    59.         {
    60.             fixed4 c = SampleSpriteTexture (IN.uv_MainTex) * IN.color;
    61.             c.rgb = lerp(c.rgb, dot(c.rgb, float3(0.3, 0.59, 0.11)), _EffectAmount);
    62.             o.Albedo = c.rgb * c.a;
    63.             o.Alpha = c.a;
    64.         }
    65.         ENDCG
    66.     }
    67.  
    68. Fallback "Sprite/Diffuse"
    69. }
    70.  
     
    wmadwand and oharinth like this.
  21. mitdave95

    mitdave95

    Joined:
    Jun 17, 2016
    Posts:
    3
    Any idea how to apply different grayscale amount to multiple sprites?
     
  22. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Assign the material to the sprite at runtime, which will create a material instance.

    Add the [PerRendererData] attribute to the _EffectAmount property in the shader, then you can change each sprite at runtime without instantiating the material:
    Code (CSharp):
    1. public float effectAmount;
    2.  
    3. private MaterialPropertyBlock propertyBlock;
    4. private SpriteRenderer spriteRenderer;
    5.  
    6. private void Awake()
    7. {
    8.     spriteRenderer = GetComponent<SpriteRenderer>();
    9.     propertyBlock = new MaterialPropertyBlock();
    10. }
    11.  
    12. private void Start()
    13. {
    14.     if(spriteRenderer != null)
    15.     {
    16.         spriteRenderer.GetPropertyBlock(propertyBlock);
    17.         propertyBlock.SetFloat("_EffectAmount", effectAmount);
    18.         spriteRenderer.SetPropertyBlock(propertyBlock);
    19.     }
    20. }
     
    Last edited: Jun 21, 2017
  23. ZNTerror

    ZNTerror

    Joined:
    Oct 22, 2014
    Posts:
    1
    You can use a MaterialPropertyBlock to change indivual instances without instancing the material multiple times.
     
    LiterallyJeff likes this.
  24. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    That's true. You'll also need to give the "_EffectAmount" the [PerRendererData] attribute I believe. I'll edit my example for that method since it's definitely better.
     
  25. lexi89puzzle

    lexi89puzzle

    Joined:
    Feb 22, 2017
    Posts:
    10
    This is awesome. Using it in a live game now! Thank you
     
    RChrispy likes this.
  26. mjunaidch

    mjunaidch

    Joined:
    Oct 23, 2016
    Posts:
    7
    RChrispy likes this.
  27. Meatb0y

    Meatb0y

    Joined:
    Jan 25, 2015
    Posts:
    43
    Thanks ! You save me a lot of time :)
     
    RChrispy likes this.
  28. GilbertoBitt

    GilbertoBitt

    Joined:
    May 27, 2013
    Posts:
    111
    Since the release of shader graph I want to convert this shader to shader graph and if nescessary create the missing nodes. To all grayscale versions the r here even for the albedo.
     
  29. Niloy

    Niloy

    Joined:
    Mar 19, 2016
    Posts:
    10
    I was trying this one and I am trying to change the _GrayscaleAmount in an Update function....But it doesn't update....the value changes on the material [I checked it on the inspector] but the UI image stays the same....the change happens when I disable and enable the object on which the material is attached to.

    Any solution would be really helpful please. :)
     
  30. Sciman101

    Sciman101

    Joined:
    Jan 7, 2014
    Posts:
    7
    Ah, thank you so much! I've been looking for the vertex/fragment functions for a sprite shader for a while now, maybe I'm just clueless and couldn't find them, but either way this is a huge help :D
     
    RChrispy likes this.
  31. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    Glad we could help so many guys out! :)
     
  32. Doborog

    Doborog

    Joined:
    Nov 14, 2018
    Posts:
    1
    +1 thank you! Great stuff. :D
     
    RChrispy likes this.
  33. mayurapositiveinfotech

    mayurapositiveinfotech

    Joined:
    May 8, 2019
    Posts:
    2
    Hello, Can anyone please help me for UI masking support on this shader?
    As I am not able to mask my image. I tried other shader too but not getting instant reflection on image at runtime.
    So I must have to use this shader.!
     

    Attached Files:

  34. mayurapositiveinfotech

    mayurapositiveinfotech

    Joined:
    May 8, 2019
    Posts:
    2
    Hello If anyone here looking for gray scale shader with masking support then here you go...
    Just create material in Assets\Resources\Materials\GrayscaleEffect.mat
    then apply grayscaleffectapplier on image gameobject
    Thank me later.. :)
     

    Attached Files:

    DryreL likes this.
  35. joostbos

    joostbos

    Joined:
    Feb 4, 2015
    Posts:
    63
    I have a scene where I want to dim the lights and I noticed that the default sprite shader was emitting light and thus lighting my objects. I was hoping this shader would fix that, but I see that this shader also still emits light.

    Can anyone explain why this is and where I can fix this (for 3d materials I know that there is a property emission)? Or point me to a sprite material or shader that does not emit light?
     
    ryzeonline likes this.
  36. Masea1

    Masea1

    Joined:
    Jun 9, 2018
    Posts:
    41
    Is this no more working?
     
  37. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    Doesnt work in my 2019, can some one fix it?

    I've found this on web, it works but lacking alpha control... I have no idea how to fix it, so can anyone take a look?
    Code (csharp):
    1.  
    2. Shader "Unity3dTips/GrayscaleTransparent" {
    3.    Properties{
    4.      _MainTex("Texture", 2D) = "white" {}
    5.      _Color("Color", Color) = (1,1,1,1)
    6.    }
    7.        SubShader{
    8.          GrabPass { "_BackgroundTexture" }
    9.  
    10.          Pass {
    11.            Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
    12.            ZWrite Off
    13.            ZTest Off
    14.            CGPROGRAM
    15.            #pragma vertex vert
    16.            #pragma fragment frag
    17.            #include "UnityCG.cginc"
    18.            sampler2D _BackgroundTexture;
    19.            sampler2D _MainTex;
    20.            fixed4 _MainTex_ST;
    21.  
    22.            struct v2f
    23.            {
    24.              fixed4 vertex : SV_POSITION;
    25.              fixed4 grabUV : TEXCOORD1;
    26.            };
    27.  
    28.            struct appdata
    29.            {
    30.              fixed4 vertex : POSITION;
    31.            };
    32.  
    33.            v2f vert(appdata v)
    34.            {
    35.              v2f o;
    36.              o.vertex = UnityObjectToClipPos(v.vertex);
    37.              o.grabUV = ComputeGrabScreenPos(o.vertex);
    38.              return o;
    39.            }
    40.  
    41.            fixed4 frag(v2f i) : SV_Target
    42.            {
    43.              fixed4 bgc = tex2Dproj(_BackgroundTexture, i.grabUV);
    44.              return (bgc.r + bgc.g + bgc.b) / 3;
    45.            }
    46.  
    47.            ENDCG
    48.          }
    49.      }
    50.          FallBack Off
    51. }
    52.  
     
    Last edited: May 6, 2020
  38. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    78
    Wow amazing! I was looking for such shader. It works great, thanks! I'm going to use this for mobile. I wonder if it has major performance effect for low-end mobile devices.
     
  39. DryreL

    DryreL

    Joined:
    Feb 23, 2020
    Posts:
    49
    Thanks, it works. But effect amount doesn't work...
     
  40. absurdnoize

    absurdnoize

    Joined:
    Nov 23, 2019
    Posts:
    10
    This is really useful, thank you very much!
     
  41. Rodlaiz

    Rodlaiz

    Joined:
    Jul 30, 2013
    Posts:
    38
    For all of you guys looking for the alpha control, I've modified the shader a bit so the alpha will control the amount of the greyscale effect:

    Code (CSharp):
    1. Shader "UI/GrayscaleTransparent"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Texture", 2D) = "white" {}
    6.         _Color("Color", Color) = (1,1,1,1)
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         GrabPass { "_BackgroundTexture" }
    12.  
    13.         Pass
    14.         {
    15.             Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
    16.  
    17.             ZWrite Off
    18.             Blend SrcAlpha OneMinusSrcAlpha
    19.             ZTest Off
    20.  
    21.             CGPROGRAM
    22.             #pragma vertex vert
    23.             #pragma fragment frag
    24.             #include "UnityCG.cginc"
    25.             sampler2D _BackgroundTexture;
    26.             sampler2D _MainTex;
    27.             fixed4 _MainTex_ST;
    28.             fixed4 _Color;
    29.  
    30.             struct v2f
    31.             {
    32.                 fixed4 vertex : SV_POSITION;
    33.                 fixed4 color : COLOR;
    34.                 fixed4 grabUV : TEXCOORD1;
    35.             };
    36.  
    37.             struct appdata
    38.             {
    39.                 fixed4 vertex : POSITION;
    40.                 fixed4 color : COLOR;
    41.             };
    42.  
    43.             v2f vert(appdata v)
    44.             {
    45.                 v2f o;
    46.                 o.vertex = UnityObjectToClipPos(v.vertex);
    47.                 o.grabUV = ComputeGrabScreenPos(o.vertex);
    48.                 o.color = v.color * _Color;
    49.                 return o;
    50.             };
    51.  
    52.             fixed4 frag(v2f i) : SV_Target
    53.             {
    54.                 fixed4 texcol = tex2Dproj(_BackgroundTexture, i.grabUV);
    55.                 texcol.rgb = lerp(texcol.rgb, dot(texcol.rgb, float3(0.3, 0.59, 0.11)), texcol.a);
    56.                 texcol = texcol * i.color;
    57.                 return texcol;
    58.             };
    59.  
    60.             ENDCG
    61.         }
    62.     }
    63.     FallBack Off
    64. }
    Enjoy! ;)
     
    absurdnoize and DryreL like this.
  42. Da_Elf

    Da_Elf

    Joined:
    Jan 21, 2017
    Posts:
    15
    It works for me when i build a windows version. But when i build a webGL version i get a bug.
    Im using it on a UI image. as i said it works in windows version
    In WebGL if i go fullscreen when the unity logo is showing all is fine.
    When i go fullscreen when the game is playing then any UI/Image with the material on it disappears. Works fine on Spriterenderer.
     
    Last edited: Aug 9, 2023