Cg入门26:Fragment shader –纹理混合动画

多张纹理混合,太多天空盒6张贴图 
会动的星空效果



湖面会动的星空效果






只输出制定颜色通道
colormask r //只准许输出红色 



源代码:
Shader "Sbin/BlendTexAnimShader"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_SecondTex ("Texture", 2D) = "white" {}
		_F("F",Range(0,10))=4
	}
	SubShader
	{
		Pass
		{
			colormask rgba				//只准许输出红色 

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			sampler2D _MainTex;
			sampler2D _SecondTex;
			float _F;

			struct v2f{
				float4 pos:POSITION;
				float2 uv:TEXCOORD0;
			};

			v2f vert (appdata_base v)
			{
				v2f o;
				o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = v.texcoord.xy;
				return o;
			}

			fixed4 frag (v2f v) : COLOR
			{
				//用一张纹理实现:会动的星空效果
				//===========================================
				//float2 uv = v.uv;
				//float offset_uv = 0.05*sin(v.uv*_F + _Time.x*2);

				//uv +=offset_uv;
				//fixed4 col1 = tex2D(_MainTex, uv);

				//uv = v.uv;
				//uv -=offset_uv;
				//fixed4 col2 = tex2D(_MainTex, uv);

				//return (col1+col2)/2;
				//===========================================
				//使用两张纹理实现:湖面会动的星空效果
				//===========================================
				//fixed4 mainColor = tex2D(_MainTex, v.uv);

				//float offset_uv = 0.05*sin(v.uv*_F + _Time.x*2);
				//float2 uv = v.uv + offset_uv;
				//fixed4 secondColor = tex2D(_SecondTex, uv);

				//mainColor.rgb += secondColor;

				//return mainColor/2;
				//===========================================
				//只输出制定颜色通道
				//===========================================
				fixed4 mainColor = tex2D(_MainTex, v.uv);

				float offset_uv = 0.05*sin(v.uv*_F + _Time.x*2);
				float2 uv = v.uv + offset_uv;
				fixed4 secondColor = tex2D(_SecondTex, uv);

				mainColor.rgb *= secondColor.b;

				return mainColor;
			}
			ENDCG
		}
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Potter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值