where does variable _ClipRect in UI-Default.Shader come from?
My Unity Version is 2018.2.3F1, in the Buildin shader: UI-Default.shader, there will be a float4 variable named "_ClipRect", I want know what is it and who set its value? the code is:
//it was declared in the Pass,and it didn't declare in the Properties
float4 _ClipRect;
//used in the fragment function
fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
#ifdef UNITY_UI_CLIP_RECT
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#endif
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
//and here is the UnityGet2DClipping function code:
inline float UnityGet2DClipping (in float2 position, in float4 clipRect)
{
float2 inside = step(clipRect.xy, position.xy) * step(position.xy, clipRect.zw);
return inside.x * inside.y;
}
I know when i add A "Rect$$anonymous$$ask2D" component, code in line 10 will execute, that is , the variable should be set by the Rect$$anonymous$$ask2D component, but I can't find the source Code of this component,so i have no idea about what exactly the values inside the _ClipRect, and i am puzzled about the UnityGet2DClipping function , don't know what it is doing
Source code all of Unity's UI is available on Bitbucket - here is a link to the file you need - https://bitbucket.org/Unity-Technologies/ui/src/2019.1/UnityEngine.UI/UI/Core/Rect$$anonymous$$ask2D.cs
Answer by JokeMaker · Jul 07, 2021 at 05:18 PM
when it is clipped by a RectMask2D
, UNITY_UI_CLIP_RECT
is defined, and _ClipRect
is set.
Your answer
Follow this Question
Related Questions
So many errors! And I need help with the GUI 1 Answer
Not able to add Sprite in the Inspector. 0 Answers
Sketchup to unity scale 0 Answers
Unity UI - Button Slow On Some Devices? 0 Answers