Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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.

Shaders

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
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Namey5 · Jun 08, 2016 at 06:36 AM

Replace

 Blend One OneMinusSrcAlpha

with

 Blend SrcAlpha OneMinusSrcAlpha

at line 27.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

78 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI mask does not work on children with different Canvas component and particles 0 Answers

Can a shader add transparency to scene borders? (VR UI) 0 Answers

Render real world UI infront of only 1 other Layer 1 Answer

viewDir changes with o.Normal 1 Answer

How to set shader vertex normals to face up 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges