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 Hivemind · Feb 02, 2013 at 10:16 PM · shadertexturesalphafadetransition

Fade Shader- One texture fades in, the other fades out

Hey Everyone,

I am trying to making a shader that contains 2 textures and colors that support transparency. I want to use a coroutine to fade between the two textures as a transition effect. I looked over the documentation and the default shaders but I couldn't come up with anything substantial. I was wondering if you guys can help me complete my code and tell me what is wrong with it.

 Shader "Custom/UnlitTransparent" {
 Properties {
 
     _Color ("Main Color", Color) = (1,0.5,0.5,1)
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     _OtherColor ("Other Color", Color) = (1,0.5,0.5,1)
     _OtherTex ("Base (RGB) Trans (A)", 2D) = "white" {}
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     LOD 100
     
     //ZWrite Off
     Blend SrcAlpha OneMinusSrcAlpha 
 
     Pass {
         Lighting Off
         
         Material {
             Diffuse [_Color]
         }
         SetTexture [_MainTex] { combine texture } 
     }
     
     Pass
     {
         Lighting Off
         Blend DstAlpha OneMinusSrcAlpha 
 
         Material {
             Diffuse [_OtherColor]
         }
         SetTexture [_OtherTex] {
             combine texture lerp (texture) previous
         }
     }    
     
 }
 }
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

2 Replies

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

Answer by robertbu · Feb 03, 2013 at 03:36 PM

Here is a very simple example of what Owen Reynolds explained.

 Shader "Custom/AlphaBlendTransition" {
 Properties {
     _Blend ("Blend", Range (0, 1) ) = 0.0
     _BaseTexture ("Base Texture", 2D) = "" {}
     _OverlayTexture ("Texture 2 with alpha", 2D) = "" {}
 
 }
 SubShader {
         Pass {
             SetTexture[_BaseTexture]
             SetTexture[_OverlayTexture] {
                 ConstantColor (0,0,0, [_Blend]) 
                 combine texture Lerp(constant) previous
             }
         }
     }
 }

This blends two textures.

Comment
Add comment · Show 3 · 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 Gillespionage · Jul 18, 2013 at 12:58 PM 0
Share

Hey! this is sweet!

I'm a shader newb and was wondering.. is it possible to get this shader to not be self illu$$anonymous$$ated?

Thanks

avatar image robertbu · Jul 18, 2013 at 02:48 PM 0
Share

@Gillespionage - These kinds of shaders typically use '_Blend' for the property, so you can search for "unity blend shader" or "unity shader blend diffuse". Here is one hit that might be what you are looking for:

http://answers.unity3d.com/questions/54837/how-to-make-a-diffuse-bump-blending.html

avatar image Gillespionage · Jul 18, 2013 at 03:08 PM 0
Share

@robertbu

Awesome! That is what I was looking for! Thank you so much :D

avatar image
1

Answer by Owen-Reynolds · Feb 02, 2013 at 10:54 PM

The goal is to have the script send the shader/Material its Lerp value going from 0 to 1. The thing is, this version of Lerp uses the alpha value of the 2nd input (the one in quotes.) Since you give it (texture) it's just doing a standard decal-blend.

So, you have to give it some fake input with the alpha set to the Lerp val you need. Can use (constant), which will use the MainColor you set. It still uses the alpha, but if you set color=new Color(1,1,1,myLerpVal) you can trick it into using your lerp val.

DISCLAIMER: I don't use shaderLab (I use surf shaders.)

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

13 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

Related Questions

Help with custom shader 0 Answers

layered texture with seperate alpha? 0 Answers

Opaque to Transparent animation effect on a textured object (Lerpz)? 1 Answer

Fading groups of objects to black 1 Answer

Opacity at Runtime - Fade Shader 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