繁体   English   中英

Unity World Space Shader渐变颜色

[英]Unity World Space Shader Gradient Color

我正在做一个统一的项目,从Microsoft Kinect获取深度数据,并在Unity中使用这些数据构建地形。 然后我使用世界空间着色器使用渐变颜色为地形着色。 我当前的问题是,仅在“场景”视图中放大时才能看到渐变。 缩小时,所有颜色都会消失。 请参阅以下屏幕截图。 我为此苦苦挣扎了很长时间。 有人知道问题出在哪里吗? 谢谢。

缩小效果放大效果

Shader "Custom/Terrain World Space Shader" {

   Properties{
  _Color("Basic Color", Color) = (1,1,1,1) // White colorr
  _Height0("Max Height for Texture 0", float) = 2.0
  _Textre0("Texture 0 (RGB)", 2D) = "surface" {}
  _Height1("Max Height for Texture 1", float) = 4.0
  _Textre1("Texture 1 (RGB)", 2D) = "surface" {}
  _Height2("Max Height for Texture 1", float) = 6.0
  _Texture2("Texture 2 (RGB)", 2D) = "surface" {}
  _Height3("Max Height for Texture 1", float) = 8.0
  _Texture3("Texture 3 (RGB)", 2D) = "surface" {}
  _Height4("Max Height for Texture 1", float) = 10.0
  _Texture4("Texture 4 (RGB)", 2D) = "surface" {}
  _Height5("Max Height for Texture 1", float) = 12.0
  _Texture5("Texture 5 (RGB)", 2D) = "surface" {}
  _Height6("Max Height for Texture 1", float) = 14.0
  _Texture6("Texture 6 (RGB)", 2D) = "surface" {}
  _Height7("Max Height for Texture 1", float) = 16.0
  _Texture7("Texture 7 (RGB)", 2D) = "surface" {}
  _Height8("Max Height for Texture 1", float) = 18.0
  _Texture8("Texture 8 (RGB)", 2D) = "surface" {}
  _Height9("Max Height for Texture 1", float) = 20.0
  _Texture9("Texture 9 (RGB)", 2D) = "surface" {}
  _Height10("Max Height for Texture 1", float) = 22.0
  _Texture10("Texture 10 (RGB)", 2D) = "surface" {}
  _Height11("Max Height for Texture 1", float) = 24.0
  _Texture11("Texture 11 (RGB)", 2D) = "surface" {}
  _Height12("Max Height for Texture 1", float) = 26.0
  _Texture12("Texture 12 (RGB)", 2D) = "surface" {}
  _Texture13("Texture 13 (RGB)", 2D) = "surface" {}
  _Scale("Texture Scale", Float) = 1.0
   }

  SubShader{
  Tags{ "RenderType" = "Opaque" }

  CGPROGRAM
  #pragma surface surf Lambert

  struct Input {
  float3 worldNormal;
  float3 worldPos; 
  };

  sampler2D _Texture0;
  sampler2D _Texture1;
  sampler2D _Texture2;
  sampler2D _Texture3;
  sampler2D _Texture4;
  sampler2D _Texture5;
  sampler2D _Texture6;
  sampler2D _Texture7;
  sampler2D _Texture8;
  sampler2D _Texture9;
  sampler2D _Texture10;
  sampler2D _Texture11;
  sampler2D _Texture12;
  sampler2D _Texture13;
  float _Height0;
  float _Height1;
  float _Height2;
  float _Height3;
  float _Height4;
  float _Height5;
  float _Height6;
  float _Height7;
  float _Height8;
  float _Height9;
  float _Height10;
  float _Height11;
  float _Height12;
  float4 _Color;
  float _Scale;

  void surf(Input IN, inout SurfaceOutput o) {
     float2 UV;
     fixed4 c;
     UV = IN.worldPos.xz;
     if (IN.worldPos.y < _Height0) {
        c = tex2D(_Texture0, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height0 && IN.worldPos.y < _Height1) {
        c = tex2D(_Texture1, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height1 && IN.worldPos.y < _Height2) {
        c = tex2D(_Texture2, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height2 && IN.worldPos.y < _Height3) {
        c = tex2D(_Texture3, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height3 && IN.worldPos.y < _Height4) {
        c = tex2D(_Texture4, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height4 && IN.worldPos.y < _Height5) {
        c = tex2D(_Texture5, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height5 && IN.worldPos.y < _Height6) {
        c = tex2D(_Texture6, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height6 && IN.worldPos.y < _Height7) {
        c = tex2D(_Texture7, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height7 && IN.worldPos.y < _Height8) {
        c = tex2D(_Texture8, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height8 && IN.worldPos.y < _Height9) {
        c = tex2D(_Texture9, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height9 && IN.worldPos.y < _Height10) {
        c = tex2D(_Texture10, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height10 && IN.worldPos.y < _Height11) {
        c = tex2D(_Texture11, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height11 && IN.worldPos.y < _Height12) {
        c = tex2D(_Texture12, UV* _Scale);
     }
     else if (IN.worldPos.y >= _Height12) {
        c = tex2D(_Texture13, UV* _Scale);
     }
     o.Albedo = c.rgb * _Color;
  }

  ENDCG
}

 Fallback "VertexLit"
}

用更大的数字设置地形“基本地图距离”设置,所有渐变颜色都会显示出来。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM