From 48a0e3facb7ff5145d927bc85680b5e1efc5734e Mon Sep 17 00:00:00 2001 From: rsformoso Date: Sat, 28 Mar 2026 21:27:46 +0800 Subject: [PATCH] Switch to non-branching approach for GetMajorAxes --- Assets/vfx-graph-gs/VFX.meta | 8 +++ Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl | 54 +++++++++++++++++ .../GetMajorAxes.hlsl.meta | 0 .../VFXGraphHLSL/GetMajorAxes.hlsl | 58 ------------------- 4 files changed, 62 insertions(+), 58 deletions(-) create mode 100644 Assets/vfx-graph-gs/VFX.meta create mode 100644 Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl rename Assets/vfx-graph-gs/{VFXGraphHLSL => VFX}/GetMajorAxes.hlsl.meta (100%) delete mode 100644 Assets/vfx-graph-gs/VFXGraphHLSL/GetMajorAxes.hlsl diff --git a/Assets/vfx-graph-gs/VFX.meta b/Assets/vfx-graph-gs/VFX.meta new file mode 100644 index 0000000..720cc90 --- /dev/null +++ b/Assets/vfx-graph-gs/VFX.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bb92af38d2a022242b4dddcb954f789e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl b/Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl new file mode 100644 index 0000000..ba01206 --- /dev/null +++ b/Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl @@ -0,0 +1,54 @@ +#define EPSILON 0.0004f + +float CrossProduct(float2 A, float2 B) +{ + return A.x * B.y - A.y * B.x; +} + +float SweepArea(float2 A, float2 B) +{ + return abs(CrossProduct(A, B)); +} + +float4x4 GetMajorAxes(float4x4 Axes, float4x4 AxesProjections) +{ + float4x4 result = (float4x4)0; + + float2 x_proj = AxesProjections[0].xy; + float2 y_proj = AxesProjections[1].xy; + float2 z_proj = AxesProjections[2].xy; + + float3 x_axes = Axes[0].xyz; + float3 y_axes = Axes[1].xyz; + float3 z_axes = Axes[2].xyz; + + float xy_area = SweepArea(x_proj, y_proj); + float xz_area = SweepArea(x_proj, z_proj); + float yz_area = SweepArea(y_proj, z_proj); + + // Compute selection weights using step + float xy_is_max = step(xz_area, xy_area) * step(yz_area, xy_area); + float xz_is_max = step(yz_area, xz_area) * (1.0 - xy_is_max); + float yz_is_max = 1.0 - xy_is_max - xz_is_max; + + // Select axis0 + float3 axis0 = + xy_is_max * x_axes + + xz_is_max * x_axes + + yz_is_max * y_axes; + + // Select axis1 + float3 axis1 = + xy_is_max * y_axes + + xz_is_max * z_axes + + yz_is_max * z_axes; + + // Normalize and scale if length is below threshold + float len0 = length(axis0); + float len1 = length(axis1); + + result[0].xyz = normalize(axis0) * max(len0, EPSILON); + result[1].xyz = normalize(axis1) * max(len1, EPSILON); + + return result; +} \ No newline at end of file diff --git a/Assets/vfx-graph-gs/VFXGraphHLSL/GetMajorAxes.hlsl.meta b/Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl.meta similarity index 100% rename from Assets/vfx-graph-gs/VFXGraphHLSL/GetMajorAxes.hlsl.meta rename to Assets/vfx-graph-gs/VFX/GetMajorAxes.hlsl.meta diff --git a/Assets/vfx-graph-gs/VFXGraphHLSL/GetMajorAxes.hlsl b/Assets/vfx-graph-gs/VFXGraphHLSL/GetMajorAxes.hlsl deleted file mode 100644 index 29de923..0000000 --- a/Assets/vfx-graph-gs/VFXGraphHLSL/GetMajorAxes.hlsl +++ /dev/null @@ -1,58 +0,0 @@ -#define EPSILON 0.0004f - -/// Hidden -float CrossProduct(float2 A, float2 B) -{ - return A.x * B.y - A.y * B.x; -} - -/// Hidden -float SweepArea(float2 A, float2 B) -{ - return abs(CrossProduct(A, B)); -} - -float4x4 GetMajorAxes(float4x4 Axes, float4x4 AxesProjections) -{ - float4x4 result = (float4x4)0; - - float2 x_proj = AxesProjections[0].xy; - float2 y_proj = AxesProjections[1].xy; - float2 z_proj = AxesProjections[2].xy; - - float3 x_axes = Axes[0].xyz; - float3 y_axes = Axes[1].xyz; - float3 z_axes = Axes[2].xyz; - - float xy_area = SweepArea(x_proj, y_proj); - float xz_area = SweepArea(x_proj, z_proj); - float yz_area = SweepArea(y_proj, z_proj); - - if (xy_area > xz_area && xy_area > yz_area) - { - result[0].xyz = x_axes; - result[1].xyz = y_axes; - } - else if (xz_area > yz_area) - { - result[0].xyz = x_axes; - result[1].xyz = z_axes; - } - else - { - result[0].xyz = y_axes; - result[1].xyz = z_axes; - } - - if (length(result[0].xyz) < 0.0004) - { - result[0].xyz = normalize(result[0].xyz) * EPSILON; - } - - if (length(result[1].xyz) < 0.0004) - { - result[1].xyz = normalize(result[1].xyz) * EPSILON; - } - - return result; -}