unity 等高线创建方法

unity 等高线创建方法

请添加图片描述工程文件下载

完整shader

Shader "SongShaderDemo/ContourLineOne"
{
    
    
	Properties
	{
    
    
		_MainTex("Texture", 2D) = "white" {
    
    }
		_Linewide("Linewide",Range(0,5)) = 1
		_ContourLine("ContourLine",Int) = 10
		_Color("color",Color) = (1,1,1,1)   
	}
		SubShader
		{
    
    
			Tags {
    
     "RenderType" = "Transparent"  "Queue" = "Transparent"}
			LOD 100


			Pass
			{
    
    
						Blend SrcAlpha OneMinusSrcAlpha
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag


				#include "UnityCG.cginc"

				struct appdata
				{
    
    
					float4 vertex : POSITION;
					float2 uv : TEXCOORD0;
				};

				struct v2f
				{
    
    
					float2 uv : TEXCOORD0;
					float4 vertex : SV_POSITION;
					float3 worldPos : TEXCOORD1;
				};
				CBUFFER_START(UnityPerMaterial)
				sampler2D _MainTex;
				float4 _MainTex_ST;
				fixed _Linewide;
				fixed _ContourLine;
				fixed4 _Color;
				CBUFFER_END
				v2f vert(appdata v)
				{
    
    
					v2f o;
					o.vertex = UnityObjectToClipPos(v.vertex);
					o.uv = TRANSFORM_TEX(v.uv, _MainTex);
					float3 curWorldpos = mul(unity_ObjectToWorld, v.vertex).xyz;

						o.worldPos = curWorldpos;

							return o;
						}

						fixed4 frag(v2f i) : SV_Target
						{
    
    
							fixed4 col = tex2D(_MainTex, i.uv);
							if (i.worldPos.y%_ContourLine < _Linewide || _ContourLine - (i.worldPos.y%_ContourLine) < _Linewide)
							{
    
    
								return _Color;
							}
							else
							{
    
    
								return col;
							}

						}
						ENDCG
					}
		}
}

猜你喜欢

转载自blog.csdn.net/dxs1990/article/details/125414038