Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Fadi · Jun 16, 2015 at 04:37 PM · shadershadersalphamask

shader problem

I need to remove the green screen behind the character ...

I tried this code

 Shader "Chromakey/Mask" {
 
 
     Properties {
 
         _MainTex ("Base (RGB)", 2D) = "white" {}
         //_MaskCol ("Mask Color", Color)  = (1.0, 0.0, 0.0, 1.0)
         Transparency ("Transparency", Range (0,1.0)) = 0.5
     }
 
     SubShader {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
         LOD 100
         
         ZWrite Off
         Blend SrcAlpha OneMinusSrcAlpha 
 
         CGINCLUDE
 
             #include "UnityCG.cginc"
             
             uniform float Transparency;
             
             half3 NormalizeColor (half3 color) {
                 //return color / max(dot(color, half3(1.0f/3.0f)), 0.0001);
                 return color / dot(color, fixed3(0.5,0.5,0.01));
             }
 
             half4 MaskColor (half3 mCol, half3 cCol) {
                 //half4 d = distance(NormalizeColor(mCol.rgb), NormalizeColor(cCol.rgb));    
                 //return ((mCol.g - (mCol.r + mCol.b)) > Transparency ) ? d : half4(mCol.rgb,1.0);
                 return ((mCol.g - (mCol.r + mCol.b)) > Transparency ) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
             
                 //float e = 0.04f;
                 //return ( mCol.g <= e && mCol.r <= e && mCol.b <= e) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
             
             
             //float f = 1.0f;
             //if ((mCol.g - (mCol.r + mCol.b)) > Transparency )
             //    f = 0.0;
             //return half4(mCol.rgb,f);
     
                 //return ((mCol.g - (mCol.r + mCol.b)) < Transparency ) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
             }
         ENDCG
 
         Pass {
             Lighting Off
             //Cull Off ZWrite On Lighting Off Fog { Mode off } 
             //Blend SrcAlpha OneMinusSrcAlpha
             CGPROGRAM
                 #pragma vertex vert_img
                 #pragma fragment frag
                 #pragma fragmentoption ARB_precision_hint_fastest
 
                 uniform sampler2D _MainTex;
                 uniform float4 _MaskCol;
 
                 half4 frag (v2f_img i) : COLOR {
 
                     half4 col = tex2D(_MainTex, i.uv);
                     half4 mask = MaskColor(col.rgb, _MaskCol.rgb);
                     //return col * mask;
                     return mask;
                 }
             ENDCG
         }
         
         
         
     }
 
     Fallback off
 }
 
 


but the problem , some green line around the character didn't disapper , is there away to change it to clear all the green layer ?

then I searched a lot and found this site talk about the same situation , but by using mask at the same image ( normal image and mask at the same image )

but the shader dosen't work fine

http://www.unity3d-france.com/unity/phpBB3/viewtopic.php?f=8&t=901&sid=bd96eaad6e6c1b2d40e34679a2bc73cf☆t=10

 Shader "Custom/VideoAlpha" {
    Properties {
       _MainTex ("Base (RGB)", 2D) = "white" {}
       _AlphaOffsetX ("alpha offset x", float) = 0.5
       _AlphaOffsetY ("alpha offset y", float) = 0
       _Cutoff ("Cutoff", Range (0,1)) = .5
    }
    SubShader {
    AlphaTest Less [_Cutoff]
          CGPROGRAM
          #pragma surface surf Lambert
    
          sampler2D _MainTex;
          float _AlphaOffsetX;
          float _AlphaOffsetY;
    
          struct Input {
             float2 uv_MainTex;
          };
    
          void surf (Input IN, inout SurfaceOutput o) 
          {
             half4 c = tex2D (_MainTex, IN.uv_MainTex);
             IN.uv_MainTex.x += _AlphaOffsetX;
             IN.uv_MainTex.y += _AlphaOffsetY;
             half4 d = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = (d.r*-1)+1;
          }
         
          ENDCG
       
    }
    FallBack "Diffuse"
 }



i added to the material then add this image

but no change at all , where the problem ?

alt text

thank you ...

Note : I need it to work with Images and video

soizickeytest-400.jpg (47.9 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Depth mask with alpha / adding alpha to frag grabpass shader 0 Answers

Implement texture masking into simple existing shader 1 Answer

Shadows with Alpha, fade out shadow. 2 Answers

Cut out shader with geometry depth and alpha 0 Answers

Shader problem with 2D fake lighting 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