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 Eldridge Felder · Mar 01, 2013 at 03:41 PM · guitexturealphamovie

Movie GUI Texture Alpha?

I've searched but never found a real solution on how to get a GUI movie in unity to have an Alpha matte applied. Does anyone know a easy way to do this? Right now my movie is being created by:

 public MovieTexture Loading_Movie;
 
 void OnGUI()
 {
 GUI.DrawTexture(new Rect(295, 200, 147, 143), Loading_Movie, ScaleMode.ScaleToFit, true, 0F);
 Loading_Movie.Play();
 Loading_Movie.loop = true;
 }

I created a separate movie that is a grayscale for an Alpha, but not sure how to apply this to the code so it makes my "Loading_Movie" have an Alpha.

So basically I have 2 movies. One is an RGB and is currently on my "Loading_Movie" public movieTexture. The second which is the grayscale for Alpha is not currently being called because Im not sure how to make it treat my RGB version as the alpha. Any suggestions?

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 simon.broggi · Aug 21, 2013 at 02:28 PM

Create a GUITexture and attach this script (uses Graphics.Blit which requires Unity Pro):

 using UnityEngine;
 using System.Collections;
 
 public class GUIVideoWithAlpha : MonoBehaviour {
 
     private Texture colorTexture;
     private Texture matteTexture;
 
     public Shader blitShader;
     private Material blitMat;
 
     void Start () {

         //make the gui texture a render texture
         guiTexture.texture = new RenderTexture(colorTexture.width, colorTexture.height, 16, RenderTextureFormat.ARGB32);

         blitMat = new Material(blitShader);
         blitMat.SetTexture("_AlphaTex", matteTexture);
 
         if(colorTexture is MovieTexture){
             (colorTexture as MovieTexture).Play();
         }
         if(matteTexture is MovieTexture){
             (matteTexture as MovieTexture).Play();
         }
     }
 
     void Update () {
         if(guiTexture.enabled){
             Graphics.Blit(colorTexture, (RenderTexture)guiTexture.texture, blitMat);
         }
     }
 }


Drop your video into the Color Texture, and the alpha matte into Mate Texture. Use this as the blitShader:

 Shader "Alpha Matte" {
 Properties {
     _MainTex ("Base (RGB)", Rect) = "white" {}
     _AlphaTex ("Base (RGB)", Rect) = "white" {}
 }
 
 SubShader {
     Pass {
         ZTest Always Cull Off ZWrite Off
         Fog { Mode off }
                 
 CGPROGRAM
 #pragma vertex vert_img
 #pragma fragment frag
 #pragma fragmentoption ARB_precision_hint_fastest 
 #include "UnityCG.cginc"
 
 uniform sampler2D _MainTex;
 uniform sampler2D _AlphaTex;
 
 fixed4 frag (v2f_img i) : COLOR
 {
     fixed4 output = tex2D(_MainTex, i.uv);
     fixed4 alpha = tex2D(_AlphaTex, i.uv);
     
     output.a = Luminance(alpha.rgb);
     return output;
 }
 ENDCG
 
     }
 }
 
 Fallback off
 
 }
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 silentslack · Aug 28, 2013 at 08:42 PM 0
Share

Hi, I would like to also know this. I tried the above solution but I get an 'InvalidCastException' when casting the Texture to a RenderTexture!?

avatar image simon.broggi · Aug 29, 2013 at 07:28 AM 0
Share

Woops, sorry. You need to assign a new render texture to the gui texture. I just added the missing line to the code in the start function. Hope it works.

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

11 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

Related Questions

Help with destroying guiRect? 0 Answers

Move Texture From Plane To GUI And Back 0 Answers

Fading a GUI.DrawTexture? 2 Answers

Alpha cutoff for a GUI Texture? 2 Answers

Make a movie texture rewind (play again) 3 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