From 23952bac55b36202d5d0143797aaeaffa2de2612 Mon Sep 17 00:00:00 2001 From: freezy Date: Thu, 21 Aug 2025 08:45:10 +0200 Subject: [PATCH] fix: Dot matrix shader. --- .../Display/DotMatrixDisplayGraph.shadergraph | 328 ++++++++---------- .../Srp/Display/DotMatrixDisplayShader.hlsl | 44 ++- 2 files changed, 171 insertions(+), 201 deletions(-) diff --git a/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayGraph.shadergraph b/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayGraph.shadergraph index 2866a508a..877806880 100644 --- a/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayGraph.shadergraph +++ b/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayGraph.shadergraph @@ -100,7 +100,7 @@ "m_Id": "43b86669fec34ffebed1498171e47274" }, { - "m_Id": "ff9140e9cb93486a810837acc15f95dc" + "m_Id": "78435179aaa34d12bc9497460a7395b2" } ], "m_GroupDatas": [], @@ -134,20 +134,6 @@ "m_SlotId": 0 } }, - { - "m_OutputSlot": { - "m_Node": { - "m_Id": "386fcbc47636417199e958b1ab89b4b7" - }, - "m_SlotId": 0 - }, - "m_InputSlot": { - "m_Node": { - "m_Id": "ff9140e9cb93486a810837acc15f95dc" - }, - "m_SlotId": 0 - } - }, { "m_OutputSlot": { "m_Node": { @@ -185,9 +171,9 @@ }, "m_InputSlot": { "m_Node": { - "m_Id": "ff9140e9cb93486a810837acc15f95dc" + "m_Id": "5e3f39ce35b74ffcb64ad89380f95b94" }, - "m_SlotId": 1 + "m_SlotId": 0 } }, { @@ -399,20 +385,6 @@ }, "m_SlotId": 2 } - }, - { - "m_OutputSlot": { - "m_Node": { - "m_Id": "ff9140e9cb93486a810837acc15f95dc" - }, - "m_SlotId": 2 - }, - "m_InputSlot": { - "m_Node": { - "m_Id": "5e3f39ce35b74ffcb64ad89380f95b94" - }, - "m_SlotId": 0 - } } ], "m_VertexContext": { @@ -458,6 +430,9 @@ }, { "m_Id": "b3d8175ca262420ebb21eb8aa266a8b0" + }, + { + "m_Id": "78435179aaa34d12bc9497460a7395b2" } ] }, @@ -474,6 +449,7 @@ "m_OutputNode": { "m_Id": "" }, + "m_SubDatas": [], "m_ActiveTargets": [ { "m_Id": "d608f7b06c6c404da16db5fbc6a8c960" @@ -579,6 +555,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -619,31 +596,6 @@ "m_BareResource": false } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", - "m_ObjectId": "1ece0e1a01174ca5aa37a8319730c443", - "m_Id": 0, - "m_DisplayName": "A", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "A", - "m_StageCapability": 3, - "m_Value": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - "w": 0.0 - }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - "w": 0.0 - }, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", @@ -683,6 +635,7 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, @@ -710,29 +663,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", - "m_ObjectId": "307eb4235a11432cba1413f411efee44", - "m_Id": 2, - "m_DisplayName": "Out", - "m_SlotType": 1, - "m_Hidden": false, - "m_ShaderOutputName": "Out", - "m_StageCapability": 3, - "m_Value": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -774,6 +704,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -796,6 +727,7 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, @@ -823,6 +755,7 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, @@ -872,10 +805,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -510.6667785644531, - "y": -958.0001220703125, - "width": 208.0, - "height": 374.0 + "x": -517.1429443359375, + "y": -952.0001220703125, + "width": 209.1429443359375, + "height": 375.4285888671875 } }, "m_Slots": [ @@ -901,6 +834,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -908,6 +842,7 @@ "m_SourceType": 0, "m_FunctionName": "Dot", "m_FunctionSource": "4a60f979fa395074196e146817eba7c1", + "m_FunctionSourceUsePragmas": true, "m_FunctionBody": "Enter function body here..." } @@ -937,6 +872,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -983,10 +919,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -171.33328247070313, - "y": -906.0000610351563, - "width": 229.3333282470703, - "height": 186.0 + "x": 125.71430206298828, + "y": -835.4285888671875, + "width": 225.71429443359376, + "height": 186.85711669921876 } }, "m_Slots": [ @@ -1006,6 +942,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1029,6 +966,7 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, @@ -1053,10 +991,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1722.666748046875, - "y": -503.3332824707031, - "width": 125.33338165283203, - "height": 34.000003814697269 + "x": -71.99999237060547, + "y": -771.9999389648438, + "width": 121.71424865722656, + "height": 34.2857666015625 } }, "m_Slots": [ @@ -1067,6 +1005,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1088,7 +1027,7 @@ "m_StageCapability": 3, "m_BareResource": false, "m_Texture": { - "m_SerializedTexture": "{\"texture\":{\"instanceID\":0}}", + "m_SerializedTexture": "", "m_Guid": "" }, "m_DefaultType": 0 @@ -1159,6 +1098,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1213,6 +1153,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1280,13 +1221,14 @@ "m_DistortionDepthTest": true, "m_AddPrecomputedVelocity": false, "m_TransparentWritesMotionVec": false, - "m_AlphaToMask": false, "m_DepthOffset": false, + "m_ConservativeDepthOffset": false, "m_TransparencyFog": true, "m_AlphaTestShadow": false, "m_BackThenFrontRendering": false, "m_TransparentDepthPrepass": false, "m_TransparentDepthPostpass": false, + "m_TransparentPerPixelSorting": false, "m_SupportLodCrossFade": false } @@ -1363,6 +1305,7 @@ "m_ObjectId": "70d02c776f554c5fb9fc61bd2a11a272", "m_RayTracing": false, "m_MaterialType": 0, + "m_MaterialTypeMask": 2, "m_RefractionModel": 0, "m_SSSTransmission": true, "m_EnergyConservingSpecular": true, @@ -1441,6 +1384,40 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "78435179aaa34d12bc9497460a7395b2", + "m_Group": { + "m_Id": "" + }, + "m_Name": "SurfaceDescription.Alpha", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "e857fe503e3d4388bbd4f4ca96216ac2" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "SurfaceDescription.Alpha" +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", @@ -1467,6 +1444,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1523,7 +1501,7 @@ "m_SGVersion": 0, "m_Type": "UnityEditor.Rendering.HighDefinition.ShaderGraph.SystemData", "m_ObjectId": "7dfde410de964ab28e15ca2ac7a38c8e", - "m_MaterialNeedsUpdateHash": 529, + "m_MaterialNeedsUpdateHash": 0, "m_SurfaceType": 0, "m_RenderingPass": 1, "m_BlendMode": 0, @@ -1533,13 +1511,23 @@ "m_OpaqueCullMode": 2, "m_SortPriority": 0, "m_AlphaTest": false, + "m_ExcludeFromTUAndAA": false, "m_TransparentDepthPrepass": false, "m_TransparentDepthPostpass": false, "m_SupportLodCrossFade": false, "m_DoubleSidedMode": 0, "m_DOTSInstancing": false, - "m_Version": 0, - "m_FirstTimeMigrationExecuted": true, + "m_CustomVelocity": false, + "m_Tessellation": false, + "m_TessellationMode": 0, + "m_TessellationFactorMinDistance": 20.0, + "m_TessellationFactorMaxDistance": 50.0, + "m_TessellationFactorTriangleSize": 100.0, + "m_TessellationShapeFactor": 0.75, + "m_TessellationBackFaceCullEpsilon": -0.25, + "m_TessellationMaxDisplacement": 0.009999999776482582, + "m_DebugSymbols": false, + "m_Version": 2, "inspectorFoldoutMask": 0 } @@ -1738,6 +1726,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1745,6 +1734,7 @@ "m_SourceType": 0, "m_FunctionName": "Dot", "m_FunctionSource": "4a60f979fa395074196e146817eba7c1", + "m_FunctionSourceUsePragmas": true, "m_FunctionBody": "Enter function body here..." } @@ -1760,10 +1750,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1722.666748046875, - "y": -559.3333740234375, - "width": 132.666748046875, - "height": 34.000030517578128 + "x": -1722.857177734375, + "y": -581.71435546875, + "width": 128.5714111328125, + "height": 34.28570556640625 } }, "m_Slots": [ @@ -1774,6 +1764,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1823,6 +1814,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1842,10 +1834,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1784.0, - "y": -1419.333251953125, - "width": 208.0, - "height": 312.6666259765625 + "x": -1749.1429443359375, + "y": -1419.4287109375, + "width": 209.1429443359375, + "height": 313.7144775390625 } }, "m_Slots": [ @@ -1856,6 +1848,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1905,10 +1898,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1722.666748046875, - "y": -761.3334350585938, - "width": 109.33336639404297, - "height": 34.0 + "x": -1722.857177734375, + "y": -717.71435546875, + "width": 108.0, + "height": 34.28564453125 } }, "m_Slots": [ @@ -1919,6 +1912,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1969,6 +1963,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2059,6 +2054,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2081,6 +2077,7 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, @@ -2126,29 +2123,6 @@ "m_ObjectId": "bdc3a45891fa4a00b64f72f0271fe623" } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", - "m_ObjectId": "c040cd25733540549782401f7def025a", - "m_Id": 1, - "m_DisplayName": "B", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "B", - "m_StageCapability": 3, - "m_Value": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.AddNode", @@ -2161,10 +2135,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -127.0001220703125, - "y": -616.0, - "width": 208.0001220703125, - "height": 302.0 + "x": -131.99996948242188, + "y": -547.4285888671875, + "width": 209.14288330078126, + "height": 303.42864990234377 } }, "m_Slots": [ @@ -2181,6 +2155,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2213,6 +2188,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2294,7 +2270,9 @@ "m_Id": "7dfde410de964ab28e15ca2ac7a38c8e" } ], - "m_CustomEditorGUI": "" + "m_CustomEditorGUI": "", + "m_SupportVFX": false, + "m_SupportLineRendering": false } { @@ -2323,6 +2301,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2356,6 +2335,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2402,6 +2382,7 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, @@ -2438,6 +2419,21 @@ "m_Channel": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "e857fe503e3d4388bbd4f4ca96216ac2", + "m_Id": 0, + "m_DisplayName": "Alpha", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Alpha", + "m_StageCapability": 2, + "m_Value": 1.0, + "m_DefaultValue": 1.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", @@ -2504,6 +2500,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2568,10 +2565,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -918.6666259765625, - "y": -1419.333251953125, - "width": 208.0, - "height": 434.6665954589844 + "x": -916.0001220703125, + "y": -1419.4287109375, + "width": 209.142822265625, + "height": 434.85723876953127 } }, "m_Slots": [ @@ -2603,13 +2600,15 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] }, "m_TextureType": 0, "m_NormalMapSpace": 0, - "m_EnableGlobalMipBias": true + "m_EnableGlobalMipBias": true, + "m_MipSamplingMode": 0 } { @@ -2644,6 +2643,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2651,6 +2651,7 @@ "m_SourceType": 0, "m_FunctionName": "SamplePosition", "m_FunctionSource": "4a60f979fa395074196e146817eba7c1", + "m_FunctionSourceUsePragmas": true, "m_FunctionBody": "Enter function body here..." } @@ -2691,48 +2692,3 @@ "m_BareResource": false } -{ - "m_SGVersion": 1, - "m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode", - "m_ObjectId": "ff9140e9cb93486a810837acc15f95dc", - "m_Group": { - "m_Id": "" - }, - "m_Name": "HDRP_Emission (Custom Function)", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": 242.4998779296875, - "y": -951.9999389648438, - "width": 243.0, - "height": 301.99993896484377 - } - }, - "m_Slots": [ - { - "m_Id": "1ece0e1a01174ca5aa37a8319730c443" - }, - { - "m_Id": "c040cd25733540549782401f7def025a" - }, - { - "m_Id": "307eb4235a11432cba1413f411efee44" - } - ], - "synonyms": [ - "code", - "HLSL" - ], - "m_Precision": 0, - "m_PreviewExpanded": true, - "m_PreviewMode": 0, - "m_CustomColors": { - "m_SerializableColors": [] - }, - "m_SourceType": 1, - "m_FunctionName": "HDRP_Emission", - "m_FunctionSource": "", - "m_FunctionBody": "#ifdef UNITY_HEADER_HD_INCLUDED\nOut = B;\n#else\nOut = A.xyz;\n#endif" -} - diff --git a/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayShader.hlsl b/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayShader.hlsl index d011f4b73..beb21e19a 100644 --- a/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayShader.hlsl +++ b/VisualPinball.Unity/Assets/Shaders/Srp/Display/DotMatrixDisplayShader.hlsl @@ -1,32 +1,48 @@ -void SamplePosition_float(float2 uv, float2 dimensions, out float2 dotCenter) +// DXR-safe AA width helper: uses fwidth in raster, constant UV feather in ray tracing. +inline float AAWidth(float d, float2 dimensions) +{ + #ifdef SHADER_STAGE_RAY_TRACING + // Feather in UVs of a single dot cell. Tune the scale as needed. + float uvFeather = max(1.0 / max(dimensions.x, dimensions.y), 1e-4) * 0.75; + return uvFeather; + #else + return fwidth(d); + #endif +} + +void SamplePosition_float(float2 uv, float2 dimensions, out float2 dotCenter) { float2 dimensionsPerDot = 1. / dimensions; float2 dotPos = floor(uv * dimensions); dotCenter = dimensionsPerDot * (dotPos + 0.5); } -float Ellipse(float2 _uv, float _padding) +float Ellipse(float2 _uv, float _padding, float2 dimensions) { float len = 1.0 - _padding; float d = length((_uv * 2 - 1) / float2(len, len)); - return saturate((1 - d) / fwidth(d)); + float w = AAWidth(d, dimensions); + return saturate((1 - d) / w); } -float RoundedRectangle(float2 _uv, float _padding, float _radius) +float RoundedRectangle(float2 _uv, float _padding, float _radius, float2 dimensions) { float len = 1.0 - _padding; _radius = max(min(min(abs(_radius * 2), abs(len)), abs(len)), 1e-5); float2 uv = abs(_uv * 2 - 1) - float2(len, len) + _radius; float d = length(max(0, uv)) / _radius; - return saturate((1 - d) / fwidth(d)); + float w = AAWidth(d, dimensions); + return saturate((1 - d) / w); } -float Rectangle(float2 _uv, float _padding) +float Rectangle(float2 _uv, float _padding, float2 dimensions) { float len = 1.0 - _padding; float2 d = abs(_uv * 2 - 1) - float2(len, len); - d = 1 - d / fwidth(d); - return saturate(min(d.x, d.y)); + // Use a single AA width for both axes to avoid per-axis derivatives. + float w = AAWidth(max(d.x, d.y), dimensions); + float2 s = 1 - d / w; + return saturate(min(s.x, s.y)); } void Dot_float(float2 uv, float2 dimensions, float padding, float roundness, float4 color, out float4 output) @@ -34,12 +50,10 @@ void Dot_float(float2 uv, float2 dimensions, float padding, float roundness, flo float2 pos = frac(uv * dimensions); if (roundness >= 0.5) { - output = color * Ellipse(pos, padding); - - } else if (roundness <= 0) { - output = color * Rectangle(pos, padding); - - } else { - output = color * RoundedRectangle(pos, padding, roundness); + output = color * Ellipse(pos, padding, dimensions); + } else if (roundness <= 0) { + output = color * Rectangle(pos, padding, dimensions); + } else{ + output = color * RoundedRectangle(pos, padding, roundness, dimensions); } }