我有幾個問題:/
Unity 2D:區域顏色反轉效果
這可能與著色器圖?
是否可以使用紋理的 alpha 通道而不是網格?
謝謝。
uj5u.com熱心網友回復:
是的,可以使用著色器圖,我會推薦這種方法,它可以使它變得非常容易。你只需要弄清楚你想如何通過你想要反轉的區域。但是,是的,有一個名為 One Minus 的節點,我認為這就是您要尋找的節點。
uj5u.com熱心網友回復:
好的,所以找到了解決方案。
無法使用著色器圖,因為節點“場景顏色”不適用于 URP。
蒸汽不和諧幫助我做到這一點
Shader "Unlit/invertColorArea"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Threshold ("Threshold", Range(0., 1.)) = 0
_ThresholdDiscard ("ThresholdDiscard", Range(0., 1.)) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Cull off
Blend OneMinusDstColor Zero
PASS
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0 Alpha:Blend
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
fixed4 _Color;
float _Threshold;
float _ThresholdDiscard;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
col.rgb = abs(_Threshold - col.rgb);
if(col.a < _ThresholdDiscard)
discard;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/340631.html
