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
1
Question by Eviral · Sep 27, 2013 at 08:03 AM · shaderalphablend

Trying to write a simple mixing 2 textures shader with alpha support on the 2d texture

I have 2 textures :

  • A background texture with no transparency (for example the earth texture)

  • A cropcircle texture (black and white texture) showing a simple white symbol over a black background

I can't find any existing CG shader (CG shader is immportant) to be able to display my white cropcircle on my planet earth planet.

I just want the black background of my cropcircle texture to be transparent and to show the earth texture bellow by transparency.

Here is the shader i'm trying to write :

 Shader "Custom/SimpleMix"
 {
     Properties
     {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _BlendTex ("_BlendTex", 2D) = "white" {}
         _Blend1 ("Blend between Base and Blend 1 textures", Range (0, 1) ) = 0 
     }
     SubShader
     {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
         LOD 200
         
         ZWrite Off
         //Blend SrcAlpha OneMinusSrcAlpha
         //Blend One One
         //Blend SrcAlpha OneMinusSrcAlpha
 
         
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
         sampler2D _BlendTex;
         float _Blend1;
 
         struct Input
         {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o)
         {
             fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
             fixed4 texTwoCol = tex2D(_BlendTex, IN.uv_MainTex);
             fixed4 output = lerp(mainCol, texTwoCol, _Blend1);
             o.Albedo = output.rgb;
             o.Alpha = output.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }


if I use Blend SrcAlpha OneMinusSrcAlpha with a png cropcircle with transparency, the earth texture become transparent too :(

Please help...

Thanks a lot

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
2

Answer by DarkPixel · Sep 27, 2013 at 08:26 PM

    void surf (Input IN, inout SurfaceOutput o)
    {
      fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
      fixed4 texTwoCol = tex2D(_BlendTex, IN.uv_MainTex);                           
      
      fixed4 mainOutput = mainCol.rgba * (1.0 - (texTwoCol.a * _Blend1));
      fixed4 blendOutput = texTwoCol.rgba * texTwoCol.a * _Blend1;         
      
      o.Albedo = mainOutput.rgb + blendOutput.rgb;
      o.Alpha = mainOutput.a + blendOutput.a;
    }

(The blend text need to have alpha to work, you can generate it from grayscale if it's a black and white texture)

Comment
Add comment · Show 1 · 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
avatar image Eviral · Sep 28, 2013 at 11:38 AM 0
Share

It works ! Thanks a lot !

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

16 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

Related Questions

Blend two texture diffuse shader with alpha 0 Answers

Decal Alpha Blend 0 Answers

Blend 2 Texture with alpha 1 Answer

Scripting Shader: How to control Alpha with slider? 1 Answer

Alpha values not blending in RenderTexture 2 Answers


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