这是indexloc提供的服务,不要输入任何密码
Skip to content

Feature main/apply ping pong fix #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions Operators/Lib/Resources/img/generate/BoxGradient.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ struct vsOutput
float2 texCoord : TEXCOORD;
};

float PingPongRepeat(float x, float pingPong, float repeat)
{
float baseValue = x;
float repeatValue = frac(baseValue);
float pingPongValue = 1.0 - abs(frac(x * 0.5) * 2.0 - 1.0);
float singlePingPong = abs(x);

// Select pingpong type: single or repeating
float pingPongOutput = lerp(singlePingPong, pingPongValue, step(0.5, repeat));

// Select between base, repeat, or pingpong
float value = lerp(baseValue, repeatValue, step(0.5, repeat)); // If repeat, use repeatValue
value = lerp(value, pingPongOutput, step(0.5, pingPong)); // If pingpong, override with pingpong

// Clamp final result if not repeating
value = lerp(saturate(value), value, step(0.5, repeat)); // If NOT repeating, clamp to [0..1]

return value;
}

Texture2D<float4> ImageA : register(t0);
Texture2D<float4> Gradient : register(t1);
sampler texSampler : register(s0);
Expand All @@ -52,11 +72,12 @@ float sdRoundedBox(in float2 p, in float2 b, in float4 r)
// Function to rotate a point around the origin
inline float2 rotatePoint(float2 p, float angle)
{
angle = radians(angle); // Convert angle to radians
float cosAngle = cos(angle);
float sinAngle = sin(angle);
return float2(
p.x * cosAngle - p.y * sinAngle,
p.x * sinAngle + p.y * cosAngle);
p.x * cosAngle + p.y * sinAngle,
p.x * sinAngle - p.y * cosAngle);
}

float4 psMain(vsOutput psInput) : SV_TARGET
Expand All @@ -68,25 +89,17 @@ float4 psMain(vsOutput psInput) : SV_TARGET
p -= 0.5;
p.x *= aspectRation;
p += Center * float2(-1, 1);
// Convert the rotation angle from degrees to radians
float rotationRadians = radians(Rotation);

// Apply the rotation to the point
p = rotatePoint(p, rotationRadians);
p = rotatePoint(p, Rotation);

float c = 0;

c = sdRoundedBox(p, Size * UniformScale, CornersRadius * UniformScale) * 2 - Offset * Width;

float4 orgColor = ImageA.Sample(texSampler, psInput.texCoord);

c = PingPong > 0.5
? (Repeat < 0.5 ? (abs(c) / Width)
: 1.000001 - abs(fmod(c, Width * 1.99999) - Width) / Width)
: c / Width;

c = Repeat > 0.5
? fmod(c, 1)
: saturate(c);
c = PingPongRepeat(c / Width, PingPong, Repeat);

float dBiased = ApplyGainAndBias(c, GainAndBias);

Expand Down
40 changes: 25 additions & 15 deletions Operators/Lib/Resources/img/generate/NGonGradient.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,32 @@ float sdRegularPolygon(in float2 p, in float r, in float n)
// Function to rotate a point around the origin
inline float2 rotatePoint(float2 p, float angle)
{
angle = radians(angle); // Convert angle to radians
float cosAngle = cos(angle);
float sinAngle = sin(angle);
return float2(
p.x * cosAngle - p.y * sinAngle,
p.x * sinAngle + p.y * cosAngle);
p.x * cosAngle + p.y * sinAngle,
p.x * sinAngle - p.y * cosAngle);
}

float PingPongRepeat(float x, float pingPong, float repeat)
{
float baseValue = x;
float repeatValue = frac(baseValue);
float pingPongValue = 1.0 - abs(frac(x * 0.5) * 2.0 - 1.0);
float singlePingPong = abs(x);

// Select pingpong type: single or repeating
float pingPongOutput = lerp(singlePingPong, pingPongValue, step(0.5, repeat));

// Select between base, repeat, or pingpong
float value = lerp(baseValue, repeatValue, step(0.5, repeat)); // If repeat, use repeatValue
value = lerp(value, pingPongOutput, step(0.5, pingPong)); // If pingpong, override with pingpong

// Clamp final result if not repeating
value = lerp(saturate(value), value, step(0.5, repeat)); // If NOT repeating, clamp to [0..1]

return value;
}

float4 psMain(vsOutput psInput) : SV_TARGET
Expand All @@ -123,25 +144,14 @@ float4 psMain(vsOutput psInput) : SV_TARGET
p.x *= aspectRatio;

// Rotate
// Convert the rotation angle from degrees to radians
float rotationRadians = radians(Rotate);
// Apply the rotation to the point
p = rotatePoint(p, rotationRadians);
p = rotatePoint(p, Rotate);

p += Position.yx;
//float c = sdNgon(p, Radius, Sides) * 2 - Offset * Width;
float c = sdRegularPolygon(p, Radius, Sides) * 2 - Offset * Width ;

float4 orgColor = ImageA.Sample(texSampler, psInput.texCoord);

c = PingPong > 0.5
? (Repeat < 0.5 ? (abs(c) / Width)
: 1.000001 - abs(fmod(c, Width * 1.99999) - Width) / Width)
: c / Width;

c = Repeat > 0.5
? fmod(c, 1)
: saturate(c);
c = PingPongRepeat(c / Width, PingPong, Repeat);

float dBiased = ApplyGainAndBias(c, GainAndBias);
dBiased = clamp(dBiased, 0.001, 0.999);
Expand Down