David Adam : d3dx8: Implement D3DXFresnelTerm.

Alexandre Julliard julliard at winehq.org
Mon Feb 2 09:01:20 CST 2009


Module: wine
Branch: master
Commit: f20ba244049f5473369e32df5fe108244da3e180
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f20ba244049f5473369e32df5fe108244da3e180

Author: David Adam <david.adam.cnrs at gmail.com>
Date:   Sat Jan 31 14:57:13 2009 +0100

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(+), 0 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 3587c6b..036a510 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 bde0e84..b355c9c 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 b1bfd74..6a7f99d 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 88da2b0..ee5c220 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);




More information about the wine-cvs mailing list