From f20ba244049f5473369e32df5fe108244da3e180 Mon Sep 17 00:00:00 2001 From: David Adam Date: Sat, 31 Jan 2009 14:57:13 +0100 Subject: [PATCH] d3dx8: Implement D3DXFresnelTerm. --- dlls/d3dx8/d3dx8.spec | 1 + dlls/d3dx8/math.c | 14 ++++++++++++++ dlls/d3dx8/tests/math.c | 10 ++++++++++ include/d3dx8math.h | 2 ++ 4 files changed, 27 insertions(+) diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec index 3587c6b4e07..036a510244b 100644 --- a/dlls/d3dx8/d3dx8.spec +++ b/dlls/d3dx8/d3dx8.spec @@ -68,6 +68,7 @@ @ stdcall D3DXPlaneTransform(ptr ptr ptr) @ stdcall D3DXColorAdjustSaturation(ptr ptr long) @ stdcall D3DXColorAdjustContrast(ptr ptr long) +@ stdcall D3DXFresnelTerm(long long) @ stdcall D3DXCreateMatrixStack(long ptr) @ stdcall D3DXCreateFont(ptr ptr ptr) @ stub D3DXCreateFontIndirect diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c index bde0e8429f8..b355c9cc309 100644 --- a/dlls/d3dx8/math.c +++ b/dlls/d3dx8/math.c @@ -58,6 +58,20 @@ D3DXCOLOR* WINAPI D3DXColorAdjustSaturation(D3DXCOLOR *pout, CONST D3DXCOLOR *pc return pout; } +/*_________________Misc__________________________*/ + +FLOAT WINAPI D3DXFresnelTerm(FLOAT costheta, FLOAT refractionindex) +{ + FLOAT a, d, g, result; + + g = sqrt(refractionindex * refractionindex + costheta * costheta - 1.0f); + a = g + costheta; + d = g - costheta; + result = ( costheta * a - 1.0f ) * ( costheta * a - 1.0f ) / ( ( costheta * d + 1.0f ) * ( costheta * d + 1.0f ) ) + 1.0f; + result = result * 0.5f * d * d / ( a * a ); + return result; +} + /*_________________D3DXMatrix____________________*/ D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, FLOAT scaling, CONST D3DXVECTOR3 *rotationcenter, CONST D3DXQUATERNION *rotation, CONST D3DXVECTOR3 *translation) diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c index b1bfd74cfe8..6a7f99da03b 100644 --- a/dlls/d3dx8/tests/math.c +++ b/dlls/d3dx8/tests/math.c @@ -166,6 +166,15 @@ static void D3DXColorTest(void) ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); } +static void D3DXFresnelTest(void) +{ + FLOAT expected, got; + + expected = 0.089187; + got = D3DXFresnelTerm(0.5f,1.5); + ok( fabs(got - expected) < admitted_error, "Expected: %f, Got: %f\n", expected, got); +} + static void D3DXMatrixTest(void) { D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3; @@ -1498,6 +1507,7 @@ static void test_matrix_stack(void) START_TEST(math) { D3DXColorTest(); + D3DXFresnelTest(); D3DXMatrixTest(); D3DXPlaneTest(); D3X8QuaternionTest(); diff --git a/include/d3dx8math.h b/include/d3dx8math.h index 88da2b05f74..ee5c220dd0e 100644 --- a/include/d3dx8math.h +++ b/include/d3dx8math.h @@ -271,6 +271,8 @@ extern "C" { D3DXCOLOR* WINAPI D3DXColorAdjustContrast(D3DXCOLOR *pout, CONST D3DXCOLOR *pc, FLOAT s); D3DXCOLOR* WINAPI D3DXColorAdjustSaturation(D3DXCOLOR *pout, CONST D3DXCOLOR *pc, FLOAT s); +FLOAT WINAPI D3DXFresnelTerm(FLOAT costheta, FLOAT refractionindex); + D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, FLOAT scaling, CONST D3DXVECTOR3 *rotationcenter, CONST D3DXQUATERNION *rotation, CONST D3DXVECTOR3 *translation); FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm); D3DXMATRIX* WINAPI D3DXMatrixInverse(D3DXMATRIX *pout, FLOAT *pdeterminant, CONST D3DXMATRIX *pm);