博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cg入门26:Fragment shader –纹理混合动画
阅读量:2202 次
发布时间:2019-05-03

本文共 1690 字,大约阅读时间需要 5 分钟。

多张纹理混合,太多天空盒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		}	}}
你可能感兴趣的文章
(PAT 1040) Longest Symmetric String (DP-最长回文子串)
查看>>
(PAT 1145) Hashing - Average Search Time (哈希表冲突处理)
查看>>
(1129) Recommendation System 排序
查看>>
PAT1090 Highest Price in Supply Chain 树DFS
查看>>
(PAT 1096) Consecutive Factors (质因子分解)
查看>>
(PAT 1019) General Palindromic Number (进制转换)
查看>>
(PAT 1073) Scientific Notation (字符串模拟题)
查看>>
(PAT 1080) Graduate Admission (排序)
查看>>
Play on Words UVA - 10129 (欧拉路径)
查看>>
mininet+floodlight搭建sdn环境并创建简答topo
查看>>
【linux】nohup和&的作用
查看>>
Set、WeakSet、Map以及WeakMap结构基本知识点
查看>>
【NLP学习笔记】(一)Gensim基本使用方法
查看>>
【NLP学习笔记】(二)gensim使用之Topics and Transformations
查看>>
【深度学习】LSTM的架构及公式
查看>>
【python】re模块常用方法
查看>>
剑指offer 19.二叉树的镜像
查看>>
剑指offer 20.顺时针打印矩阵
查看>>
剑指offer 21.包含min函数的栈
查看>>
剑指offer 23.从上往下打印二叉树
查看>>