use Render2D based solution rather than shader for alpha grid

https://github.com/FlaxEngine/FlaxEngine/pull/3281#issuecomment-3218049398
This commit is contained in:
Saas
2025-10-12 16:50:31 +02:00
parent 051d363358
commit be7871c292
2 changed files with 19 additions and 14 deletions

View File

@@ -134,11 +134,6 @@ namespace FlaxEditor
/// </summary>
public static string FlaxIconBlueTexture = "Engine/Textures/FlaxIconBlue";
/// <summary>
/// The checkboard material used as a background for displaying transparent colors.
/// </summary>
public static string ColorAlphaBackgroundGrid = "Editor/AlphaBackgroundGrid";
/// <summary>
/// The icon lists used by editor from the SegMDL2 font.
/// </summary>

View File

@@ -14,12 +14,7 @@ namespace FlaxEditor.GUI.Input
[HideInEditor]
public class ColorValueBox : Control
{
private const String ScaleParamName = "Scale";
// 4.8 is a magic number that makes the grid fit perfect in the color value box
private const float GridScale = 4.8f;
private bool _isMouseDown;
private MaterialBase checkerMaterial;
/// <summary>
/// Delegate function used for the color picker events handling.
@@ -106,9 +101,6 @@ namespace FlaxEditor.GUI.Input
public ColorValueBox()
: base(0, 0, 32, 18)
{
checkerMaterial = FlaxEngine.Content.LoadAsyncInternal<MaterialBase>(EditorAssets.ColorAlphaBackgroundGrid);
checkerMaterial = checkerMaterial.CreateVirtualInstance();
checkerMaterial.SetParameterValue(ScaleParamName, GridScale);
}
/// <summary>
@@ -146,7 +138,25 @@ namespace FlaxEditor.GUI.Input
if (isTransparent)
{
var alphaRect = new Rectangle(colorRect.Right, 0, Width - colorRect.Right, Height);
Render2D.DrawMaterial(checkerMaterial, alphaRect);
// Draw checkerboard pattern to part of the color value box
Render2D.FillRectangle(alphaRect, Color.White);
var smallRectSize = 7.9f;
var numHor = Mathf.CeilToInt(alphaRect.Width / smallRectSize);
var numVer = Mathf.CeilToInt(alphaRect.Height / smallRectSize);
for (int i = 0; i < numHor; i++)
{
for (int j = 0; j < numVer; j++)
{
if ((i + j) % 2 == 0)
{
var rect = new Rectangle(alphaRect.X + smallRectSize * i, alphaRect.Y + smallRectSize * j, new Float2(smallRectSize));
Render2D.PushClip(alphaRect);
Render2D.FillRectangle(rect, Color.Gray);
Render2D.PopClip();
}
}
}
Render2D.FillRectangle(alphaRect, _value);
}