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 Randy O · Feb 10, 2013 at 01:33 AM · transparencyblendcustom shader

How do I modify a very basic blend shader to allow both transparent textures?

I am making an iOS game and need to blend two textures with alpha back and forth.

I don't need lots of control, there are no lights or anything affecting this shader. I found a very basic blend shader that I've seen referenced several times, but I don't know how to enable transparency for both _MainTex and _Texture2.

This shader does everything I need except allow textures with transparency.

 Shader "Custom/Blend 2 Textures" { 
 
 Properties {
     _Blend ("Blend", Range (0, 1) ) = 0.5 
     _MainTex ("Texture 1", 2D) = "" 
     _Texture2 ("Texture 2", 2D) = ""
 }
 
 SubShader {    
     Pass {
         SetTexture[_MainTex]
         SetTexture[_Texture2] { 
             ConstantColor (0,0,0, [_Blend]) 
             Combine texture Lerp(constant) previous
         }        
     }
 } 
 
 }

Here's all that the texture needs to do: 1)Texture A is visible 2)Texture B is visible. 3) For .3 seconds they blend from A to B and at other times blend for 0.3 seconds B to A.

As you can see in the image below, there are numbers in focus and out of focus. Rather than a blurring shader to fake depth of field (since I'm using Unity Basic), I just want to fade back and forth between blurred and unblurred textures.

I get the feeling that as soon as I add transparency there's a lot more I have to do. Any help is very much appreciated. I'm new to custom shaders, so not sure if I bit off too much. So can I easily make both textures A and B contain transparency?

alt text

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
0
Best Answer

Answer by robertbu · Feb 11, 2013 at 03:31 AM

I've not spent much time with shader to date, but this should give you what you want:

 Shader "Custom/Blend 2 Textures" { 
  
 Properties {
     _Blend ("Blend", Range (0, 1) ) = 0.5 
     _MainTex ("Texture 1", 2D) = "" 
     _Texture2 ("Texture 2", 2D) = ""
 }
  
 SubShader { 
     Tags {"Queue"="Transparent"}
     Blend SrcAlpha OneMinusSrcAlpha
     Pass {
        SetTexture[_MainTex]
        SetTexture[_Texture2] { 
          ConstantColor (0,0,0, [_Blend]) 
          Combine texture Lerp(constant) previous
        }     
     }
 } 
  

}

Comment
Add comment · Show 2 · 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 Randy O · Feb 11, 2013 at 06:19 AM 0
Share

You're right, thank you! I did not realize that would be so straightforward, just adding a tag and the blend line.

avatar image oliran · Oct 25, 2015 at 05:31 PM 0
Share

When I tried this, everything behind the transparency of the image appears black.. Any idea how to solve this?

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

10 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

Related Questions

Composite screen shader with transparency? 0 Answers

Decal Alpha Blend 0 Answers

glass sphere with reflective/specular shader? 2 Answers

How do you get ambient occlusion working with transparency and lightmapping? 0 Answers

Create a shader using mask for sprite 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