Cg入门20:Fragment shader - 片段级模型动态变色(实现汽车动态换漆)
2016-03-23 17:02
399 查看
Unity 一个面片的最大顶点数为65524,所以大于这个数,请拆分成多个面片1.获取汽车x轴的最大值和最小值[-2.5,2.5]+R
surfaceShader 语法
surf :surface shader的方法名vert :使用顶点程序方法名
surface shader 方法不能有返回值
源代码:
效果:
surfaceShader 语法
surf :surface shader的方法名vert :使用顶点程序方法名
surface shader 方法不能有返回值
源代码:
Shader "Sbin/SurfaceShader" { Properties { _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 _UpColor("UpColor",color) = (1,0,0,1) _DownColor("DownColor",color) = (0,1,0,1) _Center("Center",range(-0.7,0.7)) = 0 _R("R",range(0,0.5)) = 0.2 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Standard vertex:vert fullforwardshadows //说明:pragma surface method1 Standard vertex:method2 fullforwardshadows #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; float x:TEXCOORD0; }; half _Glossiness; half _Metallic; float4 _UpColor; float4 _DownColor; float _Center; float _R; void vert(inout appdata_full v,out Input o){ o.uv_MainTex = v.texcoord.xy; o.x = v.vertex.x; } void surf (Input IN, inout SurfaceOutputStandard o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = c.a; float d = IN.x - _Center;//融合带 float s = abs(d); d = d/s;//正负值分别描述上半部分和下半部分,取值1和-1 float f = s/_R; //范围>1:表示上下部分;范围<1:表示融合带 f = saturate(f); d *= f;//表示全部[-1,1];范围>1:表示上部分;范围<1:表示融合带;范围<-1:表示下部分 d = d/2+0.5;//将范围控制到[0,1],因为颜色值返回就是[0,1] o.Albedo += lerp(_UpColor,_DownColor,d); } ENDCG } FallBack "Diffuse" }
效果:
相关文章推荐
- 【jQuery源码】jQuery对象初始化
- Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等)
- hdu 2795 Billboard
- Java嵌入式数据库H2学习总结(二)——在Web应用程序中使用H2数据库
- Flowplayer-一款免费的WEB视频播放器
- weak、 _weak、 _block的格式
- 详解Objective-C设计模式编程中对备忘录模式的运用
- Moore-Penrose广义逆矩阵
- 多线程 等待/通知机制
- 轻松解决oracle11g 空表不能 exp 导出 的问题。
- as3 时间
- Java Executors(线程池)
- PHP并发IO编程之路
- Android View Touch的事件分发机制
- Android--httpclient模拟post请求和get请求
- 基于ZooKeeper的分布式Session实现
- string.format
- android提供的json解析类
- 232. Implement Queue using Stacks
- SQL实现查看表结构以及表注释(comments)