unity 透明视频输出实现方法

22 篇文章 3 订阅

效果图:

 

1、shader:

Shader "Custom/NewSurfaceShader" {
    Properties{
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
            //原始代码保留
        _Num("Num",float) = 0.5 //方便调试的参数设置
    }
        SubShader{
            Tags { "Queue" = "Transparent"  "RenderType" = "Transparent"}
            LOD 200

            CGPROGRAM
            // Physically based Standard lighting model, and enable shadows on all light types
            // surface surf Standard fullforwardshadows
            //#pragma surface surf NoLight vertex:vert alpha noforwardadd
            #pragma surface surf NoLighting alpha:auto
            // Use shader model 3.0 target, to get nicer looking lighting
            #pragma target 3.0

            sampler2D _MainTex;

            struct Input {
                float2 uv_MainTex;
            };
            //添加
    //Alpha决定了贴图的透明度
            fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
            {
                fixed4 c;
                c.rgb = s.Albedo;
                c.a = s.Alpha;
                return c;
            }

            half _Glossiness;
            half _Metallic;
            fixed4 _Color;
            //别忘了声明一下_Num
            float _Num;

            // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
            // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
            // #pragma instancing_options assumeuniformscaling
            UNITY_INSTANCING_BUFFER_START(Props)
                // put more per-instance properties here
            UNITY_INSTANCING_BUFFER_END(Props)

            void surf(Input IN, inout SurfaceOutput o) {
                o.Emission = tex2D(_MainTex, IN.uv_MainTex).rgb;

                //这里给输出的Alpha赋值
                //由于我的视频没处理好,不是很对称。。。
                //对称的话应该是0.5
                //这里和0.43比较的是UV贴图的x轴的坐标(0~1,0.5就表示横坐标的一半)
                //右半边视频不显示,所以赋值alpha=0
                if (IN.uv_MainTex.y <= 0.5)
                {
                    o.Alpha = 0;
                }
                else
                {
                    //左半边视频的Alpha值和右半边黑白视频的RGB的值一样
                    //因为我这边处理的A黑白视频不是很好,所以获得了右半边UV的RGB后得比较一下
                    //再给Alpha赋值
                    o.Alpha = tex2D(_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y - 0.5)).rgb * _Num;

                }

            }
            ENDCG
        }
            FallBack "Diffuse"
}
 

 

视频地址:https://pan.baidu.com/s/1bneTfZGmICJAPz3ZJ05n7g

密码:vttk

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值