Stefan Dösinger : wined3d: Properly set the fog frag coord according to the FOGTABLEMODE.

Alexandre Julliard julliard at winehq.org
Wed Feb 11 09:24:25 CST 2009


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

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Sat Jan 10 02:29:39 2009 +0100

wined3d: Properly set the fog frag coord according to the FOGTABLEMODE.

This also fixes the test that an earlier patch broke, so the todo_wine can be
removed again.

---

 dlls/d3d9/tests/visual.c          |   12 +++---------
 dlls/wined3d/arb_program_shader.c |   11 +++++++++--
 dlls/wined3d/glsl_shader.c        |   11 +++++++++--
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index f7e41e0..6c26c6a 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -1539,15 +1539,9 @@ static void fog_with_shader_test(IDirect3DDevice9 *device)
 
             /* As the red and green component are the result of blending use 5% tolerance on the expected value */
             color = getPixelColor(device, 128, 240);
-            if(test_data[i].vshader == 1 && test_data[i].tfog == 0 && color != test_data[i].color[j]) {
-                todo_wine ok(color_match(color, test_data[i].color[j], 13),
-                             "fog vs%i ps%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%(todo)\n",
-                             test_data[i].vshader, test_data[i].pshader, test_data[i].vfog, test_data[i].tfog, j, color, test_data[i].color[j]);
-            } else {
-                ok(color_match(color, test_data[i].color[j], 13),
-                   "fog vs%i ps%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%\n",
-                   test_data[i].vshader, test_data[i].pshader, test_data[i].vfog, test_data[i].tfog, j, color, test_data[i].color[j]);
-            }
+            ok(color_match(color, test_data[i].color[j], 13),
+                "fog vs%i ps%i fvm%i ftm%i %d: got color %08x, expected %08x +-5%%\n",
+                test_data[i].vshader, test_data[i].pshader, test_data[i].vfog, test_data[i].tfog, j, color, test_data[i].color[j]);
         }
     }
 
diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index b3627fd..6bc152a 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -2068,9 +2068,16 @@ static GLuint shader_arb_generate_vshader(IWineD3DVertexShader *iface, SHADER_BU
     /* Base Shader Body */
     shader_generate_main( (IWineD3DBaseShader*) This, buffer, reg_maps, function);
 
-    /* If this shader doesn't use fog copy the z coord to the fog coord so that we can use table fog */
-    if (!reg_maps->fog)
+    /* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
+     * or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
+     * the fog frag coord is thrown away. If the fog frag coord is used, but not written by
+     * the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0)
+     */
+    if(args->fog_src == VS_FOG_Z) {
         shader_addline(buffer, "MOV result.fogcoord, TMP_OUT.z;\n");
+    } else if (!reg_maps->fog) {
+        shader_addline(buffer, "MOV result.fogcoord, 0.0;\n");
+    }
 
     /* Write the final position.
      *
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 75f8b03..d83eecb 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -3912,9 +3912,16 @@ static GLuint shader_glsl_generate_vshader(IWineD3DVertexShader *iface, SHADER_B
     if (reg_maps->shader_version >= WINED3DVS_VERSION(3,0)) shader_addline(buffer, "order_ps_input(OUT);\n");
     else shader_addline(buffer, "order_ps_input();\n");
 
-    /* If this shader doesn't use fog copy the z coord to the fog coord so that we can use table fog */
-    if (!reg_maps->fog)
+    /* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
+     * or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
+     * the fog frag coord is thrown away. If the fog frag coord is used, but not written by
+     * the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0)
+     */
+    if(args->fog_src == VS_FOG_Z) {
         shader_addline(buffer, "gl_FogFragCoord = gl_Position.z;\n");
+    } else if (!reg_maps->fog) {
+        shader_addline(buffer, "gl_FogFragCoord = 0.0;\n");
+    }
 
     /* Write the final position.
      *




More information about the wine-cvs mailing list