Unity 之 Shader 对Z深度的偏移


对Z深度的偏移

Offset 指令给了我们一个操作正常的ZTest 检测结果的手段。 
Offset有两个参数,这两个参数理解起来不是很直观,而且具体实现是和硬件相关的

下面在实际例子中看他的效果

Shader "Custom/PassFive" { Properties { //定义一个贴图 _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags {"RenderType" = "Opaque" "IGNOREPROJECTOR" = "TRUE" "QUEUE" = "Transparent"} LOD 200 Pass { //AlphaTest Greater 0.6 //AlphaTest Less 0.5 //AlphaTest Greater 0.4 //AlphaTest Less 0.9 Blend SrcAlpha One //Blend SrcColor OneMinusSrcColor //BlendOp RevSub //ColorMask RG //ColorMask RB //ZTest Greater Offset 0, 0 // 通过绑定固定通道来使用定点色 BindChannels { Bind "Vertex", vertex // 绑定定点 Bind "Normal", normal Bind "Color", color Bind "Texcoord", texcoord0 Bind "Texcoord", texcoord1 } //给材质设置 贴图 SetTexture [_MainTex] { Combine texture * primary double } } } FallBack "Diffuse" } 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

这里写图片描述

下面将 Offset 0, 0 改为 Offset -10000, 0 
效果如下

这里写图片描述


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM