unity-shader 템플릿 테스트 - 마스크
실험 효과
장면에 어떤 인물 a가 있는데 숨겨서 보이지 않는다. 평면 b를 사용하여 화면을 표시하고 평면 b가 인물 a와 중첩될 때 평면 b 범위 내의 인물을 표시한다.
의 원리
평면 b의 RenderQueue는 3000으로 설정된 투명도 유형 위에 있습니다.알파 값을 0으로 맞추면 돼요.
인물 a의 경우 3000+, 가설은 3001
효과
shader 코드
평면 b의 shader - testStencilByMaskPlane.shader
Shader "ITS/test/testStencilByMaskPlane" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_MainColor ("Color", Color) = (1, 1, 1, 1)
}
SubShader {
// Tags { "RenderType"="Transparent" }
Tags {
"Queue"="Transparent" "RenderType"="Transparent"}
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Stencil
{
Ref 1
Comp Always
Pass Replace
ZFail Replace
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _MainColor;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
col *= _MainColor;
UNITY_APPLY_FOG(i.fogCoord, col);
// UNITY_OPAQUE_ALPHA(col.a);
return col;
}
ENDCG
}
}
}
인물 a의 shader - test StencilBy MaskChar.shader
Shader "ITS/test/testStencilByMaskChar" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_MainColor ("Color", Color) = (1, 1, 1, 1)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
Pass {
ZTest LEqual
Stencil
{
Ref 1
Comp Equal
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _MainColor;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
col *= _MainColor;
UNITY_APPLY_FOG(i.fogCoord, col);
UNITY_OPAQUE_ALPHA(col.a);
return col;
}
ENDCG
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
UGUI 컨트롤 이동식 클래스 구성 요소 드래그Unity3d가 자체적으로 가지고 있는 UGUI는 드래그 기능이 없기 때문에 드래그 기능을 실현하려면 반드시 스스로 드래그 종류를 실현해야 한다.그래서 나는 일반적인 UGUI 드래그 구성 요소를 써서 사용이 편리하다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.