Implement native 0x202 color interpolation
This commit is contained in:
@@ -73,7 +73,9 @@ public class GfxCommandBufferTests
|
||||
}, System.Array.Empty<string>());
|
||||
var vm = new VirtualMachine(scene, t, new RecordingHost());
|
||||
vm.Run();
|
||||
Assert.Equal(0x80_112233L, vm.Gfx.TryGet(0x1000)!.Color);
|
||||
var o = vm.Gfx.TryGet(0x1000)!;
|
||||
Assert.Equal(0x80_112233L, o.OneShotColorTarget);
|
||||
Assert.True(o.OneShotColorEnabled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
75
engine/Age.Engine.Tests/OneShotColorTests.cs
Normal file
75
engine/Age.Engine.Tests/OneShotColorTests.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Age.Engine.Model;
|
||||
|
||||
namespace Age.Engine.Tests;
|
||||
|
||||
public class OneShotColorTests
|
||||
{
|
||||
private static GfxState Visible(long current)
|
||||
{
|
||||
var gfx = new GfxState();
|
||||
gfx.SetSurface(1, 0x23, -1);
|
||||
gfx.BindDraw(0x100, 1, 0, 0, 100, 100, 0, 0);
|
||||
gfx.SetObjectColor(0x100, current);
|
||||
return gfx;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DelayedColor_UsesCurrentTargetAndCommitsWithNativeIntegerLerp()
|
||||
{
|
||||
var gfx = Visible(GfxState.PackColor(0x00, 0x102030));
|
||||
gfx.SetAnimatedObjectColorResolved(0x100, 100, 400, 0xff, 0x90a0b0);
|
||||
|
||||
var start = gfx.SnapshotVisibleObjects(1000).Single();
|
||||
Assert.Equal(0, start.TintStrength);
|
||||
Assert.Equal(0.0, start.ColorTransition!.Value.Progress);
|
||||
Assert.Equal(0, gfx.SnapshotVisibleObjects(1100).Single().TintStrength);
|
||||
|
||||
var half = gfx.SnapshotVisibleObjects(1300).Single();
|
||||
Assert.Equal(0x7f, half.TintStrength);
|
||||
Assert.Equal(0x506070, half.Tint);
|
||||
Assert.Equal(0.5, half.ColorTransition!.Value.Progress, 3);
|
||||
|
||||
var end = gfx.SnapshotVisibleObjects(1500).Single();
|
||||
Assert.Equal(0xff, end.TintStrength);
|
||||
Assert.Equal(0x90a0b0, end.Tint);
|
||||
Assert.False(gfx.TryGet(0x100)!.OneShotColorEnabled);
|
||||
Assert.Equal(-1, gfx.TryGet(0x100)!.OneShotColorTarget);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaticWriteAfterOp202_BecomesInterpolationCurrent_NotAnEndpointOverwrite()
|
||||
{
|
||||
var gfx = Visible(GfxState.PackColor(0xff, 0x000000));
|
||||
gfx.SetAnimatedObjectColorResolved(0x100, 0, 300, 0x00, 0xffffff);
|
||||
gfx.SetStaticObjectColorResolved(0x100, 0, 0xff, 0xffffff);
|
||||
|
||||
var start = gfx.SnapshotVisibleObjects(2000).Single();
|
||||
Assert.Equal(0xff, start.TintStrength);
|
||||
Assert.Equal(0xffffff, start.Tint);
|
||||
var half = gfx.SnapshotVisibleObjects(2150).Single();
|
||||
Assert.Equal(0x7f, half.TintStrength);
|
||||
Assert.Equal(0xffffff, half.Tint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorAndScale_ShareOneShotStartClock()
|
||||
{
|
||||
var gfx = Visible(GfxState.PackColor(0x00, 0xffffff));
|
||||
gfx.SetAnimatedObjectColorResolved(0x100, 0, 1000, 0xff, 0xffffff);
|
||||
gfx.SetScaleChannel(0x100, 0, 1000, (200, 200, 100));
|
||||
|
||||
gfx.SnapshotVisibleObjects(5000);
|
||||
var half = gfx.SnapshotVisibleObjects(5500).Single();
|
||||
Assert.Equal(0x7f, half.TintStrength);
|
||||
Assert.Equal(1.5, half.Transform.ScaleX, 3);
|
||||
Assert.Equal(5000, half.ColorTransition!.Value.StartMs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NegativeTargetComponents_PreserveCurrentStaticBytes()
|
||||
{
|
||||
var gfx = Visible(GfxState.PackColor(0x33, 0x123456));
|
||||
gfx.SetAnimatedObjectColorResolved(0x100, 0, 100, -1, -1);
|
||||
Assert.Equal(GfxState.PackColor(0x33, 0x123456), gfx.TryGet(0x100)!.OneShotColorTarget);
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,19 @@ public class RenderObjectBlendTests
|
||||
Assert.Equal(BlendKind.Alpha, ro2.Blend);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Mode1_UsesArgbAlphaAsOpacityAndRgbAsMultiplicativeModulation()
|
||||
{
|
||||
var g = WithVisibleObject(0x100, resId: 5, colorKey: -1);
|
||||
g.SetStaticObjectColorResolved(0x100, 1, 0x40, 0x80ff40);
|
||||
var ro = g.SnapshotVisibleObjects().Single();
|
||||
Assert.Equal(0x40, ro.Alpha);
|
||||
Assert.Equal(0, ro.TintStrength);
|
||||
Assert.Equal(0x80ff40, ro.Tint);
|
||||
Assert.True(ro.MultiplyTint);
|
||||
Assert.Equal(BlendKind.Alpha, ro.Blend);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorKey_IsCarriedThrough()
|
||||
{
|
||||
|
||||
@@ -27,4 +27,17 @@ public class SoftwareAffineRasterizerTests
|
||||
Assert.InRange(colored, 3, 5);
|
||||
Assert.Equal(0, dst[(1*5+1)*4+3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BlitRgba_MultiplyTintUsesD3dStyleRgbModulationAndOpacity()
|
||||
{
|
||||
byte[] src = { 200, 100, 50, 255 };
|
||||
byte[] dst = new byte[4];
|
||||
SoftwareAffineRasterizer.BlitRgba(dst, 1, 1, src, 1, 1, 0, 0, 1, 1,
|
||||
new Affine2D(1, 0, 0, 1, 0, 0), 0x80ff40, 0, 0.5f, multiplyTint: true);
|
||||
Assert.InRange(dst[0], 49, 50);
|
||||
Assert.InRange(dst[1], 49, 50);
|
||||
Assert.InRange(dst[2], 5, 7);
|
||||
Assert.InRange(dst[3], 126, 127);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user