纳金网

标题: 给物体添加一个明暗变化效果的shader [打印本页]

作者: 晃晃    时间: 2011-9-5 08:27
标题: 给物体添加一个明暗变化效果的shader
个不错的shader,可以为场景的物体添加一个渐变明暗效果,下面是截图:


下面是shader代码:


Shader "Hidden/TerrainEngine/BillboardTree" {

Properties {

  _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}

}
SubShader {

  Tags { "Queue" = "Transparent-100" "IgnoreProjector"="***e" "RenderType"="TreeBillboard" }

  

  Pass {

   ColorMask rgb

   Blend SrcAlpha OneMinusSrcAlpha

   ZWrite Off Cull Off

   

   CGPROGRAM

   #pragma vertex vert

   #include "UnityCG.cginc"

   #include "TerrainEngine.cginc"

   #pragma fragment frag
   s***ct v2f {

    float4 pos : POSITION;

    fixed4 color : COLOR0;

    float2 uv : TEXCOORD0;

   };
   v2f vert (appdata_tree_billboard v) {

    v2f o;

    TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);

    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);

    o.uv.x = v.texcoord.x;

    o.uv.y = v.texcoord.y > 0;

    o.color = v.color;

    o.color *= o.uv.y;

    return o;

   }
   sampler2D _MainTex;

   fixed4 frag(v2f input) : COLOR

   {

    fixed4 col = tex2D( _MainTex, input.uv);

    col.rgb *= input.color.rgb;

    clip(col.a);

    return col;

   }

   ENDCG   

  }

}
SubShader {

  Tags { "Queue" = "Transparent-100" "IgnoreProjector"="***e" "RenderType"="TreeBillboard" }

  

  Pass {
   CGPROGRAM

   #pragma vertex vert

   #pragma exclude_renderers shaderonly

   #include "UnityCG.cginc"

   #include "TerrainEngine.cginc"
   s***ct v2f {

    float4 pos : POSITION;

    fixed4 color : COLOR0;

    float2 uv : TEXCOORD0;

   };
   v2f vert (appdata_tree_billboard v) {

    v2f o;

    TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);

    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);

    o.uv.x = v.texcoord.x;

    o.uv.y = v.texcoord.y > 0;

    o.color = v.color;

    return o;

   }

   ENDCG  
   ColorMask rgb

   Blend SrcAlpha OneMinusSrcAlpha

   ZWrite Off Cull Off

   

   AlphaTest Greater 0

   SetTexture [_MainTex] { combine texture * primary, texture }

  }

}
Fallback Off

}
作者: Asen    时间: 2011-9-7 08:36
木有图啊~~~~~~~~~
作者: C.R.CAN    时间: 2012-5-3 23:18
不错啊 经典

作者: markq    时间: 2012-5-4 23:21
  谢谢分享



爱生活 爱3D 爱纳金网



www.narkii.com
作者: 菜刀吻电线    时间: 2012-6-3 23:18
“再次路过……”我造一个-----特别路过

作者: 晃晃    时间: 2012-8-26 00:02
谢谢楼主,真是太实用了





欢迎光临 纳金网 (http://wwww.narkii.com/club/) Powered by Discuz! X2.5