• 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 VivienS · Oct 08, 2010 at 07:48 AM · shaderalpha

Shader that combines two textures' alpha channels?

Hello.

I'm looking for a transparent diffuse shader that combines two textures' alpha channels like this

alt text I think there was a standard shader in one of the online repositories that does this, but I can't find it anymore.

Appreciate your help!

thanks, vivien


Edit: Related to the above: What could I do to animate (scroll) the texture 1 and it's alpha and keep texture 2 static? (The result would be a scrolling transparent texture with a static alpha that makes it f.i fade at the borders)

Thanks!

Comment
Add comment · Show 3
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 Azial · Feb 24, 2013 at 09:58 PM 0
Share

Related to your Edit: Add this:

float2 uv_Alpha$$anonymous$$ap

to the struct Input {...} function and change: o.Alpha = c.a * tex2D(Alpha$$anonymous$$ap, IN.uv$$anonymous$$ainTex).r; to:

o.Alpha = c.a * tex2D(_Alpha$$anonymous$$ap, IN.uv_Alpha$$anonymous$$ap).r;

You can scroll the first texture with this script attached to your gameobject with the material that uses the shader:

 var scrollSpeed : float = 0.05;
 var scrollVector : Vector2 = Vector2(0, 1);
 
 function Update () {
     renderer.material.SetTextureOffset ("_$$anonymous$$ainTex", scrollVector * Time.time * scrollSpeed);
 }
avatar image sathya · Jul 04, 2013 at 01:57 PM 0
Share

Can you please write the same for openGLES V1.1. Unfortunately i am running my game in openglES1. can not change it at this point of time.

avatar image alemke · Sep 15, 2014 at 04:15 AM 0
Share

Has anyone been able to make an additive mobile version of this shader?

3 Replies

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

Answer by taoa · Oct 08, 2010 at 10:33 AM

How did you end up with some white in your red/green/blue channels? ^^

Anyway, here you go:

 Shader "Transparent/Diffuse + Extra Alpha"
 {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     LOD 200
 
 CGPROGRAM
 #pragma surface surf Lambert alpha
 
 sampler2D _MainTex;
 sampler2D _AlphaMap;
 float4 _Color;
 
 struct Input {
     float2 uv_MainTex;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_MainTex).r;
 }
 ENDCG
 }
 
 Fallback "Transparent/VertexLit"
 }



Sinon vous auriez pu me demander directement.

V.

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 manny003 · Jan 02, 2016 at 03:52 PM 0
Share

Try as I might, I cannot seem to make the original shader was posted by @Taoa, an Unlit/Self Lit shader. Without adding extra lights, it's simply too dim.

How can we make the shader texture appear full brightness with depending on any lights?

Thanks, $$anonymous$$anny

avatar image
2

Answer by Azial · Feb 24, 2013 at 11:20 PM

Nice Shader, for those who want it as additive Shader (useful for fire-effects like in WoW since Wotlk) I wrote this:

 Shader "Custom/AdditivMask" {
     Properties {
     _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
     _MainTex ("Particle Texture", 2D) = "white" {}
     _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
     }
 
     SubShader {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
         Blend SrcAlpha One
         AlphaTest Greater .01
         ColorMask RGB
         Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
         BindChannels {
             Bind "Color", color
             Bind "Vertex", vertex
             Bind "TexCoord", texcoord
         }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
         sampler2D _AlphaMap;
         fixed4 _TintColor;
 
         struct Input {
             float2 uv_MainTex;
             float2 uv_AlphaMap;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D (_MainTex, IN.uv_MainTex) * _TintColor;
             o.Albedo = c.rgb;
             o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_AlphaMap).r;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }
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
avatar image
0

Answer by fcbdigitalstudio · Sep 19, 2017 at 06:53 PM

I was able to pull off an unlit effect by using

  void surf (Input IN, inout SurfaceOutput o) {
      half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
      //o.Albedo = c.rgb;
      o.Emission = c.rgb;
      o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_MainTex).r;
  }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Shader is not displaying alpha correctly 0 Answers

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

2048px square texture blurr problem 0 Answers

How do you setup Depth Bias Alpha for Shaders? 0 Answers

Advanced shader issue - base surface color not showing 0 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