From 38d88c1265a0f3aa430fe9a26e6e35d94314e533 Mon Sep 17 00:00:00 2001 From: freezy Date: Thu, 21 Aug 2025 11:07:21 +0200 Subject: [PATCH 1/2] fix: Segment shader. --- .../Display/SegmentDisplayGraph.shadergraph | 409 ++++++++++-------- .../Srp/Display/SegmentDisplayShader.hlsl | 237 +++++----- 2 files changed, 357 insertions(+), 289 deletions(-) diff --git a/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayGraph.shadergraph b/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayGraph.shadergraph index 11b95b7e9..e8d8859ce 100644 --- a/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayGraph.shadergraph +++ b/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayGraph.shadergraph @@ -142,7 +142,7 @@ "m_Id": "a03ddb067fd64232afc1285d1c4fe423" }, { - "m_Id": "d7a11082affc4a9b86ef3d15523ebdc5" + "m_Id": "55995b5dffbe4fd8b021bef37e1a4993" } ], "m_GroupDatas": [], @@ -423,9 +423,9 @@ }, "m_InputSlot": { "m_Node": { - "m_Id": "d7a11082affc4a9b86ef3d15523ebdc5" + "m_Id": "e1130d45aea34d8abdb72ba39be96139" }, - "m_SlotId": 1 + "m_SlotId": 0 } }, { @@ -456,20 +456,6 @@ "m_SlotId": 1 } }, - { - "m_OutputSlot": { - "m_Node": { - "m_Id": "bbf02ed4cd92417c804bb3108b4a9b6a" - }, - "m_SlotId": 2 - }, - "m_InputSlot": { - "m_Node": { - "m_Id": "d7a11082affc4a9b86ef3d15523ebdc5" - }, - "m_SlotId": 0 - } - }, { "m_OutputSlot": { "m_Node": { @@ -498,20 +484,6 @@ "m_SlotId": 11 } }, - { - "m_OutputSlot": { - "m_Node": { - "m_Id": "d7a11082affc4a9b86ef3d15523ebdc5" - }, - "m_SlotId": 2 - }, - "m_InputSlot": { - "m_Node": { - "m_Id": "e1130d45aea34d8abdb72ba39be96139" - }, - "m_SlotId": 0 - } - }, { "m_OutputSlot": { "m_Node": { @@ -626,6 +598,9 @@ }, { "m_Id": "ca8a75f0eeed42b981894eb21f91d540" + }, + { + "m_Id": "55995b5dffbe4fd8b021bef37e1a4993" } ] }, @@ -642,6 +617,7 @@ "m_OutputNode": { "m_Id": "" }, + "m_SubDatas": [], "m_ActiveTargets": [ { "m_Id": "70b7c54e19f74cd191c6c4e86e048608" @@ -682,16 +658,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 0.0, "m_FloatType": 0, "m_RangeValues": { "x": 0.0, "y": 1.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -747,6 +736,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -762,7 +752,6 @@ "m_DistortionDepthTest": true, "m_AddPrecomputedVelocity": false, "m_TransparentWritesMotionVec": false, - "m_AlphaToMask": false, "m_DepthOffset": false, "m_ConservativeDepthOffset": false, "m_TransparencyFog": true, @@ -770,6 +759,7 @@ "m_BackThenFrontRendering": false, "m_TransparentDepthPrepass": false, "m_TransparentDepthPostpass": false, + "m_TransparentPerPixelSorting": false, "m_SupportLodCrossFade": false } @@ -788,16 +778,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 0.0, "m_FloatType": 0, "m_RangeValues": { "x": 0.0, "y": 1.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -850,6 +853,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -904,16 +908,20 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": { - "m_SerializedTexture": "{\"texture\":{\"instanceID\":0}}", + "m_SerializedTexture": "", "m_Guid": "" }, "isMainTexture": false, "useTilingAndOffset": false, + "useTexelSize": true, "m_Modifiable": true, "m_DefaultType": 0 } @@ -933,16 +941,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 1.0, "m_FloatType": 0, "m_RangeValues": { "x": 0.0, "y": 1.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -1002,7 +1023,7 @@ "m_StageCapability": 3, "m_BareResource": false, "m_Texture": { - "m_SerializedTexture": "{\"texture\":{\"instanceID\":0}}", + "m_SerializedTexture": "", "m_Guid": "" }, "m_DefaultType": 0 @@ -1034,6 +1055,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1082,6 +1104,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1116,10 +1139,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1032.0, - "y": -816.0000610351563, - "width": 121.33331298828125, - "height": 34.0 + "x": -1021.142822265625, + "y": -862.2857666015625, + "width": 117.71429443359375, + "height": 34.2857666015625 } }, "m_Slots": [ @@ -1130,6 +1153,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1202,16 +1226,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 2.0, "m_FloatType": 2, "m_RangeValues": { "x": 0.0, "y": 1.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -1288,6 +1325,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1323,6 +1361,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1334,25 +1373,36 @@ { "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", - "m_ObjectId": "54f1ab9aabde4e74b8b1a499d227360a", - "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_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "55995b5dffbe4fd8b021bef37e1a4993", + "m_Group": { + "m_Id": "" }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0 + "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_Labels": [] + "m_Slots": [ + { + "m_Id": "9a78607ffeb249dd8003ce38e2f3c5f9" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "SurfaceDescription.Alpha" } { @@ -1381,6 +1431,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1405,10 +1456,13 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": { "x": 0.30000001192092898, "y": 0.5, @@ -1443,6 +1497,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1576,6 +1631,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1666,6 +1722,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -1673,6 +1730,7 @@ "m_SourceType": 0, "m_FunctionName": "SegmentDisplay", "m_FunctionSource": "f52e22b29fa2471449033035256abdb4", + "m_FunctionSourceUsePragmas": true, "m_FunctionBody": "Enter function body here..." } @@ -1698,7 +1756,8 @@ } ], "m_CustomEditorGUI": "", - "m_SupportVFX": false + "m_SupportVFX": false, + "m_SupportLineRendering": false } { @@ -1788,10 +1847,13 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": { "r": 1.0, "g": 0.4000000059604645, @@ -1823,6 +1885,7 @@ "m_ObjectId": "7b3360db276c4b2fa8618a61732a9b8e", "m_RayTracing": false, "m_MaterialType": 0, + "m_MaterialTypeMask": 2, "m_RefractionModel": 0, "m_SSSTransmission": true, "m_EnergyConservingSpecular": true, @@ -1919,10 +1982,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1032.0, - "y": -34.0000114440918, - "width": 121.00006103515625, - "height": 33.999961853027347 + "x": 30.8571720123291, + "y": -678.2858276367188, + "width": 120.00000762939453, + "height": 34.28582763671875 } }, "m_Slots": [ @@ -1933,6 +1996,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2035,16 +2099,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 2.0, "m_FloatType": 0, "m_RangeValues": { "x": 0.0, "y": 1.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -2094,6 +2171,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2144,6 +2222,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2165,7 +2244,7 @@ "m_StageCapability": 3, "m_BareResource": false, "m_Texture": { - "m_SerializedTexture": "{\"texture\":{\"instanceID\":0}}", + "m_SerializedTexture": "", "m_Guid": "" }, "m_DefaultType": 0 @@ -2197,6 +2276,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2242,10 +2322,13 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": { "x": 1.399999976158142, "y": 0.0, @@ -2280,6 +2363,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2304,6 +2388,21 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "9a78607ffeb249dd8003ce38e2f3c5f9", + "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.Rendering.HighDefinition.ShaderGraph.HDLitSubTarget", @@ -2336,6 +2435,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2357,10 +2457,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": 64.00004577636719, - "y": -730.0, - "width": 225.99998474121095, - "height": 186.0 + "x": 247.4286346435547, + "y": -748.5714721679688, + "width": 224.5714569091797, + "height": 186.28564453125 } }, "m_Slots": [ @@ -2380,6 +2480,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2403,10 +2504,13 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": { "r": 0.25471699237823489, "g": 0.25471699237823489, @@ -2468,6 +2572,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2534,6 +2639,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2541,6 +2647,7 @@ "m_SourceType": 0, "m_FunctionName": "SegmentDisplay", "m_FunctionSource": "f52e22b29fa2471449033035256abdb4", + "m_FunctionSourceUsePragmas": true, "m_FunctionBody": "Enter function body here..." } @@ -2613,10 +2720,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -266.0000305175781, - "y": -859.9999389648438, - "width": 207.99996948242188, - "height": 301.9999694824219 + "x": -266.85711669921877, + "y": -901.1428833007813, + "width": 209.14283752441407, + "height": 303.4285888671875 } }, "m_Slots": [ @@ -2633,6 +2740,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2691,7 +2799,7 @@ "m_SGVersion": 0, "m_Type": "UnityEditor.Rendering.HighDefinition.ShaderGraph.SystemData", "m_ObjectId": "c13c9c2245e946788164ab5b0b62b2c6", - "m_MaterialNeedsUpdateHash": 529, + "m_MaterialNeedsUpdateHash": 0, "m_SurfaceType": 0, "m_RenderingPass": 1, "m_BlendMode": 0, @@ -2701,6 +2809,7 @@ "m_OpaqueCullMode": 2, "m_SortPriority": 0, "m_AlphaTest": false, + "m_ExcludeFromTUAndAA": false, "m_TransparentDepthPrepass": false, "m_TransparentDepthPostpass": false, "m_SupportLodCrossFade": false, @@ -2715,7 +2824,8 @@ "m_TessellationShapeFactor": 0.75, "m_TessellationBackFaceCullEpsilon": -0.25, "m_TessellationMaxDisplacement": 0.009999999776482582, - "m_Version": 1, + "m_DebugSymbols": false, + "m_Version": 2, "inspectorFoldoutMask": 0 } @@ -2784,31 +2894,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", - "m_ObjectId": "c6d79c04c8c94dd482a54e9fa71bcd35", - "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.Vector1MaterialSlot", @@ -2887,6 +2972,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -2968,6 +3054,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3073,51 +3160,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 1, - "m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode", - "m_ObjectId": "d7a11082affc4a9b86ef3d15523ebdc5", - "m_Group": { - "m_Id": "" - }, - "m_Name": "HDRP_Emission (Custom Function)", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": 289.5, - "y": -859.9999389648438, - "width": 208.0001220703125, - "height": 301.99993896484377 - } - }, - "m_Slots": [ - { - "m_Id": "c6d79c04c8c94dd482a54e9fa71bcd35" - }, - { - "m_Id": "54f1ab9aabde4e74b8b1a499d227360a" - }, - { - "m_Id": "fe485e86546549aea458950f5246881e" - } - ], - "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" -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector2MaterialSlot", @@ -3165,6 +3207,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": false, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3218,6 +3261,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3279,16 +3323,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 0.0, "m_FloatType": 1, "m_RangeValues": { "x": -3.0, "y": 3.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -3306,16 +3363,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 0.05000000074505806, "m_FloatType": 1, "m_RangeValues": { "x": 0.0, "y": 0.5 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { @@ -3429,6 +3499,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3477,6 +3548,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3512,6 +3584,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3562,6 +3635,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3595,6 +3669,7 @@ "synonyms": [], "m_Precision": 0, "m_PreviewExpanded": true, + "m_DismissedVersion": 0, "m_PreviewMode": 0, "m_CustomColors": { "m_SerializableColors": [] @@ -3602,29 +3677,6 @@ "m_SerializedDescriptor": "SurfaceDescription.Smoothness" } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", - "m_ObjectId": "fe485e86546549aea458950f5246881e", - "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": 1, "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", @@ -3640,16 +3692,29 @@ "m_GeneratePropertyBlock": true, "m_UseCustomSlotLabel": false, "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, "m_Precision": 0, "overrideHLSLDeclaration": false, "hlslDeclarationOverride": 0, "m_Hidden": false, + "m_PerRendererData": false, + "m_customAttributes": [], "m_Value": 14.0, "m_FloatType": 2, "m_RangeValues": { "x": 0.0, "y": 1.0 - } + }, + "m_SliderType": 0, + "m_SliderPower": 3.0, + "m_EnumType": 0, + "m_CSharpEnumString": "", + "m_EnumNames": [ + "Default" + ], + "m_EnumValues": [ + 0 + ] } { diff --git a/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl b/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl index e835e400e..ce37ea6e3 100644 --- a/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl +++ b/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl @@ -1,15 +1,4 @@ -float _SegmentWeight; -float _Height; -float _NumChars; -float _NumSegments; -float _SkewAngle; -float _HorizontalMiddle; - -float2 _SeparatorPos; -int _SeparatorType; // 0 = none, 1 = dot, 2 = 2-segment comma -int _SeparatorEveryThreeOnly; - -static float SegmentGap; +static float SegmentGap; static float EdgeBlur = 0.1; // used to remove aliasing static float SharpEdge = 0.7; @@ -37,6 +26,18 @@ static float2 dbl; static float2 dbr; static float2 dp; +struct SegContext { + float segmentWeight; + float segmentGap; + float numChars; + float numSegments; + float horizontalMiddle; + float skewAngle; + float2 separatorPos; + int separatorType; // 0 = none, 1 = dot, 2 = 2-segment comma + int separatorEveryThreeOnly; +}; + float4 SplitAndBlur(float v) { float be = clamp(EdgeBlur, 0, 9999); @@ -106,7 +107,7 @@ float DiagDist(float2 v) return abs(v.x); } -float LongLine(float2 a, float2 b, float2 p, bool topFlat, bool bottomFlat) +float LongLine(float2 a, float2 b, float2 p, bool topFlat, bool bottomFlat, SegContext ctx) { if ((topFlat && p.y < min(-a.y, -b.y) + SegmentGap) || (bottomFlat && p.y > max(-a.y, -b.y) - SegmentGap)) { return 0; @@ -114,65 +115,65 @@ float LongLine(float2 a, float2 b, float2 p, bool topFlat, bool bottomFlat) float2 pa = p - float2(a.x, -a.y); float2 ba = float2(b.x, -b.y) - float2(a.x, -a.y); float t = clamp(dot(pa, ba) / dot(ba, ba), SegmentGap, 1.0 - SegmentGap); - float2 v = abs(pa - ba * t) / _SegmentWeight * 0.5; + float2 v = abs(pa - ba * t) / ctx.segmentWeight * 0.5; return Rounder2(1 - v.x, 1 - v.y - v.x); } -float ShortLine(float2 a, float2 b, float2 p) +float ShortLine(float2 a, float2 b, float2 p, SegContext ctx) { float2 pa = p - float2(a.x, -a.y); float2 ba = float2(b.x, -b.y) - float2(a.x, -a.y); float t = clamp(dot(pa, ba) / dot(ba, ba), SegmentGap * 2.0, 1.0 - SegmentGap * 2.0); - float2 v = abs(pa - ba * t) / _SegmentWeight * 0.5; + float2 v = abs(pa - ba * t) / ctx.segmentWeight * 0.5; return Rounder2(1 - v.x, 1 - v.y - v.x); } -float MidLine(float2 a, float2 b, float2 p) +float MidLine(float2 a, float2 b, float2 p, SegContext ctx) { float2 pa = p - float2(a.x, -a.y); float2 ba = float2(b.x, -b.y) - float2(a.x, -a.y); float t = clamp(dot(pa, ba) / dot(ba, ba), SegmentGap * 1.1, 1.0 - SegmentGap * 1.1); - float2 v = abs(pa - ba * t) / _SegmentWeight * 0.5; + float2 v = abs(pa - ba * t) / ctx.segmentWeight * 0.5; return Rounder2(1 - v.x, 1 - v.y - v.x); } -float DiagLineForward(float2 a, float2 b, float2 p) +float DiagLineForward(float2 a, float2 b, float2 p, SegContext ctx) { float2 pa = p - float2(a.x, -a.y); float2 ba = float2(b.x, -b.y) - float2(a.x, -a.y); float t = pa.x / ba.x; float2 intersectP = abs(pa - ba * t); - float xl = clamp(1 - (p.x - a.x + SegmentGap + _SegmentWeight) / _SegmentWeight * 0.5, -9999, 1); - float xr = clamp(0 + (p.x - b.x - SegmentGap + _SegmentWeight) / _SegmentWeight * 0.5, -9999, 1); + float xl = clamp(1 - (p.x - a.x + SegmentGap + ctx.segmentWeight) / ctx.segmentWeight * 0.5, -9999, 1); + float xr = clamp(0 + (p.x - b.x - SegmentGap + ctx.segmentWeight) / ctx.segmentWeight * 0.5, -9999, 1); float t2 = pa.y / ba.y; float yu = clamp(t2 + 1.0 - SegmentGap * 2, -9999, 1); float yd = clamp(2 - t2 - SegmentGap * 2, -9999, 1); return Rounder( - 1 - intersectP.y / (_SegmentWeight * 4.0), + 1 - intersectP.y / (ctx.segmentWeight * 4.0), xl * xr, (yd * yu) / SegmentGap * 0.5 - 4.0 ); } -float DiagLineBackward(float2 a, float2 b, float2 p) +float DiagLineBackward(float2 a, float2 b, float2 p, SegContext ctx) { float2 pa = p - float2(a.x, -a.y); float2 ba = float2(b.x, -b.y) - float2(a.x, -a.y); float t = pa.x / ba.x; float2 intersectP = abs(pa - ba * t); - float xr = clamp(0 + (p.x - a.x - SegmentGap + _SegmentWeight) / _SegmentWeight * 0.5, -9999, 1); - float xl = clamp(1 - (p.x - b.x + SegmentGap + _SegmentWeight) / _SegmentWeight * 0.5, -9999, 1); + float xr = clamp(0 + (p.x - a.x - SegmentGap + ctx.segmentWeight) / ctx.segmentWeight * 0.5, -9999, 1); + float xl = clamp(1 - (p.x - b.x + SegmentGap + ctx.segmentWeight) / ctx.segmentWeight * 0.5, -9999, 1); float t2 = pa.y / ba.y; float yu = clamp(t2 + 1.0 - SegmentGap * 2, -9999, 1); float yd = clamp(2 - t2 - SegmentGap * 2, -9999, 1); return Rounder( - 1 - intersectP.y / (_SegmentWeight * 4.0), + 1 - intersectP.y / (ctx.segmentWeight * 4.0), xl * xr, (yd * yu) / SegmentGap * 0.5 - 4.0 ); @@ -182,10 +183,10 @@ float2 Translate(float2 coord, float2 translate) { return coord - translate; } -float Circle(float2 _st, float _radius, float smooth) +float Circle(float2 _st, float _radius, float smooth, SegContext ctx) { - _st.x += _st.y * -_SkewAngle; // un-angle - _st.x += _SkewAngle * 0.5; // un-angle + _st.x += _st.y * -ctx.skewAngle; // un-angle + _st.x += ctx.skewAngle * 0.5; // un-angle _st.y *= 0.9; // unstretch float2 dist = _st - float2(0.5, 0.5); return 1. - smoothstep( @@ -195,15 +196,15 @@ float Circle(float2 _st, float _radius, float smooth) ); } -float Comma(float2 uv) +float Comma(float2 uv, SegContext ctx) { if (uv.y < 0.61) { return 0.; } - float c = Circle(Translate(uv, float2(-0.15, 0.1)), 0.15, .7); // plus - c *= 1. - Circle(Translate(uv, float2(-0.01, 0.05)), 0.01, 2.5); // minus top - c *= 1. - Circle(Translate(uv, float2(-0.42, .13)), 0.48, .3); // minus left + float c = Circle(Translate(uv, float2(-0.15, 0.1)), 0.15, .7, ctx); // plus + c *= 1. - Circle(Translate(uv, float2(-0.01, 0.05)), 0.01, 2.5, ctx); // minus top + c *= 1. - Circle(Translate(uv, float2(-0.42, .13)), 0.48, .3, ctx); // minus left return c; } @@ -220,9 +221,9 @@ float3 Combine(float3 accu, float val, bool showSeg) ); } -bool ShowSeg(UnityTexture2D data, int charIndex, int segIndex) +bool ShowSeg(UnityTexture2D data, int charIndex, int segIndex, SegContext ctx) { - float2 d = float2(1. / 16, 1. / _NumChars); + float2 d = float2(1. / 16, 1. / ctx.numChars); float2 pos = float2(float(segIndex), float(charIndex)); float4 pixel = tex2Dlod(data, float4(d.x * (pos.x + .5), d.y * (pos.y + .5), 0., 0.)); if (pixel.b > .5) { @@ -231,111 +232,111 @@ bool ShowSeg(UnityTexture2D data, int charIndex, int segIndex) return false; } -float3 SegDispSeparator(UnityTexture2D data, int charIndex, int segIndex, float2 p, float3 r) +float3 SegDispSeparator(UnityTexture2D data, int charIndex, int segIndex, float2 p, float3 r, SegContext ctx) { - bool isThree = fmod(_NumChars - charIndex + 2, 3) == 0 && charIndex != _NumChars - 1; - bool separatorEveryThreeOnly = _SeparatorEveryThreeOnly == 1; + bool isThree = fmod(ctx.numChars - charIndex + 2, 3) == 0 && charIndex != ctx.numChars - 1; + bool separatorEveryThreeOnly = ctx.separatorEveryThreeOnly == 1; float2 pos = float2(-0.5, 0.43); if (!separatorEveryThreeOnly || isThree) { - switch (_SeparatorType) { + switch (ctx.separatorType) { case 0: return r; case 1: - r = Combine(r, Circle(p - pos - _SeparatorPos / 2., 0.025, 1.5), ShowSeg(data, charIndex, segIndex)); + r = Combine(r, Circle(p - pos - ctx.separatorPos / 2., 0.025, 1.5, ctx), ShowSeg(data, charIndex, segIndex, ctx)); break; case 2: - r = Combine(r, Circle(p - pos - _SeparatorPos / 2., 0.025, 1.5), ShowSeg(data, charIndex, segIndex)); - r = Combine(r, Comma(p - pos - _SeparatorPos / 2.), ShowSeg(data, charIndex, segIndex)); + r = Combine(r, Circle(p - pos - ctx.separatorPos / 2., 0.025, 1.5, ctx), ShowSeg(data, charIndex, segIndex, ctx)); + r = Combine(r, Comma(p - pos - ctx.separatorPos / 2., ctx), ShowSeg(data, charIndex, segIndex, ctx)); break; } } return r; } -float3 SegDisp7(UnityTexture2D data, int charIndex, float2 p, float3 r) +float3 SegDisp7(UnityTexture2D data, int charIndex, float2 p, float3 r, SegContext ctx) { - r = Combine(r, MidLine(tl, tr, p), ShowSeg(data, charIndex, 0)); - r = Combine(r, LongLine(tr, mr, p, false, false), ShowSeg(data, charIndex, 1)); - r = Combine(r, LongLine(mr, br, p, false, false), ShowSeg(data, charIndex, 2)); - r = Combine(r, MidLine(br, bl, p), ShowSeg(data, charIndex, 3)); - r = Combine(r, LongLine(bl, ml, p, false, false), ShowSeg(data, charIndex, 4)); - r = Combine(r, LongLine(ml, tl, p, false, false), ShowSeg(data, charIndex, 5)); - r = Combine(r, MidLine(mr, ml, p), ShowSeg(data, charIndex, 6)); - r = SegDispSeparator(data, charIndex, 7, p, r); + r = Combine(r, MidLine(tl, tr, p, ctx), ShowSeg(data, charIndex, 0, ctx)); + r = Combine(r, LongLine(tr, mr, p, false, false, ctx), ShowSeg(data, charIndex, 1, ctx)); + r = Combine(r, LongLine(mr, br, p, false, false, ctx), ShowSeg(data, charIndex, 2, ctx)); + r = Combine(r, MidLine(br, bl, p, ctx), ShowSeg(data, charIndex, 3, ctx)); + r = Combine(r, LongLine(bl, ml, p, false, false, ctx), ShowSeg(data, charIndex, 4, ctx)); + r = Combine(r, LongLine(ml, tl, p, false, false, ctx), ShowSeg(data, charIndex, 5, ctx)); + r = Combine(r, MidLine(mr, ml, p, ctx), ShowSeg(data, charIndex, 6, ctx)); + r = SegDispSeparator(data, charIndex, 7, p, r, ctx); return r; } -float3 SegDisp9(UnityTexture2D data, int charIndex, float2 p, float3 r) +float3 SegDisp9(UnityTexture2D data, int charIndex, float2 p, float3 r, SegContext ctx) { - r = Combine(r, MidLine(tl, tr, p), ShowSeg(data, charIndex, 0)); - r = Combine(r, LongLine(tr, mr, p, false, false), ShowSeg(data, charIndex, 1)); - r = Combine(r, LongLine(mr, br, p, false, false), ShowSeg(data, charIndex, 2)); - r = Combine(r, MidLine(br, bl, p), ShowSeg(data, charIndex, 3)); - r = Combine(r, LongLine(bl, ml, p, false, false), ShowSeg(data, charIndex, 4)); - r = Combine(r, LongLine(ml, tl, p, false, false), ShowSeg(data, charIndex, 5)); - r = Combine(r, MidLine(mr, ml, p), ShowSeg(data, charIndex, 6)); - r = SegDispSeparator(data, charIndex, 7, p, r); - r = Combine(r, LongLine(tm, mm, p, true, true), ShowSeg(data, charIndex, 8)); - r = Combine(r, LongLine(mm, bm, p, true, true), ShowSeg(data, charIndex, 9)); + r = Combine(r, MidLine(tl, tr, p, ctx), ShowSeg(data, charIndex, 0, ctx)); + r = Combine(r, LongLine(tr, mr, p, false, false, ctx), ShowSeg(data, charIndex, 1, ctx)); + r = Combine(r, LongLine(mr, br, p, false, false, ctx), ShowSeg(data, charIndex, 2, ctx)); + r = Combine(r, MidLine(br, bl, p, ctx), ShowSeg(data, charIndex, 3, ctx)); + r = Combine(r, LongLine(bl, ml, p, false, false, ctx), ShowSeg(data, charIndex, 4, ctx)); + r = Combine(r, LongLine(ml, tl, p, false, false, ctx), ShowSeg(data, charIndex, 5, ctx)); + r = Combine(r, MidLine(mr, ml, p, ctx), ShowSeg(data, charIndex, 6, ctx)); + r = SegDispSeparator(data, charIndex, 7, p, r, ctx); + r = Combine(r, LongLine(tm, mm, p, true, true, ctx), ShowSeg(data, charIndex, 8, ctx)); + r = Combine(r, LongLine(mm, bm, p, true, true, ctx), ShowSeg(data, charIndex, 9, ctx)); return r; } -float3 SegDisp14(UnityTexture2D data, int charIndex, float2 p, float3 r) +float3 SegDisp14(UnityTexture2D data, int charIndex, float2 p, float3 r, SegContext ctx) { - r = Combine(r, MidLine(tl, tr, p), ShowSeg(data, charIndex, 0)); - r = Combine(r, LongLine(tr, mr, p, false, false), ShowSeg(data, charIndex, 1)); - r = Combine(r, LongLine(mr, br, p, false, false), ShowSeg(data, charIndex, 2)); - r = Combine(r, MidLine(br, bl, p), ShowSeg(data, charIndex, 3)); - r = Combine(r, LongLine(bl, ml, p, false, false), ShowSeg(data, charIndex, 4)); - r = Combine(r, LongLine(ml, tl, p, false, false), ShowSeg(data, charIndex, 5)); - r = Combine(r, ShortLine(mm, ml, p), ShowSeg(data, charIndex, 6)); - r = SegDispSeparator(data, charIndex, 7, p, r); - r = Combine(r, DiagLineBackward(dtl, dtm, p), ShowSeg(data, charIndex, 8)); - r = Combine(r, LongLine(tm, mm, p, true, false), ShowSeg(data, charIndex, 9)); - r = Combine(r, DiagLineForward(dtr, dtm, p), ShowSeg(data, charIndex, 10)); - r = Combine(r, ShortLine(mm, mr, p), ShowSeg(data, charIndex, 11)); - r = Combine(r, DiagLineBackward(dbm, dbr, p), ShowSeg(data, charIndex, 12)); - r = Combine(r, LongLine(mm, bm, p, false, true), ShowSeg(data, charIndex, 13)); - r = Combine(r, DiagLineForward(dbm, dbl, p), ShowSeg(data, charIndex, 14)); + r = Combine(r, MidLine(tl, tr, p, ctx), ShowSeg(data, charIndex, 0, ctx)); + r = Combine(r, LongLine(tr, mr, p, false, false, ctx), ShowSeg(data, charIndex, 1, ctx)); + r = Combine(r, LongLine(mr, br, p, false, false, ctx), ShowSeg(data, charIndex, 2, ctx)); + r = Combine(r, MidLine(br, bl, p, ctx), ShowSeg(data, charIndex, 3, ctx)); + r = Combine(r, LongLine(bl, ml, p, false, false, ctx), ShowSeg(data, charIndex, 4, ctx)); + r = Combine(r, LongLine(ml, tl, p, false, false, ctx), ShowSeg(data, charIndex, 5, ctx)); + r = Combine(r, ShortLine(mm, ml, p, ctx), ShowSeg(data, charIndex, 6, ctx)); + r = SegDispSeparator(data, charIndex, 7, p, r, ctx); + r = Combine(r, DiagLineBackward(dtl, dtm, p, ctx), ShowSeg(data, charIndex, 8, ctx)); + r = Combine(r, LongLine(tm, mm, p, true, false, ctx), ShowSeg(data, charIndex, 9, ctx)); + r = Combine(r, DiagLineForward(dtr, dtm, p, ctx), ShowSeg(data, charIndex, 10, ctx)); + r = Combine(r, ShortLine(mm, mr, p, ctx), ShowSeg(data, charIndex, 11, ctx)); + r = Combine(r, DiagLineBackward(dbm, dbr, p, ctx), ShowSeg(data, charIndex, 12, ctx)); + r = Combine(r, LongLine(mm, bm, p, false, true, ctx), ShowSeg(data, charIndex, 13, ctx)); + r = Combine(r, DiagLineForward(dbm, dbl, p, ctx), ShowSeg(data, charIndex, 14, ctx)); return r; } -float3 SegDisp16(UnityTexture2D data, int charIndex, float2 p, float3 r) +float3 SegDisp16(UnityTexture2D data, int charIndex, float2 p, float3 r, SegContext ctx) { - r = Combine(r, ShortLine(tl, tm, p), ShowSeg(data, charIndex, 0)); // a - r = Combine(r, ShortLine(tm, tr, p), ShowSeg(data, charIndex, 1)); // b - r = Combine(r, LongLine(tr, mr, p, false, false), ShowSeg(data, charIndex, 2)); // c - r = Combine(r, LongLine(mr, br, p, false, false), ShowSeg(data, charIndex, 3)); // d - r = Combine(r, ShortLine(br, bm, p), ShowSeg(data, charIndex, 4)); // e - r = Combine(r, ShortLine(bm, bl, p), ShowSeg(data, charIndex, 5)); // f - r = Combine(r, LongLine(bl, ml, p, false, false), ShowSeg(data, charIndex, 6)); // g - r = Combine(r, LongLine(ml, tl, p, false, false), ShowSeg(data, charIndex, 7)); // h - r = Combine(r, DiagLineBackward(dtl, dtm, p), ShowSeg(data, charIndex, 8)); // i - r = Combine(r, LongLine(tm, mm, p, false, false), ShowSeg(data, charIndex, 9)); // j - r = Combine(r, DiagLineForward(dtr, dtm, p), ShowSeg(data, charIndex, 10)); // k - r = Combine(r, ShortLine(mm, mr, p), ShowSeg(data, charIndex, 11)); // l - r = Combine(r, DiagLineBackward(dbm, dbr, p), ShowSeg(data, charIndex, 12));// m - r = Combine(r, LongLine(mm, bm, p, false, false), ShowSeg(data, charIndex, 13)); // n - r = Combine(r, DiagLineForward(dbm, dbl, p), ShowSeg(data, charIndex, 14)); // o - r = Combine(r, ShortLine(mm, ml, p), ShowSeg(data, charIndex, 15)); // p + r = Combine(r, ShortLine(tl, tm, p, ctx), ShowSeg(data, charIndex, 0, ctx)); // a + r = Combine(r, ShortLine(tm, tr, p, ctx), ShowSeg(data, charIndex, 1, ctx)); // b + r = Combine(r, LongLine(tr, mr, p, false, false, ctx), ShowSeg(data, charIndex, 2, ctx)); // c + r = Combine(r, LongLine(mr, br, p, false, false, ctx), ShowSeg(data, charIndex, 3, ctx)); // d + r = Combine(r, ShortLine(br, bm, p, ctx), ShowSeg(data, charIndex, 4, ctx)); // e + r = Combine(r, ShortLine(bm, bl, p, ctx), ShowSeg(data, charIndex, 5, ctx)); // f + r = Combine(r, LongLine(bl, ml, p, false, false, ctx), ShowSeg(data, charIndex, 6, ctx)); // g + r = Combine(r, LongLine(ml, tl, p, false, false, ctx), ShowSeg(data, charIndex, 7, ctx)); // h + r = Combine(r, DiagLineBackward(dtl, dtm, p, ctx), ShowSeg(data, charIndex, 8, ctx)); // i + r = Combine(r, LongLine(tm, mm, p, false, false, ctx), ShowSeg(data, charIndex, 9, ctx)); // j + r = Combine(r, DiagLineForward(dtr, dtm, p, ctx), ShowSeg(data, charIndex, 10, ctx)); // k + r = Combine(r, ShortLine(mm, mr, p, ctx), ShowSeg(data, charIndex, 11, ctx)); // l + r = Combine(r, DiagLineBackward(dbm, dbr, p, ctx), ShowSeg(data, charIndex, 12, ctx));// m + r = Combine(r, LongLine(mm, bm, p, false, false, ctx), ShowSeg(data, charIndex, 13, ctx)); // n + r = Combine(r, DiagLineForward(dbm, dbl, p, ctx), ShowSeg(data, charIndex, 14, ctx)); // o + r = Combine(r, ShortLine(mm, ml, p, ctx), ShowSeg(data, charIndex, 15, ctx)); // p return r; } -float3 SegDisp(UnityTexture2D data, int charIndex, float2 p) +float3 SegDisp(UnityTexture2D data, int charIndex, float2 p, SegContext ctx) { float3 r = (0.); - p.x -= p.y * -_SkewAngle; - switch (_NumSegments) { - case 7: return SegDisp7(data, charIndex, p, r); - case 9: return SegDisp9(data, charIndex, p, r); - case 14: return SegDisp14(data, charIndex, p, r); - case 16: return SegDisp16(data, charIndex, p, r); + p.x -= p.y * -ctx.skewAngle; + switch (ctx.numSegments) { + case 7: return SegDisp7(data, charIndex, p, r, ctx); + case 9: return SegDisp9(data, charIndex, p, r, ctx); + case 14: return SegDisp14(data, charIndex, p, r, ctx); + case 16: return SegDisp16(data, charIndex, p, r, ctx); } return r; } @@ -344,31 +345,33 @@ void SegmentDisplay_float(float2 coords, UnityTexture2D data, float numChars, fl int separatorType, int separatorEveryThreeOnly, float2 separatorPos, float segmentWeight, float horizontalMiddle, float skewAngle, float2 padding, out float output) { - _SegmentWeight = segmentWeight; - _NumChars = numChars; - _NumSegments = numSegments; - _SkewAngle = skewAngle; - _HorizontalMiddle = horizontalMiddle; - _SeparatorType = separatorType; - _SeparatorEveryThreeOnly = separatorEveryThreeOnly; - _SeparatorPos = separatorPos; + SegContext ctx; + ctx.segmentWeight = segmentWeight; + ctx.segmentGap = segmentWeight * 1.5; + ctx.numChars = numChars; + ctx.numSegments = numSegments; + ctx.horizontalMiddle = horizontalMiddle; + ctx.skewAngle = skewAngle; + ctx.separatorPos = separatorPos; + ctx.separatorType = separatorType; // int → int, no cast needed + ctx.separatorEveryThreeOnly = separatorEveryThreeOnly; SegmentGap = segmentWeight * 1.5; - mm = float2(.0 + _HorizontalMiddle, 0); // middle - tm = float2(.0 + _HorizontalMiddle, 1); - bm = float2(.0 + _HorizontalMiddle, -1); + mm = float2(.0 + horizontalMiddle, 0); // middle + tm = float2(.0 + horizontalMiddle, 1); + bm = float2(.0 + horizontalMiddle, -1); dtl = tl + float2(0.0, -segmentWeight); dtr = tr + float2(0.0, -segmentWeight); - dtm = mm + float2(0.0 + _HorizontalMiddle, segmentWeight); - dbm = mm + float2(0.0 + _HorizontalMiddle, -segmentWeight); + dtm = mm + float2(0.0 + horizontalMiddle, segmentWeight); + dbm = mm + float2(0.0 + horizontalMiddle, -segmentWeight); dbl = bl + float2(0.0, segmentWeight); dbr = br + float2(0.0, segmentWeight); dp = br + float2(segmentWeight * 4.0, SegmentGap); - float cellWidth = 1. / _NumChars; + float cellWidth = 1. / numChars; float2 originPos = float2( -.5 + cellWidth / 2., @@ -386,7 +389,7 @@ void SegmentDisplay_float(float2 coords, UnityTexture2D data, float numChars, fl float2 f = float2(numChars * (1. + padding.x + segmentWeight * 2.), 1. + (padding.y + segmentWeight)); for (int character = 0; character < numChars; character++) { - d += SegDisp(data, character, (uv - pos) * f); + d += SegDisp(data, character, (uv - pos) * f, ctx); pos.x += cellWidth; if (character >= numChars - 1.) { From 83bd12dfce4d318a97d009874117b77826fe5d8c Mon Sep 17 00:00:00 2001 From: freezy Date: Thu, 21 Aug 2025 11:19:51 +0200 Subject: [PATCH 2/2] seg-shader: Use variable from context directly. --- .../Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl b/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl index ce37ea6e3..7eb019aee 100644 --- a/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl +++ b/VisualPinball.Unity/Assets/Shaders/Srp/Display/SegmentDisplayShader.hlsl @@ -356,7 +356,6 @@ void SegmentDisplay_float(float2 coords, UnityTexture2D data, float numChars, fl ctx.separatorType = separatorType; // int → int, no cast needed ctx.separatorEveryThreeOnly = separatorEveryThreeOnly; - SegmentGap = segmentWeight * 1.5; mm = float2(.0 + horizontalMiddle, 0); // middle tm = float2(.0 + horizontalMiddle, 1); bm = float2(.0 + horizontalMiddle, -1); @@ -367,9 +366,7 @@ void SegmentDisplay_float(float2 coords, UnityTexture2D data, float numChars, fl dbm = mm + float2(0.0 + horizontalMiddle, -segmentWeight); dbl = bl + float2(0.0, segmentWeight); dbr = br + float2(0.0, segmentWeight); - dp = br + float2(segmentWeight * 4.0, SegmentGap); - - + dp = br + float2(segmentWeight * 4.0, ctx.segmentGap); float cellWidth = 1. / numChars;