码迷,mamicode.com
首页 > 编程语言 > 详细

unity之风吹草动雾shader

时间:2017-06-09 11:15:11      阅读:661      评论:0      收藏:0      [点我收藏+]

标签:rgb   float   time   nsf   osi   render   tran   code   sam   

// Upgrade NOTE: replaced tex2D unity_Lightmap with UNITY_SAMPLE_TEX2D

Shader "Unlit/Grass"
{
Properties {
_MainTex ("Grass Texture", 2D) = "white" {}
_TimeScale ("Time Scale", float) = 1
_alphaValue("alphavalue",range(0,1))=0.5
_Color("Color",Color) = (1,1,1,1)
}

SubShader{
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
Pass{
Tags{ "LightMode"="ForwardBase" }
ZWrite On
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog

#include "UnityCG.cginc"
#include "Lighting.cginc"

sampler2D _MainTex;
float4 _Color;
half _TimeScale;
fixed _alphaValue;
struct a2v {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
UNITY_FOG_COORDS(2)
};
v2f vert(a2v v){
v2f o;
float4 offset = float4(0,0,0,0);
offset.x = sin(3.1416 * _Time.y * clamp(v.texcoord.y-0.5, 0, 1)) * _TimeScale;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex + offset);
o.uv = v.texcoord.xy;
o.uv2 = ((v.texcoord1.xy * unity_LightmapST.xy) + unity_LightmapST.zw);
UNITY_TRANSFER_FOG(o,o.pos);
return o;
}
fixed4 frag(v2f i) : SV_Target{
fixed4 col = tex2D(_MainTex, i.uv);
col.rgb *= DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv2)) * _Color;
clip(col.a - _alphaValue);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
FallBack "Mobile/Diffuse"
}

 

项目中经常会有草动的效果,此shader可行,

unity之风吹草动雾shader

标签:rgb   float   time   nsf   osi   render   tran   code   sam   

原文地址:http://www.cnblogs.com/huangguadazhanxihongshi/p/6970843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!