本文主要是介绍unity shader 闪烁+流光,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
unity shader 闪烁+流光 上图
上码
Shader "Unlit/流光闪烁"
{Properties{_MainTex ("_MainTex", 2D) = "white" {}_TwinkleSpeed ("TwinkleSpeed", Float ) = 1 //闪烁速度_TwinkleColor ("TwinkleColor", Color) = (0.5,0.5,0.5,1) //闪烁颜色_TimeTex("TimeTexture",2D)="white"{} //流光贴图}SubShader{Tags { "RenderType"="Opaque" }LOD 100Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"uniform sampler2D _MainTex; uniform float4 _MainTex_ST;uniform sampler2D _TimeTex; uniform float4 _TimeTex_ST;uniform float _TwinkleSpeed;uniform float4 _TwinkleColor;struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;};v2f vert (appdata v){v2f o;o.vertex = UnityObjectToClipPos(v.vertex);o.uv = v.uv;return o;}fixed4 frag (v2f i) : SV_Target{float4 MainTex = tex2D(_MainTex,TRANSFORM_TEX(i.uv, _MainTex));float4 time = _Time;float2 timeuv = (i.uv+_Time.g);float4 TimeTex = tex2D(_TimeTex,TRANSFORM_TEX(timeuv, _TimeTex)); //流光计算float3 twinkle = MainTex.b*((cos(time.b*_TwinkleSpeed))*_TwinkleColor.rgb); //闪烁计算return MainTex+TimeTex+ float4(twinkle,0); //各种 +++}ENDCG}}
}
这篇关于unity shader 闪烁+流光的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!