aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit eb7e1265ed6ea1c052c138cc10e84614ebc80c0c
parent 200e72f39ffbc0cb5b803f44bc1ea607f7b58df7
Author: anon <anon@example.com>
Date:   Thu, 15 Oct 2026 15:22:26 +0000

Generate camera-space native texture coordinates

Diffstat:
Mdecompiled/runtime/linux_graphics.c | 17++++++++++-------
Mdecompiled/tests/devices.c | 16++++++++++++----
Mtools/reconstruction/test_portable_devices.py | 4++--
3 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c @@ -1792,11 +1792,12 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin for (unsigned stage = 0; stage < 2; ++stage) { float *uv = stage ? vertices[i].uv_second : vertices[i].uv; unsigned coordinate = device->stages[stage].texture_coordinate; - uv[0] = uv[1] = 0; - if (coordinate < texture_count) - memcpy(uv, (const unsigned char *)input_vertex + stride - texture_count * 8 + coordinate * 8, 8); - if (device->stages[stage].texture_transform == 2) { - float input_uv[] = {uv[0], uv[1], 1, 0}, transformed[4]; + float input_uv[] = {0, 0, 1, 0}, transformed[4]; + if (coordinate == 0x20000) memcpy(input_uv, camera, 16); + else if (coordinate < texture_count) + memcpy(input_uv, (const unsigned char *)input_vertex + stride - texture_count * 8 + coordinate * 8, 8); + memcpy(uv, input_uv, 8); + if (device->stages[stage].texture_transform) { transform_vector(input_uv, (const float *)device->transforms[3 + stage], transformed); memcpy(uv, transformed, 8); } @@ -1820,6 +1821,8 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin for (unsigned stage = 0; stage < 2; ++stage) { float *uv = stage ? vertices[i].uv_second : vertices[i].uv; unsigned coordinate = device->stages[stage].texture_coordinate; + /* Pretransformed vertices use the stage's own UV set for generation modes. */ + if (coordinate == 0x20000) coordinate = stage; uv[0] = uv[1] = 0; if (coordinate < texture_count) memcpy(uv, (void *)ADDR(input + i * stride + uv_offset + coordinate * 8), 8); @@ -1954,11 +1957,11 @@ static void device_set_texture_state(void) struct device_object *device = find_device(MEM32(g_esp + 4)); uint32_t stage = MEM32(g_esp + 8), state = MEM32(g_esp + 12), value = MEM32(g_esp + 16); if (stage >= 2) { fprintf(stderr, "Unsupported texture stage %u\n", stage); exit(3); } - if (state == 11 && value <= 1) device->stages[stage].texture_coordinate = value; + if (state == 11 && (value <= 1 || value == 0x20000)) device->stages[stage].texture_coordinate = value; else if (state == 16 && (value == 1 || value == 2)) device->stages[stage].mag_filter = value; else if (state == 17 && (value == 1 || value == 2)) device->stages[stage].min_filter = value; else if (state == 18 && (value == 1 || value == 2)) device->stages[stage].mip_filter = value; - else if (state == 24 && (value == 0 || value == 2)) device->stages[stage].texture_transform = value; + else if (state == 24 && (value == 0 || value == 2 || value == 3)) device->stages[stage].texture_transform = value; /* ADDRESS has an independent cache; only changed states update the sampler. */ else if (state == 12 && (value == 1 || value == 3)) { if (device->stages[stage].address != value) device->stages[stage].sampler_u = device->stages[stage].sampler_v = value; diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c @@ -1077,12 +1077,20 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32 assert(!invoke(device, 20, 3, 27u, 1u)); assert(!invoke(device, 20, 3, 19u, 5u)); assert(!invoke(device, 20, 3, 20u, 6u)); - for (unsigned sample = 0; sample < 320; ++sample) { + for (unsigned sample = 0; sample < 448; ++sample) { struct vertex { float x, y, z, rhw; uint32_t color; float u, v, u1, v1; } vertices[] = { {0,0,.25f,1,0x4080c0a0, -.25f,.125f, .875f,-.375f}, {32,0,.25f,.5f,0x8080c0a0, 1.75f,.125f, -.125f,-.375f}, {0,32,.25f,2,0xc080c0a0, -.25f,1.875f, .875f,1.625f}, }; + if (sample >= 320) { + const float world[] = {.75f,0,0,0, 0,.875f,0,0, 0,0,1,0, .125f,0,0,1}; + const float view[] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,-.25f,0,1}; + memcpy(memory(workspace() + 1024), world, 64); + assert(!invoke(device, 11, 3, 1u, workspace() + 1024)); + memcpy(memory(workspace() + 1024), view, 64); + assert(!invoke(device, 11, 3, 2u, workspace() + 1024)); + } uint32_t factor = sample & 8 ? 0x804060c0u : 0x20c08040u; assert(!invoke(device, 20, 3, 60u, factor)); assert(!invoke(device, 21, 3, 60u, workspace()) && *memory(workspace()) == factor); @@ -1092,14 +1100,14 @@ static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32 memcpy(memory(input + i * 32), xyz, 12); memcpy(memory(input + i * 32 + 12), &vertices[i].color, 20); } - const uint32_t arguments[] = {0, 1, 2, 0, 3}; + const uint32_t arguments[] = {0, 1, 2, 0, 3, 2, 2}; for (unsigned stage = 0; stage < 2; ++stage) { uint32_t texture = sample >= 192 && sample < 256 ? 0 : textures[sample & 16 ? 0 : stage]; assert(!invoke(device, 35, 3, stage, texture)); assert(!invoke(device, 34, 3, stage, workspace()) && *memory(workspace()) == texture); if (texture) assert(invoke(texture, 2, 1) > 0); - assert(!invoke(device, 37, 4, stage, 11u, stage)); - assert(!invoke(device, 37, 4, stage, 24u, sample & 32 ? 2u : 0u)); + assert(!invoke(device, 37, 4, stage, 11u, sample >= 320 && (stage || (sample & 16)) ? 0x20000u : stage)); + assert(!invoke(device, 37, 4, stage, 24u, sample >= 384 ? 3u : sample >= 320 ? (sample & 4 ? 2u : 0u) : sample & 32 ? 2u : 0u)); const float matrix[] = {2,0,0,0, 0,1,0,0, .125f,.375f,1,0, 0,0,0,1}; memcpy(memory(workspace() + 1024), matrix, 64); assert(!invoke(device, 11, 3, 16u + stage, workspace() + 1024)); diff --git a/tools/reconstruction/test_portable_devices.py b/tools/reconstruction/test_portable_devices.py @@ -25,8 +25,8 @@ actual = subprocess.check_output(wsl + ["env", "GALLIUM_DRIVER=d3d12", linux_wor assert actual == expected, (expected, actual) windows_pixels = (work / "reference.rgb").read_bytes() linux_pixels = (work / "native.rgb").read_bytes() -assert len(windows_pixels) == len(linux_pixels) == 4970496 +assert len(windows_pixels) == len(linux_pixels) == 5363712 error = max(abs(a - b) for a, b in zip(windows_pixels, linux_pixels)) assert error <= 1, error print("Windows == Linux: " + actual.strip()) -print("All 1656832 pixels agree within one 8-bit channel step; maximum error:", error) +print("All 1787904 pixels agree within one 8-bit channel step; maximum error:", error)