本文主要是介绍Unity 三维剖面shader简易版,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在法线连续的情况下效果凑合,目前项目着急,先用着,以后有时间慢慢改进。
Shader "ShenDong/SimpleSection"
{Properties{_MainTex("Texture", 2D) = "white" {}_IntensityX("Side X Intensity",range(0,2)) = 1_IntensityY("Side Y Intensity",range(0,2)) = 1_IntensityZ("Side Z Intensity",range(0,2)) = 1}SubShader{Tags { "RenderType" = "Opaque" }LOD 100Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float3 normal : NORMAL;};struct v2f{float3 normal : NORMAL;float4 vertex : TEXCOORD0;float4 screenvert : SV_POSITION;};sampler2D _MainTex;float4 _MainTex_ST;fixed _IntensityX;fixed _IntensityY;fixed _IntensityZ;v2f vert(appdata v){v2f o;o.vertex = v.vertex;o.normal = v.normal;o.screenvert = UnityObjectToClipPos(v.vertex);return o;}fixed4 frag(v2f i) : SV_Target{float3 f3 = i.vertex.xyz;f3.x = frac(f3.x);f3.y = frac(f3.y);f3.z = frac(f3.z);fixed4 c0 = tex2D(_MainTex, f3.xy * _MainTex_ST.xy + _MainTex_ST.zw);fixed4 c1 = tex2D(_MainTex, f3.yz * _MainTex_ST.xy + _MainTex_ST.zw);fixed4 c2 = tex2D(_MainTex, f3.zx * _MainTex_ST.xy + _MainTex_ST.zw);return c0 * i.normal.z* i.normal.z * _IntensityZ + c1 * i.normal.x * i.normal.x * _IntensityX + c2 * i.normal.y * i.normal.y * _IntensityY;}ENDCG}}
}
这篇关于Unity 三维剖面shader简易版的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!