Built-in转URP Chapter10(4)-Mirror 镜子效果

话不多说,直接上代码,具体区别我后边会补充上,

暂时委屈各位,先锻炼下自己的“找不同”的能力,哈哈:

Built-CG写法:

Shader "Unity Shaders Book/Chapter 10/Mirror" {
	Properties {
		_MainTex("Render Tex", 2D) = "white" {}
		_AlphaScale("Aplpha Scale", Range(0, 1)) = 0.5
	}

	SubShader {
		// Tags {"Queue"="Geometry" "RenderType"="Opaque"}
		Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}

		Pass {
			Tags {"Lighting"="ForwardBase"}
			ZWrite Off
			Blend SrcAlpha OneMinusSrcAlpha

			CGPROGRAM
			#include "Lighting.cginc"

			#pragma vertex vert
			#pragma fragment frag

			sampler2D _MainTex;
			fixed _AlphaScale;

			struct a2v {
				float4 vertex : POSITION;
				float4 texcoord : TEXCOORD0;
			};

			struct v2f {
				float4 pos : SV_POSITION;
				float2 uv : TEXCOORD0;
			};

			v2f vert(a2v v) {
				v2f o;
				o.pos = UnityObjectToClipPos(v.vertex);
				o.uv = v.texcoord.xy;
				o.uv.x = 1 - o.uv.x;
				return o;
			}

			fixed4 frag(v2f i) : SV_Target {
				fixed4 texColor = tex2D(_MainTex, i.uv);
				return fixed4(texColor.rgb, texColor.a * _AlphaScale);
			}

			ENDCG
		}
	}
}

URP+HLSL写法:

Shader "Unity Shaders Book/Chapter 10/Mirror" {
	Properties {
		_MainTex("Render Tex", 2D) = "white" {}
		_AlphaScale("Aplpha Scale", Range(0, 1)) = 0.5
	}

	SubShader {
		Tags {
			"RenderPipeline"="UniversalPipeline"
			"Queue"="Geometry" "RenderType"="Opaque"
		}

		// Tags {
		// 	"RenderPipeline"="UniversalPipeline"
		// 	"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
		// }

		Pass {
			Tags {"Lighting"="UniversalForward"}
			// ZWrite Off
			// Blend SrcAlpha OneMinusSrcAlpha

			HLSLPROGRAM

			#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

			#pragma vertex vert
			#pragma fragment frag

CBUFFER_START(UnityPerMaterial)
			half _AlphaScale;
CBUFFER_END

			TEXTURE2D(_MainTex);
			SAMPLER(sampler_MainTex);

			struct a2v {
				float4 vertex : POSITION;
				half4 texcoord : TEXCOORD0;
			};

			struct v2f {
				float4 pos : SV_POSITION;
				float2 uv : TEXCOORD0;
			};

			v2f vert(a2v v) {
				v2f o;
				o.pos = TransformObjectToHClip(v.vertex.xyz);
				o.uv = v.texcoord.xy;
				o.uv.x = 1 - o.uv.x;
				return o;
			}

			half4 frag(v2f i) : SV_Target {
				half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
				return half4(texColor.rgb, texColor.a * _AlphaScale);
			}

			ENDHLSL
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值