[2/7] wined3d: Remove fog coordinate clamping in the vertex shader

Fabian Bieler der.fabe at gmx.net
Thu Mar 22 12:19:10 CDT 2007


This patch removes the clamping of the fog coordinate from the vertex shader.
This should neither be neccessary in combination with pixel shaders as the 
coordinate is clamped there anyway, nor in combination with the fixed 
function rasterizer as the specs clearly state, that when shaders are used, 
the fog computation should take place in the rasterizer [1,2,3], and clamping 
the fog coordinate (rather than the fog parameter) makes no sense.

Also, this patch passes the vertex z coord to the fog coordinate if it is not 
used otherwise to enable table fog with such vertex programs (linear with 
pixel shaders, all modes with fixed function rasterizer).

[1]: The OpenGL Graphics System: A Specificatoin: ver2.1: section 3.10
[2]: http://www.opengl.org/registry/specs/ARB/vertex_program.txt: 4419f
[3]: The OpenGL Shading Language: ver1.20, rev6: section 7.6
-------------- next part --------------
From 66fd23c8d458e4283f7ab7120d38540f0793def6 Mon Sep 17 00:00:00 2001
From: Fabian Bieler <der.fabe at gmx.net>
Date: Thu, 22 Mar 2007 17:34:57 +0100
Subject: [PATCH] wined3d: Remove fog coordinate clamping in the vertex shader

---
 dlls/wined3d/arb_program_shader.c |    2 +-
 dlls/wined3d/vertexshader.c       |   19 ++++++++-----------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index d24a5f9..bffc2a4 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -313,7 +313,7 @@ static void vshader_program_add_param(SHADER_OPCODE_ARG *arg, const DWORD param,
   IWineD3DVertexShaderImpl* This = (IWineD3DVertexShaderImpl*) arg->shader;
 
   /* oPos, oFog and oPts in D3D */
-  static const char * const hwrastout_reg_names[] = { "TMP_OUT", "TMP_FOG", "result.pointsize" };
+  static const char * const hwrastout_reg_names[] = { "TMP_OUT", "result.fogcoord", "result.pointsize" };
 
   DWORD reg = param & WINED3DSP_REGNUM_MASK;
   DWORD regtype = shader_get_regtype(param);
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index 5d3a506..22c49c2 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -336,11 +336,11 @@ static VOID IWineD3DVertexShaderImpl_GenerateShader(
         if (This->baseShader.hex_version >= WINED3DVS_VERSION(3,0))
             vshader_glsl_output_unpack(&buffer, This->semantics_out);
 
-        /* Clamp the fog from 0 to 1 if it's used */
-        if (reg_maps->fog) {
+        /* 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)
             This->usesFog = 1;
-            shader_addline(&buffer, "gl_FogFragCoord = clamp(gl_FogFragCoord, 0.0, 1.0);\n");
-        }
+        else
+            shader_addline(&buffer, "gl_FogFragCoord = gl_Position.z;\n");
         
         /* Write the final position.
          *
@@ -382,17 +382,14 @@ static VOID IWineD3DVertexShaderImpl_GenerateShader(
         /* We need a constant to fixup the final position */
         shader_addline(&buffer, "PARAM posFixup = program.env[%d];\n", ARB_SHADER_PRIVCONST_POS);
 
-        if (reg_maps->fog) {
-            This->usesFog = 1;
-            shader_addline(&buffer, "TEMP TMP_FOG;\n");
-        }
-
         /* Base Shader Body */
         shader_generate_main( (IWineD3DBaseShader*) This, &buffer, reg_maps, pFunction);
 
-        /* Make sure the fog value is positive - values above 1.0 are ignored */
+        /* 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)
-            shader_addline(&buffer, "MAX result.fogcoord, TMP_FOG, 0.0;\n");
+            This->usesFog = 1;
+        else
+            shader_addline(&buffer, "MOV result.fogcoord, TMP_OUT.z;\n");
 
         /* Write the final position.
          *
-- 
1.4.4.1



More information about the wine-patches mailing list