Shader "Rive/UI/Default" { Properties { // Standard UI/Main texture (per renderer) [PerRendererData] _MainTex ("Texture", 2D) = "white" {} _Color ("Tint", Color) = (1,1,1,1) // Stencil properties so Mask / RectMask2D work [PerRendererData] _StencilComp ("Stencil Comparison", Float) = 8 [PerRendererData] _Stencil ("Stencil ID", Float) = 0 [PerRendererData] _StencilOp ("Stencil Operation", Float) = 0 [PerRendererData] _StencilWriteMask ("Stencil Write Mask", Float) = 255 [PerRendererData] _StencilReadMask ("Stencil Read Mask", Float) = 255 // Color mask / alpha clip for UI [PerRendererData] _ColorMask ("Color Mask", Float) = 15 [PerRendererData] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } // Stencil setup used by Mask / RectMask2D Stencil { Ref [_Stencil] Comp [_StencilComp] Pass [_StencilOp] ReadMask [_StencilReadMask] WriteMask [_StencilWriteMask] } ColorMask [_ColorMask] Cull Off ZWrite Off ZTest [unity_GUIZTestMode] Blend One OneMinusSrcAlpha Pass { Name "RiveGammaDecodeUI" CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 2.0 #include "UnityCG.cginc" #include "UnityUI.cginc" #pragma multi_compile __ UNITY_UI_CLIP_RECT #pragma multi_compile __ UNITY_UI_ALPHACLIP struct appdata_t { float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; float2 texcoord1 : TEXCOORD1; // used for RectMask2D UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; float4 worldPosition : TEXCOORD1; UNITY_VERTEX_OUTPUT_STEREO }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _Color; float4 _ClipRect; v2f vert (appdata_t v) { v2f o; UNITY_SETUP_INSTANCE_ID(v); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); o.worldPosition = v.vertex; o.vertex = UnityObjectToClipPos(v.vertex); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); o.color = v.color * _Color; return o; } half4 frag (v2f i) : SV_Target { // Sample texture half4 tex = tex2D(_MainTex, i.texcoord); // Rive renders premultiplied alpha into the render texture. // Convert to linear in un-premultiplied space, then premultiply again. #if !defined(UNITY_COLORSPACE_GAMMA) if (tex.a > 0.0h) { half3 unpremultiplied = tex.rgb / tex.a; tex.rgb = GammaToLinearSpace(unpremultiplied) * tex.a; } #endif // Preserve premultiplied alpha when Unity UI applies tint/CanvasGroup alpha. half4 color; color.a = tex.a * i.color.a; color.rgb = tex.rgb * i.color.rgb * i.color.a; // RectMask2D clipping // we scale both RGB and A to keep premultiplied invariant #ifdef UNITY_UI_CLIP_RECT half clipFactor = UnityGet2DClipping(i.worldPosition.xy, _ClipRect); color *= clipFactor; #endif // Optional alpha clipping for masking #ifdef UNITY_UI_ALPHACLIP clip (color.a - 0.001); #endif return color; } ENDCG } } Fallback "UI/Default" }