当前位置: 移动技术网 > IT编程>开发语言>c# > Unity3D Shader实现扫描显示效果(2)

Unity3D Shader实现扫描显示效果(2)

2019年07月18日  | 移动技术网IT编程  | 我要评论

上一篇使用的方式是对uv进行剪裁,如果用于模型的话,会出现一些问题。本篇使用的方式是对模型进行模型空间的剪裁,可设置剪裁方向。效果如下:

设置界面如下:

mode用于设置剪裁方向。
clip用于设置剪裁值。

shader实现如下:

shader "xm/scaneffect2" 
{
 properties {
  _color ("color", color) = (1,1,1,1)
  _maintex ("albedo (rgb)", 2d) = "white" {}
  _glossiness ("smoothness", range(0,1)) = 0.5
  _metallic ("metallic", range(0,1)) = 0.0
  _clip("clip", float) = 0
  [keywordenum(none, left, up, forward)]_mode("mode", float) = 0
 }
 subshader {
  tags { "rendertype"="opaque" }
  lod 200

  cgprogram
  // physically based standard lighting model, and enable shadows on all light types
  #pragma surface surf standard fullforwardshadows vertex:vert

  // use shader model 3.0 target, to get nicer looking lighting
  #pragma target 3.0

  sampler2d _maintex;

  struct input {
   float2 uv_maintex;
   float4 localpos;
  };

  half _glossiness;
  half _metallic;
  fixed4 _color;
  float _clip;
  float _mode;

  void vert(inout appdata_full i, out input o)
  {
   unity_initialize_output(input, o);
   o.localpos = i.vertex;
  }

  void surf (input i, inout surfaceoutputstandard o) {

   if(i.localpos.x >= _clip && _mode == 1 || i.localpos.y >= _clip && _mode == 2|| i.localpos.z >= _clip && _mode == 3)
   {
    clip(-1);
   }

   // albedo comes from a texture tinted by color
   fixed4 c = tex2d (_maintex, i.uv_maintex) * _color;
   o.albedo = c.rgb;
   // metallic and smoothness come from slider variables
   o.metallic = _metallic;
   o.smoothness = _glossiness;
   o.alpha = c.a;
  }
  endcg
 }
 fallback "diffuse"
}


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网