CultPhasor.cos/.sin become .cosine/.sine in C# and HLSL (GLSL regenerated next)
SPIRV-Cross renames members matching GLSL builtins, so the source names change. Resolver and JSON writer accessors follow the members; the wire (positional MessagePack, JSON keys) is untouched in this commit. The committed GLSL is stale until its regeneration commit, so CommittedGlslEqualsLowering fails here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
28e35dc448
commit
d605c70bba
6 changed files with 37 additions and 37 deletions
|
|
@ -14,8 +14,8 @@
|
||||||
// against CultMath.CultPhasor, same field order.
|
// against CultMath.CultPhasor, same field order.
|
||||||
struct CultPhasor
|
struct CultPhasor
|
||||||
{
|
{
|
||||||
float4 cos;
|
float4 cosine;
|
||||||
float4 sin;
|
float4 sine;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Johansen's Phacelle noise on 3D cells. See math.phacelle's comment (math.Phacelle.cs) for the stripe wave
|
// Johansen's Phacelle noise on 3D cells. See math.phacelle's comment (math.Phacelle.cs) for the stripe wave
|
||||||
|
|
@ -84,13 +84,13 @@ CultPhasor cultmath_phacelle(float3 p, float3 side, float offset, float normaliz
|
||||||
float outCos = rawCos / rawLength;
|
float outCos = rawCos / rawLength;
|
||||||
float outSin = rawSin / rawLength;
|
float outSin = rawSin / rawLength;
|
||||||
float3 gradLength = (rawCos * gradRawCos + rawSin * gradRawSin) / rawLength;
|
float3 gradLength = (rawCos * gradRawCos + rawSin * gradRawSin) / rawLength;
|
||||||
result.cos = float4((gradRawCos - outCos * gradLength) / rawLength, outCos);
|
result.cosine = float4((gradRawCos - outCos * gradLength) / rawLength, outCos);
|
||||||
result.sin = float4((gradRawSin - outSin * gradLength) / rawLength, outSin);
|
result.sine = float4((gradRawSin - outSin * gradLength) / rawLength, outSin);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.cos = float4(gradRawCos / floorLength, rawCos / floorLength);
|
result.cosine = float4(gradRawCos / floorLength, rawCos / floorLength);
|
||||||
result.sin = float4(gradRawSin / floorLength, rawSin / floorLength);
|
result.sine = float4(gradRawSin / floorLength, rawSin / floorLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ namespace CultMath;
|
||||||
public struct CultPhasor
|
public struct CultPhasor
|
||||||
{
|
{
|
||||||
/// <summary>(∇cos, cos): the normalized cosine wave and its gradient.</summary>
|
/// <summary>(∇cos, cos): the normalized cosine wave and its gradient.</summary>
|
||||||
public float4 cos;
|
public float4 cosine;
|
||||||
|
|
||||||
/// <summary>(∇sin, sin): the normalized sine wave and its gradient.</summary>
|
/// <summary>(∇sin, sin): the normalized sine wave and its gradient.</summary>
|
||||||
public float4 sin;
|
public float4 sine;
|
||||||
|
|
||||||
public CultPhasor(float4 cos, float4 sin)
|
public CultPhasor(float4 cosine, float4 sine)
|
||||||
{
|
{
|
||||||
this.cos = cos;
|
this.cosine = cosine;
|
||||||
this.sin = sin;
|
this.sine = sine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,12 +93,12 @@ public sealed class PhacelleTests
|
||||||
var actual = math.phacelle(p, side, offset, normalization);
|
var actual = math.phacelle(p, side, offset, normalization);
|
||||||
var expected = Evaluate(p, side, offset, normalization);
|
var expected = Evaluate(p, side, offset, normalization);
|
||||||
|
|
||||||
maxError = Math.Max(maxError, Math.Max(Math.Abs(actual.cos.w - expected.Cos), Math.Abs(actual.sin.w - expected.Sin)));
|
maxError = Math.Max(maxError, Math.Max(Math.Abs(actual.cosine.w - expected.Cos), Math.Abs(actual.sine.w - expected.Sin)));
|
||||||
if (expected.RawLength >= 1.0 - normalization + ThresholdBand)
|
if (expected.RawLength >= 1.0 - normalization + ThresholdBand)
|
||||||
{
|
{
|
||||||
// The output magnitude is 1 wherever the raw magnitude reaches 1 - normalization.
|
// The output magnitude is 1 wherever the raw magnitude reaches 1 - normalization.
|
||||||
above++;
|
above++;
|
||||||
var magnitude = Math.Sqrt((double)actual.cos.w * actual.cos.w + (double)actual.sin.w * actual.sin.w);
|
var magnitude = Math.Sqrt((double)actual.cosine.w * actual.cosine.w + (double)actual.sine.w * actual.sine.w);
|
||||||
Assert.True(Math.Abs(magnitude - 1.0) < ValueTolerance, $"magnitude {magnitude} above the threshold at {p}");
|
Assert.True(Math.Abs(magnitude - 1.0) < ValueTolerance, $"magnitude {magnitude} above the threshold at {p}");
|
||||||
}
|
}
|
||||||
else if (expected.RawLength <= 1.0 - normalization - ThresholdBand)
|
else if (expected.RawLength <= 1.0 - normalization - ThresholdBand)
|
||||||
|
|
@ -130,10 +130,10 @@ public sealed class PhacelleTests
|
||||||
var quarter = math.phacelle(p, side, offset + 0.25f, 0.5f);
|
var quarter = math.phacelle(p, side, offset + 0.25f, 0.5f);
|
||||||
var whole = math.phacelle(p, side, offset + 1.0f, 0.5f);
|
var whole = math.phacelle(p, side, offset + 1.0f, 0.5f);
|
||||||
|
|
||||||
Assert.True(MathF.Abs(quarter.cos.w + basePhasor.sin.w) < 2.0e-5f);
|
Assert.True(MathF.Abs(quarter.cosine.w + basePhasor.sine.w) < 2.0e-5f);
|
||||||
Assert.True(MathF.Abs(quarter.sin.w - basePhasor.cos.w) < 2.0e-5f);
|
Assert.True(MathF.Abs(quarter.sine.w - basePhasor.cosine.w) < 2.0e-5f);
|
||||||
Assert.True(MathF.Abs(whole.cos.w - basePhasor.cos.w) < 2.0e-5f);
|
Assert.True(MathF.Abs(whole.cosine.w - basePhasor.cosine.w) < 2.0e-5f);
|
||||||
Assert.True(MathF.Abs(whole.sin.w - basePhasor.sin.w) < 2.0e-5f);
|
Assert.True(MathF.Abs(whole.sine.w - basePhasor.sine.w) < 2.0e-5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,9 +166,9 @@ public sealed class PhacelleTests
|
||||||
if (distance > 0.0) above++; else below++;
|
if (distance > 0.0) above++; else below++;
|
||||||
|
|
||||||
var analytic = math.phacelle(p, side, offset, normalization);
|
var analytic = math.phacelle(p, side, offset, normalization);
|
||||||
var numericCos = CentralDifference(q => math.phacelle(q, side, offset, normalization).cos.w, p, GradientEps);
|
var numericCos = CentralDifference(q => math.phacelle(q, side, offset, normalization).cosine.w, p, GradientEps);
|
||||||
var numericSin = CentralDifference(q => math.phacelle(q, side, offset, normalization).sin.w, p, GradientEps);
|
var numericSin = CentralDifference(q => math.phacelle(q, side, offset, normalization).sine.w, p, GradientEps);
|
||||||
maxError = MathF.Max(maxError, MathF.Max(MaxComponentError(numericCos, analytic.cos), MaxComponentError(numericSin, analytic.sin)));
|
maxError = MathF.Max(maxError, MathF.Max(MaxComponentError(numericCos, analytic.cosine), MaxComponentError(numericSin, analytic.sine)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.True(above >= 150 && below >= 150, $"{above} points above and {below} below the threshold");
|
Assert.True(above >= 150 && below >= 150, $"{above} points above and {below} below the threshold");
|
||||||
|
|
@ -199,7 +199,7 @@ public sealed class PhacelleTests
|
||||||
var flow = math.normalize(tangent);
|
var flow = math.normalize(tangent);
|
||||||
var sideDirection = math.cross(hat, flow);
|
var sideDirection = math.cross(hat, flow);
|
||||||
var phasor = math.phacelle(hat * radiusInCells, sideDirection * math.TAU, 0.25f, 0.5f);
|
var phasor = math.phacelle(hat * radiusInCells, sideDirection * math.TAU, 0.25f, 0.5f);
|
||||||
var gradient = new float3(phasor.cos.x, phasor.cos.y, phasor.cos.z);
|
var gradient = new float3(phasor.cosine.x, phasor.cosine.y, phasor.cosine.z);
|
||||||
alongFlow += Math.Abs(math.dot(gradient, flow));
|
alongFlow += Math.Abs(math.dot(gradient, flow));
|
||||||
acrossFlow += Math.Abs(math.dot(gradient, sideDirection));
|
acrossFlow += Math.Abs(math.dot(gradient, sideDirection));
|
||||||
used++;
|
used++;
|
||||||
|
|
@ -232,7 +232,7 @@ public sealed class PhacelleTests
|
||||||
{
|
{
|
||||||
var low = math.phacelle(SetAxis(p, axis, GetAxis(p, axis) - steps[k] * 0.5f), side, offset, 0.5f);
|
var low = math.phacelle(SetAxis(p, axis, GetAxis(p, axis) - steps[k] * 0.5f), side, offset, 0.5f);
|
||||||
var high = math.phacelle(SetAxis(p, axis, GetAxis(p, axis) + steps[k] * 0.5f), side, offset, 0.5f);
|
var high = math.phacelle(SetAxis(p, axis, GetAxis(p, axis) + steps[k] * 0.5f), side, offset, 0.5f);
|
||||||
maxDifference[k] = MathF.Max(maxDifference[k], MathF.Max(MathF.Abs(low.cos.w - high.cos.w), MathF.Abs(low.sin.w - high.sin.w)));
|
maxDifference[k] = MathF.Max(maxDifference[k], MathF.Max(MathF.Abs(low.cosine.w - high.cosine.w), MathF.Abs(low.sine.w - high.sine.w)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -260,8 +260,8 @@ public sealed class PhacelleTests
|
||||||
var pruned = math.phacelle(p, side, offset, normalization);
|
var pruned = math.phacelle(p, side, offset, normalization);
|
||||||
var unpruned = math.phacelle(p, side, offset, normalization, false);
|
var unpruned = math.phacelle(p, side, offset, normalization, false);
|
||||||
|
|
||||||
AssertBitEqual(unpruned.cos, pruned.cos);
|
AssertBitEqual(unpruned.cosine, pruned.cosine);
|
||||||
AssertBitEqual(unpruned.sin, pruned.sin);
|
AssertBitEqual(unpruned.sine, pruned.sine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,8 +325,8 @@ public sealed class PhacelleTests
|
||||||
var pruned = math.phacelle(p, PruneCutSide, PruneCutOffset, PruneCutNormalization);
|
var pruned = math.phacelle(p, PruneCutSide, PruneCutOffset, PruneCutNormalization);
|
||||||
var unpruned = math.phacelle(p, PruneCutSide, PruneCutOffset, PruneCutNormalization, false);
|
var unpruned = math.phacelle(p, PruneCutSide, PruneCutOffset, PruneCutNormalization, false);
|
||||||
|
|
||||||
AssertBitEqual(unpruned.cos, pruned.cos);
|
AssertBitEqual(unpruned.cosine, pruned.cosine);
|
||||||
AssertBitEqual(unpruned.sin, pruned.sin);
|
AssertBitEqual(unpruned.sine, pruned.sine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
// against CultMath.CultPhasor, same field order.
|
// against CultMath.CultPhasor, same field order.
|
||||||
struct CultPhasor
|
struct CultPhasor
|
||||||
{
|
{
|
||||||
float4 cos;
|
float4 cosine;
|
||||||
float4 sin;
|
float4 sine;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Johansen's Phacelle noise on 3D cells. See math.phacelle's comment (math.Phacelle.cs) for the stripe wave
|
// Johansen's Phacelle noise on 3D cells. See math.phacelle's comment (math.Phacelle.cs) for the stripe wave
|
||||||
|
|
@ -84,13 +84,13 @@ CultPhasor cultmath_phacelle(float3 p, float3 side, float offset, float normaliz
|
||||||
float outCos = rawCos / rawLength;
|
float outCos = rawCos / rawLength;
|
||||||
float outSin = rawSin / rawLength;
|
float outSin = rawSin / rawLength;
|
||||||
float3 gradLength = (rawCos * gradRawCos + rawSin * gradRawSin) / rawLength;
|
float3 gradLength = (rawCos * gradRawCos + rawSin * gradRawSin) / rawLength;
|
||||||
result.cos = float4((gradRawCos - outCos * gradLength) / rawLength, outCos);
|
result.cosine = float4((gradRawCos - outCos * gradLength) / rawLength, outCos);
|
||||||
result.sin = float4((gradRawSin - outSin * gradLength) / rawLength, outSin);
|
result.sine = float4((gradRawSin - outSin * gradLength) / rawLength, outSin);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.cos = float4(gradRawCos / floorLength, rawCos / floorLength);
|
result.cosine = float4(gradRawCos / floorLength, rawCos / floorLength);
|
||||||
result.sin = float4(gradRawSin / floorLength, rawSin / floorLength);
|
result.sine = float4(gradRawSin / floorLength, rawSin / floorLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -511,8 +511,8 @@ public static class CultMathJson
|
||||||
a => new CultPhasor(new float4(a[0], a[1], a[2], a[3]), new float4(a[4], a[5], a[6], a[7])),
|
a => new CultPhasor(new float4(a[0], a[1], a[2], a[3]), new float4(a[4], a[5], a[6], a[7])),
|
||||||
(v, a) =>
|
(v, a) =>
|
||||||
{
|
{
|
||||||
a[0] = v.cos.x; a[1] = v.cos.y; a[2] = v.cos.z; a[3] = v.cos.w;
|
a[0] = v.cosine.x; a[1] = v.cosine.y; a[2] = v.cosine.z; a[3] = v.cosine.w;
|
||||||
a[4] = v.sin.x; a[5] = v.sin.y; a[6] = v.sin.z; a[7] = v.sin.w;
|
a[4] = v.sine.x; a[5] = v.sine.y; a[6] = v.sine.z; a[7] = v.sine.w;
|
||||||
}),
|
}),
|
||||||
Add<SpanNoise, float>(f, new Fields<float>(("field", Xyzw<float>()), ("curvature", Val<float>()), ("fold", Val<float>())),
|
Add<SpanNoise, float>(f, new Fields<float>(("field", Xyzw<float>()), ("curvature", Val<float>()), ("fold", Val<float>())),
|
||||||
a => new SpanNoise(new float4(a[0], a[1], a[2], a[3]), a[4], a[5]),
|
a => new SpanNoise(new float4(a[0], a[1], a[2], a[3]), a[4], a[5]),
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ public sealed class CultMathResolver : IFormatterResolver
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}),
|
}),
|
||||||
Shape<CultPhasor>((ref MessagePackWriter w, CultPhasor v) => { w.WriteArrayHeader(2); PutFloat4(ref w, v.cos); PutFloat4(ref w, v.sin); },
|
Shape<CultPhasor>((ref MessagePackWriter w, CultPhasor v) => { w.WriteArrayHeader(2); PutFloat4(ref w, v.cosine); PutFloat4(ref w, v.sine); },
|
||||||
(ref MessagePackReader r) =>
|
(ref MessagePackReader r) =>
|
||||||
{
|
{
|
||||||
var value = default(CultPhasor);
|
var value = default(CultPhasor);
|
||||||
|
|
@ -229,8 +229,8 @@ public sealed class CultMathResolver : IFormatterResolver
|
||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0: value.cos = GetFloat4(ref r); break;
|
case 0: value.cosine = GetFloat4(ref r); break;
|
||||||
case 1: value.sin = GetFloat4(ref r); break;
|
case 1: value.sine = GetFloat4(ref r); break;
|
||||||
default: r.Skip(); break;
|
default: r.Skip(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue