BoYing Unity 之 Shader 笔记(一)帧动画
2015-11-09 16:38
471 查看
使用unity推崇的方式编写的一个播放序列图(帧动画)的shader
Shader "Custom/M1_UV" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} _SizeX ("列", Float) = 4 _SizeY ("行", Float) = 2 _Speed ("播放速度", Float) = 150 } SubShader { // 这里使用Unity3d自带光照模型Lambert // 不用做顶点处理,只需要一个表面处理函数surf CGPROGRAM #pragma surface surf Lambert alpha // 声明参数 fixed4 _Color; sampler2D _MainTex; uniform fixed _SizeX; uniform fixed _SizeY; uniform fixed _Speed; // 获取_MainTex的UV信息定义输入结构体 struct Input { // 在贴图变量前加上uv表示提取uv值(二维坐标) float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { // 获取单元格UV float2 cellUV = float2(IN.uv_MainTex.x /_SizeX, IN.uv_MainTex.y /_SizeY); // UV坐标值范围为0-1,获取单元格宽度 float deltaX = 1 / _SizeX; // 单元格增量宽度 float deltaY = 1 / _SizeY; // 单元格增量高度 // 当前播放总索引 int index = _Time * _Speed; // 求列索引 int col = fmod(index, _SizeX); // 求行索引 int row = index / _SizeX; // 原始UV + 当前格增量 cellUV.x += col * deltaX; cellUV.y += row * deltaY; // 创建tex2d(材质,uv)*主色 fixed4 c = tex2D(_MainTex, cellUV) * _Color; // RGB o.Albedo = c.rgb; // 透明度 o.Alpha = c.a; } ENDCG } }
相关文章推荐
- 反编译ARB program to GLSL shader日记
- 虚幻3引擎
- 基于顶点纹理的无限大海水仿真
- 图形加速卡技术 [专业的基础技术文章]
- 关于VR(主要是虚拟城市场景)的一些想法及实现(可能会连载)
- 编译ics
- 项目中的简单shader
- Simulating Ocean Water
- 在c++中模以”委托“
- 关于NGUI中UITexture贴图自定义的shader文件在UISrollView中不报错的解决方案
- OpenGL&D3D State Machine
- 得到一个 a4e9 bitmap的倒影
- DirectX 8 开发者常见问题集
- error X3025:global variebles are implicitly constant,enable compatibility mode to allow modificatiom
- dx编译shader报错:global variables are implicitly constant, enable compatibility mode to...
- 2016年的游戏引擎设计
- 纹理过滤模式中的Bilinear、Trilinear以及Anistropic Filtering
- Bump Mapping综述
- 一个简单例子表示fixed functional VS/Assemble VS/HLSI VS的例子
- ogre中的材质脚本