赞
踩
先上流光效果。
变动的是世界坐标x值。当顶点世界坐标靠近变动值,则在附近取流光贴图颜色值附加到物体上。
首先,我们需要在使用shader模型位置处加上vertex:Myvert 后面名字是顶点着色器函数名字
#pragma surface surf Lambert alpha:fade keepalpha noshadow vertex:Myvert
然后编写顶点着色器片段。这里在结构体处增加了世界坐标。
- struct Input
- {
- float2 uv_texcoord;
- float3 worldSpacePos;
- };
- void Myvert(inout appdata_full v, out Input i)
- {
- UNITY_INITIALIZE_OUTPUT(Input, i);
- i.worldSpacePos = mul(unity_ObjectToWorld, v.vertex);
- }
然后就可以在表面着色器片段中编写自己的需求了。
整体代码如下:
- Shader "Map-base"
- {
- Properties
- {
- _Color("_Color", Color) = (0,0,0,1)
- _Normal("Normal", 2D) = "white" {}
- [HDR]_linecolor("line-color", Color) = (0,0,0,0)
- _linemap("line-map", 2D) = "white" {}
- [HideInInspector] _texcoord( "", 2D ) = "white" {}
- [HideInInspector] __dirty( "", Int ) = 1
- _FlowX("_FlowX",float)=0
- _FlowTex("_FlowTex",2D)="white" {}
- _FlowWidth("_FlowWidth",Range(0.01,1))=1
- }
-
- SubShader
- {
- Tags{ "RenderType" = "Transparent" "Queue" = "Transparent+100" "IgnoreProjector" = "True" "IsEmissive" = "true" }
- Cull Back
- CGPROGRAM
- #include "UnityStandardUtils.cginc"
- #pragma target 3.0
- #pragma surface surf Lambert alpha:fade keepalpha noshadow vertex:Myvert
- struct Input
- {
- float2 uv_texcoord;
- float3 worldSpacePos;
- };
-
- uniform sampler2D _Normal;
- uniform float4 _Normal_ST;
- uniform float4 _Color;
- uniform float4 _linecolor;
- uniform sampler2D _linemap;
- uniform float4 _linemap_ST;
- uniform float _FlowX;
- uniform sampler2D _FlowTex;
- uniform float _FlowWidth;
-
-
-
- void Myvert(inout appdata_full v, out Input i)
- {
- UNITY_INITIALIZE_OUTPUT(Input, i);
- i.worldSpacePos = mul(unity_ObjectToWorld, v.vertex);
- }
-
- void surf( Input i , inout SurfaceOutput o )
- {
- float2 uv_Normal = i.uv_texcoord * _Normal_ST.xy + _Normal_ST.zw;
- o.Normal = UnpackScaleNormal( tex2D( _Normal, uv_Normal ), 2.0 );
- float2 uv_linemap = i.uv_texcoord * _linemap_ST.xy + _linemap_ST.zw;
- o.Emission = ( _linecolor * tex2D( _linemap, uv_linemap ).a ).rgb;
- float d1=i.worldSpacePos.x-_FlowX;
- fixed4 c=fixed4(0,0,0,1);
- if(abs(d1)>_FlowWidth/2)
- c=fixed4(0,0,0,1);
- else c=tex2D(_FlowTex, fixed2(0.5+d1/_FlowWidth,1));
- o.Albedo = _Color.rgb+c.rgb;
- o.Alpha = _Color.a*c.a;
- }
-
- ENDCG
- }
- CustomEditor "ASEMaterialInspector"
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。