I have a leaderboard where I display a player's information and their profile picture.
picture1
The picture (this is the cat's head on the left) was made in 3D so that I could animate it for different skins. I made a mask for the scroll view and it works fine, as you can see in the picture above.
Under the rating I want to show the player’s place and his skin.picture2 .
But in order for his skin to be displayed, I need to put the same max in this place as on the scroll view (because the skins have the same shaders and it won’t be drawn without stencil ref =1) But when I put the shader in that place that makes the ref = 1, then other objects start to be drawn along with the one I need (since the scroll view goes far down).
picture3
I tried to solve this in different ways, but I came to the conclusion that since the objects have the same material, they will always be drawn together, regardless of what masks and comparisons I make in the shader.
My shader mask:
Shader "Custom/UIMaskFor3D"
{
Properties
{
[IntRange] _StencilComp ("Stencil Comparison", Range(1,8)) = 1
[IntRange] _Stencil ("Stencil ID", Range(0,255)) = 0
[IntRange] _StencilOp ("Stencil Operation", Range(0,7))=2
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
}
SubShader
{
Tags { "Queue"="Geometry-1" }
Blend Zero One
ZWrite Off
Pass {
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
}
}
}
}
My shader for skin:
Shader "Unlit/Transparent" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
[IntRange] _StencilComp ("Stencil Comparison", Range(1,8)) = 1
[IntRange] _Stencil ("Stencil ID", Range(0,255)) = 1
[IntRange] _StencilOp ("Stencil Operation", Range(0,7))=0
_StencilWriteMask ("Stencil Write Mask", Range(0,255)) = 255.000000
_StencilReadMask ("Stencil Read Mask", Range(0,255)) = 255.000000
_ColorMask ("Color Mask", Float) = 15
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Stencil{
Ref [_Stencil]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
Comp Equal
}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
return col;
}
ENDCG
}
}
}