aorecomp

Anarchy Online classic in the browser

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


commit d177a5cb61dfe8d5414e820a285639675d770d67
parent d4408069694eb3c5092caaaf2be2de48f45589b1
Author: anon <anon@example.com>
Date:   Fri, 23 Oct 2026 00:13:52 +0000

Support fourfold texture modulation for nano effects

Implement clamped color and alpha modulation in the Direct3D adapter and shared renderer. Verify both stages with native and WASM pixel tests and rebuild the browser bundle.

Diffstat:
Mclient/runtime/gl_renderer.c | 3++-
Mclient/runtime/linux_graphics.c | 4++--
Mclient/tests/devices.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/client/runtime/gl_renderer.c b/client/runtime/gl_renderer.c @@ -205,8 +205,9 @@ int gl_renderer_initialize(void) "vec3 c1=argument(color_arg1[s],t).rgb, c2=argument(color_arg2[s],t).rgb;" "float a1=argument(alpha_arg1[s],t).a, a2=argument(alpha_arg2[s],t).a;" "pixel.rgb=color_op[s]==4 ? c1*c2 : color_op[s]==7 ? min(vec3(1.0),c1+c2) : c1;" + "if(color_op[s]==6) pixel.rgb=min(vec3(1.0),4.0*c1*c2);" "if(color_op[s]==20) pixel.rgb=min(vec3(1.0),c1+(1.0-argument(color_arg1[s],t).a)*c2);" - "if(alpha_op[s]!=1) pixel.a=alpha_op[s]==3 ? a2 : alpha_op[s]==4 ? a1*a2 : a1; }\n" + "if(alpha_op[s]!=1) pixel.a=alpha_op[s]==3 ? a2 : alpha_op[s]==4 ? a1*a2 : alpha_op[s]==6 ? min(1.0,4.0*a1*a2) : a1; }\n" "void main() { pixel=color; if(textured[0]) { combine(0,texture(image0,uv));" "if(textured[1]) combine(1,texture(image1,uv_second)); }" "pixel.rgb=min(vec3(1.0),pixel.rgb+highlight);" diff --git a/client/runtime/linux_graphics.c b/client/runtime/linux_graphics.c @@ -2372,8 +2372,8 @@ static void device_set_texture_state(void) if (device->stages[stage].address_v != value) device->stages[stage].sampler_v = value; device->stages[stage].address_v = value; } - else if (state == 1 && (value == 1 || value == 2 || value == 4 || value == 7 || value == 20)) device->stages[stage].color_op = value; - else if (state == 4 && (value >= 1 && value <= 4)) device->stages[stage].alpha_op = value; + else if (state == 1 && (value == 1 || value == 2 || value == 4 || value == 6 || value == 7 || value == 20)) device->stages[stage].color_op = value; + else if (state == 4 && ((value >= 1 && value <= 4) || value == 6)) device->stages[stage].alpha_op = value; /* CURRENT selects the preceding stage; DIFFUSE selects vertex color. */ else if (state == 2 && (value & ~0x20u) <= 3) device->stages[stage].color_arg1 = value; else if (state == 5 && (value & ~0x20u) <= 3) device->stages[stage].alpha_arg1 = value; diff --git a/client/tests/devices.c b/client/tests/devices.c @@ -1383,6 +1383,70 @@ static void depth_bias_offsets_overlapping_geometry(uint32_t device, uint32_t ta assert(!invoke(device, 20, 3, 23u, 4u)); } +static void fourfold_modulation_clamps_before_the_next_stage(uint32_t device, uint32_t target) +{ + uint32_t desc = workspace() + 128, input = workspace() + 512; + struct vertex { float x, y, z, rhw; uint32_t color; } vertices[] = { + {0,0,.25f,1,0xc0c04020}, {32,0,.25f,1,0xc0c04020}, {0,32,.25f,1,0xc0c04020} + }; + memcpy(memory(input), vertices, sizeof(vertices)); + assert(!invoke(device, 20, 3, 137u, 0u)); + assert(!invoke(device, 20, 3, 29u, 0u)); + assert(!invoke(device, 20, 3, 28u, 0u)); + assert(!invoke(device, 20, 3, 27u, 0u)); + assert(!invoke(device, 20, 3, 15u, 0u)); + assert(!invoke(device, 20, 3, 22u, 1u)); + assert(!invoke(device, 20, 3, 23u, 8u)); + assert(!invoke(device, 20, 3, 60u, 0x80808080u)); + for (unsigned stage = 0; stage < 2; ++stage) { + assert(!invoke(device, 35, 3, stage, 0u)); + assert(!invoke(device, 37, 4, stage, 2u, stage ? 1u : 3u)); + assert(!invoke(device, 37, 4, stage, 3u, stage ? 3u : 0u)); + assert(!invoke(device, 37, 4, stage, 4u, 2u)); + assert(!invoke(device, 37, 4, stage, 5u, stage ? 1u : 0u)); + } + + assert(!invoke(device, 37, 4, 0u, 1u, 6u)); + assert(!invoke(device, 37, 4, 1u, 1u, 4u)); + assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f800000u, 0u)); + assert(!invoke(device, 5, 1)); + assert(!invoke(device, 25, 6, 4u, 0x44u, input, 3u, 0u)); + assert(!invoke(device, 6, 1)); + + assert(!invoke(device, 36, 4, 0u, 1u, workspace()) && *memory(workspace()) == 6); + *memory(desc) = 124; + assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); + uint32_t pixels = *memory(desc + 36), pitch = *memory(desc + 16); + assert((*memory(pixels + 8 * pitch + 8 * 4) & 0xffffff) == 0x804120); + assert(!invoke(target, 32, 2, 0u)); + + for (unsigned i = 0; i < 3; ++i) vertices[i].color = 0xc0c08020; + memcpy(memory(input), vertices, sizeof(vertices)); + assert(!invoke(device, 37, 4, 0u, 4u, 6u)); + assert(!invoke(device, 37, 4, 0u, 5u, 3u)); + assert(!invoke(device, 37, 4, 0u, 6u, 0u)); + assert(!invoke(device, 37, 4, 1u, 4u, 4u)); + assert(!invoke(device, 37, 4, 1u, 6u, 3u)); + assert(!invoke(device, 20, 3, 27u, 1u)); + assert(!invoke(device, 20, 3, 19u, 5u)); + assert(!invoke(device, 20, 3, 20u, 6u)); + + assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff000000u, 0x3f800000u, 0u)); + assert(!invoke(device, 5, 1)); + assert(!invoke(device, 25, 6, 4u, 0x44u, input, 3u, 0u)); + assert(!invoke(device, 6, 1)); + + assert(!invoke(device, 36, 4, 0u, 4u, workspace()) && *memory(workspace()) == 6); + *memory(desc) = 124; + assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); + pixels = *memory(desc + 36); pitch = *memory(desc + 16); + assert((*memory(pixels + 8 * pitch + 8 * 4) & 0xffffff) == 0x404010); + assert(!invoke(target, 32, 2, 0u)); + assert(!invoke(device, 37, 4, 1u, 1u, 1u)); + assert(!invoke(device, 37, 4, 0u, 1u, 4u)); + assert(!invoke(device, 20, 3, 23u, 4u)); +} + static void two_texture_stages_combine_independent_samples(uint32_t draw, uint32_t device, uint32_t target, FILE *file) { uint32_t desc = workspace() + 128, input = workspace() + 512, textures[2]; @@ -1850,6 +1914,7 @@ static void device_lifetime_and_rendering(const char *pixels_path) assert(invoke(d3d, 2, 1) > 0); depth_bias_offsets_overlapping_geometry(device, color, 24, file); alpha_tests_preserve_rejected_color_and_depth(draw, device, color, file); + fourfold_modulation_clamps_before_the_next_stage(device, color); two_texture_stages_combine_independent_samples(draw, device, color, file); line_lists_draw_independent_segments(draw, device, color); assert(!fclose(file));