[6/7] wined3d: Fix arb texbem instruction for projective textures

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


-------------- next part --------------
From a7064c9e8d68797509a212c65e812a995e79c88c Mon Sep 17 00:00:00 2001
From: Fabian Bieler <der.fabe at gmx.net>
Date: Thu, 22 Mar 2007 17:43:50 +0100
Subject: [PATCH] wined3d: Fix arb texbem instruction for projective textures

---
 dlls/wined3d/arb_program_shader.c |   38 +++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index bffc2a4..2185455 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -379,7 +379,7 @@ static void vshader_program_add_param(SHADER_OPCODE_ARG *arg, const DWORD param,
   }
 }
 
-static void shader_hw_sample(SHADER_OPCODE_ARG* arg, DWORD sampler_idx, const char *dst_str, const char *coord_reg) {
+static void shader_hw_sample(SHADER_OPCODE_ARG* arg, DWORD sampler_idx, const char *dst_str, const char *coord_reg, BOOL projective) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
     IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *) deviceImpl->stateBlock->textures[sampler_idx];
@@ -411,7 +411,7 @@ static void shader_hw_sample(SHADER_OPCODE_ARG* arg, DWORD sampler_idx, const ch
             tex_type = "";
     }
 
-    if (deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS] & WINED3DTTFF_PROJECTED) {
+    if (projective && deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS] & WINED3DTTFF_PROJECTED) {
         shader_addline(buffer, "TXP %s, %s, texture[%u], %s;\n", dst_str, coord_reg, sampler_idx, tex_type);
     } else {
         shader_addline(buffer, "TEX %s, %s, texture[%u], %s;\n", dst_str, coord_reg, sampler_idx, tex_type);
@@ -656,7 +656,7 @@ void pshader_hw_tex(SHADER_OPCODE_ARG* arg) {
   else
      reg_sampler_code = src[1] & WINED3DSP_REGNUM_MASK;
 
-  shader_hw_sample(arg, reg_sampler_code, reg_dest, reg_coord);
+  shader_hw_sample(arg, reg_sampler_code, reg_dest, reg_coord, TRUE);
 }
 
 void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg) {
@@ -690,7 +690,7 @@ void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg) {
      sprintf(dst_str, "T%u", reg1);
      shader_addline(buffer, "MOV TMP.r, T%u.a;\n", reg2);
      shader_addline(buffer, "MOV TMP.g, T%u.r;\n", reg2);
-     shader_hw_sample(arg, reg1, dst_str, "TMP");
+     shader_hw_sample(arg, reg1, dst_str, "TMP", TRUE);
 }
 
 void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg) {
@@ -704,7 +704,7 @@ void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg) {
      sprintf(dst_str, "T%u", reg1);
      shader_addline(buffer, "MOV TMP.r, T%u.g;\n", reg2);
      shader_addline(buffer, "MOV TMP.g, T%u.b;\n", reg2);
-     shader_hw_sample(arg, reg1, dst_str, "TMP");
+     shader_hw_sample(arg, reg1, dst_str, "TMP", TRUE);
 }
 
 void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
@@ -729,13 +729,23 @@ void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
         shader_addline(buffer, "DP3 TMP.r, TMP2, T%u;\n", src);
         shader_addline(buffer, "SWZ TMP2, bumpenvmat, y, w, 0, 0;\n");
         shader_addline(buffer, "DP3 TMP.g, TMP2, T%u;\n", src);
-        shader_addline(buffer, "ADD TMP.rg, TMP, %s;\n", reg_coord);
-        /* Not sure about this, but hl2 needs it. It uses a projected texture with texbem and depends on the 4th coordinate */
-        shader_addline(buffer, "MOV TMP.a, %s;\n", reg_coord);
-        shader_hw_sample(arg, reg_dest_code, reg_coord, "TMP");
+
+        /* with projective textures, texbem only divides the static texture coord, not the displacement,
+         * so we can't let the GL handle this.
+         */
+        if (((IWineD3DDeviceImpl*) This->baseShader.device)->stateBlock->textureState[reg_dest_code][WINED3DTSS_TEXTURETRANSFORMFLAGS]
+              & WINED3DTTFF_PROJECTED) {
+            shader_addline(buffer, "RCP TMP2.a, %s.a;\n", reg_coord);
+            shader_addline(buffer, "MUL TMP2.rg, %s, TMP2.a;\n", reg_coord);
+            shader_addline(buffer, "ADD TMP.rg, TMP, TMP2;\n");
+        } else {
+            shader_addline(buffer, "ADD TMP.rg, TMP, %s;\n", reg_coord);
+        }
+
+        shader_hw_sample(arg, reg_dest_code, reg_coord, "TMP", FALSE);
     } else {
         /* Without a bump matrix loaded, just sample with the unmodified coordinates */
-        shader_hw_sample(arg, reg_dest_code, reg_coord, reg_coord);
+        shader_hw_sample(arg, reg_dest_code, reg_coord, reg_coord, TRUE);
     }
 }
 
@@ -759,7 +769,7 @@ void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg) {
     sprintf(dst_str, "T%u", reg);
     pshader_gen_input_modifier_line(buffer, arg->src[0], 0, src0_name);
     shader_addline(buffer, "DP3 TMP.y, T%u, %s;\n", reg, src0_name);
-    shader_hw_sample(arg, reg, dst_str, "TMP");
+    shader_hw_sample(arg, reg, dst_str, "TMP", TRUE);
 }
 
 void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg) {
@@ -789,7 +799,7 @@ void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg) {
 
     /* Sample the texture using the calculated coordinates */
     sprintf(dst_str, "T%u", reg);
-    shader_hw_sample(arg, reg, dst_str, "TMP");
+    shader_hw_sample(arg, reg, dst_str, "TMP", TRUE);
     current_state->current_row = 0;
 }
 
@@ -817,7 +827,7 @@ void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
 
     /* Sample the texture using the calculated coordinates */
     sprintf(dst_str, "T%u", reg);
-    shader_hw_sample(arg, reg, dst_str, "TMP");
+    shader_hw_sample(arg, reg, dst_str, "TMP", TRUE);
     current_state->current_row = 0;
 }
 
@@ -841,7 +851,7 @@ void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg) {
 
     /* Sample the texture using the calculated coordinates */
     sprintf(dst_str, "T%u", reg);
-    shader_hw_sample(arg, reg, dst_str, "TMP");
+    shader_hw_sample(arg, reg, dst_str, "TMP", TRUE);
     current_state->current_row = 0;
 }
 
-- 
1.4.4.1



More information about the wine-patches mailing list