- Home /
 
               Question by 
               Flaring-Afro · Jun 07, 2016 at 01:03 PM · 
                uishadershaders  
              
 
              Shader tints transparency instead of leaving it invisible
I downloaded shaders from the link below to make buttons with text that is transparent. It works, but if the material color is not black, the invisibly transparent areas of a sprite become tinted. I'm guessing there is a way to prevent this in the shader UIMasked's code but can't figure out what needs to be changed.
Shader code
 // Compiled shader for PC, Mac & Linux Standalone, uncompressed size: 8.8KB
 
 // Skipping shader variants that would not be included into build of current scene.
 
 Shader "IndieYP/UIMasked" {
 Properties {
 [PerRendererData]  _MainTex ("Sprite", 2D) = "white" { }
  _Color ("Tint", Color) = (1,1,1,1)
 [MaterialToggle]  PixelSnap ("PixelSnap", Float) = 0
 }
 SubShader { 
  Tags { "QUEUE"="Transparent+2" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="true" }
 
 
  // Stats for Vertex shader:
  //       d3d11 : 5 math
  //    d3d11_9x : 5 math
  //        d3d9 : 5 math
  // Stats for Fragment shader:
  //       d3d11 : 1 math, 1 texture
  //    d3d11_9x : 1 math, 1 texture
  //        d3d9 : 2 math, 1 texture
  Pass {
   Tags { "QUEUE"="Transparent+2" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="true" }
   ZWrite Off
   Cull Off
   Blend One OneMinusSrcAlpha
   GpuProgramID 1857
 Program "vp" {
 SubProgram "d3d9 " {
 // Stats: 5 math
 Bind "vertex" Vertex
 Bind "texcoord" TexCoord0
 Matrix 0 [glstate_matrix_mvp]
 Vector 4 [_MainTex_ST]
 "//
 // Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
 //
 // Parameters:
 //
 //   float4 _MainTex_ST;
 //   row_major float4x4 glstate_matrix_mvp;
 //
 //
 // Registers:
 //
 //   Name               Reg   Size
 //   ------------------ ----- ----
 //   glstate_matrix_mvp c0       4
 //   _MainTex_ST        c4       1
 //
 
     vs_2_0
     dcl_position v0
     dcl_texcoord v1
     dp4 oPos.x, c0, v0
     dp4 oPos.y, c1, v0
     dp4 oPos.z, c2, v0
     dp4 oPos.w, c3, v0
     mad oT0.xy, v1, c4, c4.zwzw
 
 // approximately 5 instruction slots used
 "
 }
 SubProgram "d3d11 " {
 // Stats: 5 math
 Bind "vertex" Vertex
 Bind "texcoord" TexCoord0
 ConstBuffer "$Globals" 128
 Vector 112 [_MainTex_ST]
 ConstBuffer "UnityPerDraw" 352
 Matrix 0 [glstate_matrix_mvp]
 BindCB  "$Globals" 0
 BindCB  "UnityPerDraw" 1
 "//
 // Generated by Microsoft (R) D3D Shader Disassembler
 //
 //
 // Input signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // POSITION                 0   xyzw        0     NONE   float   xyzw
 // NORMAL                   0   xyz         1     NONE   float       
 // TEXCOORD                 0   xyzw        2     NONE   float   xy  
 //
 //
 // Output signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // SV_POSITION              0   xyzw        0      POS   float   xyzw
 // TEXCOORD                 0   xy          1     NONE   float   xy  
 //
       vs_4_0
       dcl_constantbuffer cb0[8], immediateIndexed
       dcl_constantbuffer cb1[4], immediateIndexed
       dcl_input v0.xyzw
       dcl_input v2.xy
       dcl_output_siv o0.xyzw, position
       dcl_output o1.xy
       dcl_temps 1
    0: mul r0.xyzw, v0.yyyy, cb1[1].xyzw
    1: mad r0.xyzw, cb1[0].xyzw, v0.xxxx, r0.xyzw
    2: mad r0.xyzw, cb1[2].xyzw, v0.zzzz, r0.xyzw
    3: mad o0.xyzw, cb1[3].xyzw, v0.wwww, r0.xyzw
    4: mad o1.xy, v2.xyxx, cb0[7].xyxx, cb0[7].zwzz
    5: ret 
 // Approximately 0 instruction slots used
 "
 }
 SubProgram "d3d11_9x " {
 // Stats: 5 math
 Bind "vertex" Vertex
 Bind "texcoord" TexCoord0
 ConstBuffer "$Globals" 128
 Vector 112 [_MainTex_ST]
 ConstBuffer "UnityPerDraw" 352
 Matrix 0 [glstate_matrix_mvp]
 BindCB  "$Globals" 0
 BindCB  "UnityPerDraw" 1
 "//
 // Generated by Microsoft (R) D3D Shader Disassembler
 //
 //
 // Input signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // POSITION                 0   xyzw        0     NONE   float   xyzw
 // NORMAL                   0   xyz         1     NONE   float       
 // TEXCOORD                 0   xyzw        2     NONE   float   xy  
 //
 //
 // Output signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // SV_POSITION              0   xyzw        0      POS   float   xyzw
 // TEXCOORD                 0   xy          1     NONE   float   xy  
 //
 //
 // Constant buffer to DX9 shader constant mappings:
 //
 // Target Reg Buffer  Start Reg # of Regs        Data Conversion
 // ---------- ------- --------- --------- ----------------------
 // c1         cb0             7         1  ( FLT, FLT, FLT, FLT)
 // c2         cb1             0         4  ( FLT, FLT, FLT, FLT)
 //
 //
 // Runtime generated constant mappings:
 //
 // Target Reg                               Constant Description
 // ---------- --------------------------------------------------
 // c0                              Vertex Shader position offset
 //
 //
 // Level9 shader bytecode:
 //
     vs_2_0
           dcl_texcoord v0
           dcl_texcoord2 v2
    0:     mad oT0.xy, v2, c1, c1.zwzw
    1:     mul r0, v0.y, c3
    2:     mad r0, c2, v0.x, r0
    3:     mad r0, c4, v0.z, r0
    4:     mad r0, c5, v0.w, r0
    5:     mad oPos.xy, r0.w, c0, r0
    6:     mov oPos.zw, r0
 
 // approximately 7 instruction slots used
       vs_4_0
       dcl_constantbuffer cb0[8], immediateIndexed
       dcl_constantbuffer cb1[4], immediateIndexed
       dcl_input v0.xyzw
       dcl_input v2.xy
       dcl_output_siv o0.xyzw, position
       dcl_output o1.xy
       dcl_temps 1
    0: mul r0.xyzw, v0.yyyy, cb1[1].xyzw
    1: mad r0.xyzw, cb1[0].xyzw, v0.xxxx, r0.xyzw
    2: mad r0.xyzw, cb1[2].xyzw, v0.zzzz, r0.xyzw
    3: mad o0.xyzw, cb1[3].xyzw, v0.wwww, r0.xyzw
    4: mad o1.xy, v2.xyxx, cb0[7].xyxx, cb0[7].zwzz
    5: ret 
 // Approximately 0 instruction slots used
 "
 }
 }
 Program "fp" {
 SubProgram "d3d9 " {
 // Stats: 2 math, 1 textures
 Vector 0 [_Color]
 SetTexture 0 [_MainTex] 2D 0
 "//
 // Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
 //
 // Parameters:
 //
 //   float4 _Color;
 //   sampler2D _MainTex;
 //
 //
 // Registers:
 //
 //   Name         Reg   Size
 //   ------------ ----- ----
 //   _Color       c0       1
 //   _MainTex     s0       1
 //
 
     ps_2_0
     dcl t0.xy
     dcl_2d s0
     texld_pp r0, t0, s0
     mul_pp r0, r0, c0
     mov_pp oC0, r0
 
 // approximately 3 instruction slots used (1 texture, 2 arithmetic)
 "
 }
 SubProgram "d3d11 " {
 // Stats: 1 math, 1 textures
 SetTexture 0 [_MainTex] 2D 0
 ConstBuffer "$Globals" 128
 Vector 96 [_Color]
 BindCB  "$Globals" 0
 "//
 // Generated by Microsoft (R) D3D Shader Disassembler
 //
 //
 // Input signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // SV_POSITION              0   xyzw        0      POS   float       
 // TEXCOORD                 0   xy          1     NONE   float   xy  
 //
 //
 // Output signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // SV_Target                0   xyzw        0   TARGET   float   xyzw
 //
       ps_4_0
       dcl_constantbuffer cb0[7], immediateIndexed
       dcl_sampler s0, mode_default
       dcl_resource_texture2d (float,float,float,float) t0
       dcl_input_ps linear v1.xy
       dcl_output o0.xyzw
       dcl_temps 1
    0: sample r0.xyzw, v1.xyxx, t0.xyzw, s0
    1: mul o0.xyzw, r0.xyzw, cb0[6].xyzw
    2: ret 
 // Approximately 0 instruction slots used
 "
 }
 SubProgram "d3d11_9x " {
 // Stats: 1 math, 1 textures
 SetTexture 0 [_MainTex] 2D 0
 ConstBuffer "$Globals" 128
 Vector 96 [_Color]
 BindCB  "$Globals" 0
 "//
 // Generated by Microsoft (R) D3D Shader Disassembler
 //
 //
 // Input signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // SV_POSITION              0   xyzw        0      POS   float       
 // TEXCOORD                 0   xy          1     NONE   float   xy  
 //
 //
 // Output signature:
 //
 // Name                 Index   Mask Register SysValue  Format   Used
 // -------------------- ----- ------ -------- -------- ------- ------
 // SV_Target                0   xyzw        0   TARGET   float   xyzw
 //
 //
 // Constant buffer to DX9 shader constant mappings:
 //
 // Target Reg Buffer  Start Reg # of Regs        Data Conversion
 // ---------- ------- --------- --------- ----------------------
 // c0         cb0             6         1  ( FLT, FLT, FLT, FLT)
 //
 //
 // Sampler/Resource to DX9 shader sampler mappings:
 //
 // Target Sampler Source Sampler  Source Resource
 // -------------- --------------- ----------------
 // s0             s0              t0               
 //
 //
 // Level9 shader bytecode:
 //
     ps_2_0
           dcl t0.xy
           dcl_2d s0
    0:     texld_pp r0, t0, s0
    0:     mul_pp r0, r0, c0
    1:     mov_pp oC0, r0
 
 // approximately 3 instruction slots used (1 texture, 2 arithmetic)
       ps_4_0
       dcl_constantbuffer cb0[7], immediateIndexed
       dcl_sampler s0, mode_default
       dcl_resource_texture2d (float,float,float,float) t0
       dcl_input_ps linear v1.xy
       dcl_output o0.xyzw
       dcl_temps 1
    0: sample r0.xyzw, v1.xyxx, t0.xyzw, s0
    1: mul o0.xyzw, r0.xyzw, cb0[6].xyzw
    2: ret 
 // Approximately 0 instruction slots used
 "
 }
 }
  }
 }
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Namey5 · Jun 08, 2016 at 06:36 AM
Replace
 Blend One OneMinusSrcAlpha
with
 Blend SrcAlpha OneMinusSrcAlpha
at line 27.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                