From: Elizabeth Figura <zfigura@codeweavers.com> This is primarily a regression test for e77fc003c136086cac640d5bd687bcf47993f9f3. --- dlls/d3d9/tests/visual.c | 126 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c index c8a20d446b0..ade80fbe9a1 100644 --- a/dlls/d3d9/tests/visual.c +++ b/dlls/d3d9/tests/visual.c @@ -28891,6 +28891,131 @@ static void test_texture_transform_flags(void) release_test_context(&context); } +/* A test to show that lights are affected by the view matrix but not the world + * matrix, and to make sure that lighting is invalidated when the view matrix + * (and nothing else) changes. */ +static void test_lighting_matrices(void) +{ + struct d3d9_test_context context; + struct surface_readback rb; + IDirect3DDevice9 *device; + unsigned int color; + HRESULT hr; + + static const D3DMATERIAL9 material = {.Power = 1.0f}; + + static const D3DLIGHT9 light = + { + .Type = D3DLIGHT_SPOT, + .Diffuse = {1.0f, 1.0f, 1.0f, 1.0f}, + .Specular = {1.0f, 1.0f, 1.0f, 1.0f}, + .Position = {2.0f, -2.0f, 2.0f}, + .Direction = {1.0f, 1.0f, -0.5f}, + .Range = 1000.0f, + .Falloff = 1.0f, + .Attenuation1 = 0.1f, + .Theta = 1.0f, + .Phi = 3.0f, + }; + + static const D3DMATRIX world_matrix = + {{{ + 0.5f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.5f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.5f, 0.0f, + 0.0f, 0.2f, 0.0f, 1.0f, + }}}; + + static const D3DMATRIX view_matrix = + {{{ + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.0f, 1.0f, + }}}; + + static const struct + { + struct vec3 position; + struct vec3 normal; + unsigned int diffuse; + unsigned int specular; + } + tri[] = + { + {{ 2.0f, -2.0f, 0.5f}, {-0.3f, -0.4f, 0.4f}, 0x00ff0000, 0x0000ff00}, + {{-2.0f, -2.0f, 0.5f}, {-1.0f, 0.4f, 0.4f}, 0x00ff0000, 0x0000ff00}, + {{ 0.0f, 2.0f, 0.5f}, { 0.0f, -0.4f, 0.4f}, 0x00ff0000, 0x0000ff00}, + }, + tri2[] = + { + {{ 1.0f, -3.0f, 0.5f}, {-0.3f, -0.4f, 0.4f}, 0x00ff0000, 0x0000ff00}, + {{-3.0f, -3.0f, 0.5f}, {-1.0f, 0.4f, 0.4f}, 0x00ff0000, 0x0000ff00}, + {{-1.0f, 1.0f, 0.5f}, { 0.0f, -0.4f, 0.4f}, 0x00ff0000, 0x0000ff00}, + }; + + if (!init_test_context(&context)) + return; + device = context.device; + + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetMaterial(device, &material); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetLight(device, 123, &light); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_LightEnable(device, 123, TRUE); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARENABLE, TRUE); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world_matrix); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 1, tri, sizeof(*tri)); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + get_rt_readback(context.backbuffer, &rb); + color = get_readback_color(&rb, 320, 240); + ok(color_match(color, 0x939100, 1), "Got color %08x.\n", color); + color = get_readback_color(&rb, 10, 430); + ok(color_match(color, 0x040400, 1), "Got color %08x.\n", color); + color = get_readback_color(&rb, 320, 10); + ok(color_match(color, 0xb5a600, 1), "Got color %08x.\n", color); + color = get_readback_color(&rb, 630, 430); + ok(color_match(color, 0xeafb00, 1), "Got color %08x.\n", color); + release_surface_readback(&rb); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &view_matrix); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 1, tri2, sizeof(*tri2)); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + get_rt_readback(context.backbuffer, &rb); + color = get_readback_color(&rb, 320, 240); + ok(color_match(color, 0x1d1c00, 1), "Got color %08x.\n", color); + color = get_readback_color(&rb, 10, 430); + ok(color_match(color, 0x000000, 1), "Got color %08x.\n", color); + color = get_readback_color(&rb, 320, 10); + ok(color_match(color, 0x3f3d00, 1), "Got color %08x.\n", color); + color = get_readback_color(&rb, 630, 430); + ok(color_match(color, 0x000000, 1), "Got color %08x.\n", color); + release_surface_readback(&rb); + + release_test_context(&context); +} + START_TEST(visual) { D3DADAPTER_IDENTIFIER9 identifier; @@ -29050,4 +29175,5 @@ START_TEST(visual) test_ffp_w(); test_fog(); test_texture_transform_flags(); + test_lighting_matrices(); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9850