Hello Guest

Author Topic: Question about depthmask and grayscale  (Read 4183 times)

quangtu89

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Question about depthmask and grayscale
« on: February 11, 2015, 04:56:25 am »
This is my grayscale shader

Code: [Select]
Shader "Sprites/GrayScale"
{
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
        _EffectAmount ("Effect Amount", Range (0, 1)) = 1.0
    }
 
    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }
 
        Cull Off
        Lighting Off
        ZWrite Off
        Fog { Mode Off }
        Blend SrcAlpha OneMinusSrcAlpha
 
        Pass
        {
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile DUMMY PIXELSNAP_ON
            #include "UnityCG.cginc"
           
            struct appdata_t
            {
                float4 vertex   : POSITION;
                float4 color    : COLOR;
                float2 texcoord : TEXCOORD0;
            };
 
            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                half2 texcoord  : TEXCOORD0;
            };
           
            fixed4 _Color;
 
            v2f vert(appdata_t IN)
            {
                v2f OUT;
                OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
                OUT.texcoord = IN.texcoord;
                OUT.color = IN.color * _Color;
                #ifdef PIXELSNAP_ON
                OUT.vertex = UnityPixelSnap (OUT.vertex);
                #endif
 
                return OUT;
            }
 
            sampler2D _MainTex;
            uniform float _EffectAmount;
 
            fixed4 frag(v2f IN) : COLOR
            {
                half4 texcol = tex2D (_MainTex, IN.texcoord);             
                texcol.rgb = lerp(texcol.rgb, dot(texcol.rgb, float3(0.3, 0.59, 0.11)), _EffectAmount);
                texcol = texcol * IN.color;
                return texcol;
            }
        ENDCG
        }
    }
    Fallback "Sprites/Default"
}


When i use this shader , depthmask of toolkit 2d don't effect to sprites use this grayscale shader ...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about depthmask and grayscale
« Reply #1 on: February 11, 2015, 11:04:37 am »
Seems to work fine for me. There must be something wrong in your setup apart from the shader. If its still broken post a repro

quangtu89

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Question about depthmask and grayscale
« Reply #2 on: February 12, 2015, 03:42:52 am »
I tried with two sprite . a normal sprite with a sprite with grayscale . Please check attachment image

quangtu89

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Question about depthmask and grayscale
« Reply #3 on: February 12, 2015, 03:44:51 am »
thank you very much . i fixed this problem .