From: Elizabeth Figura zfigura@codeweavers.com
Pass it to GLSL as a 4x4 matrix, and truncate it before use.
This will be necessary for the HLSL backend, which pads matrices to 4xn. --- dlls/wined3d/device.c | 13 +++---------- dlls/wined3d/glsl_shader.c | 10 +++++----- dlls/wined3d/stateblock.c | 2 +- dlls/wined3d/utils.c | 16 +++++++++++----- dlls/wined3d/wined3d_private.h | 4 ++-- 5 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 47469027ba7..0fb71108b27 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -34,13 +34,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d); WINE_DECLARE_DEBUG_CHANNEL(d3d_perf); WINE_DECLARE_DEBUG_CHANNEL(winediag);
-struct wined3d_matrix_3x3 -{ - float _11, _12, _13; - float _21, _22, _23; - float _31, _32, _33; -}; - struct light_transformed { struct wined3d_color diffuse, specular, ambient; @@ -54,7 +47,7 @@ struct lights_settings struct light_transformed lights[WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS]; struct wined3d_color ambient_light; struct wined3d_matrix modelview_matrix; - struct wined3d_matrix_3x3 normal_matrix; + struct wined3d_matrix normal_matrix; struct wined3d_vec4 position_transformed;
float fog_start, fog_end, fog_density; @@ -2894,7 +2887,7 @@ static void wined3d_vec3_normalise(struct wined3d_vec3 *v) }
static void wined3d_vec3_transform(struct wined3d_vec3 *dst, - const struct wined3d_vec3 *v, const struct wined3d_matrix_3x3 *m) + const struct wined3d_vec3 *v, const struct wined3d_matrix *m) { struct wined3d_vec3 tmp;
@@ -2951,7 +2944,7 @@ static void init_transformed_lights(struct lights_settings *ls, if (!compute_lighting) return;
- compute_normal_matrix(&ls->normal_matrix._11, legacy_lighting, &ls->modelview_matrix); + compute_normal_matrix(&ls->normal_matrix, legacy_lighting, &ls->modelview_matrix);
wined3d_color_from_d3dcolor(&ls->ambient_light, state->rs[WINED3D_RS_AMBIENT]); ls->legacy_lighting = !!legacy_lighting; diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 49b641d0635..7c85739e32b 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -1570,9 +1570,9 @@ static void shader_glsl_ffp_vertex_normalmatrix_uniform(const struct wined3d_con if (prog->vs.normal_matrix_location == -1) return;
- GL_EXTCALL(glUniformMatrix3fv(prog->vs.normal_matrix_location, - 1, FALSE, constants->modelview.not_blended.normal_matrix)); - checkGLcall("glUniformMatrix3fv"); + GL_EXTCALL(glUniformMatrix4fv(prog->vs.normal_matrix_location, + 1, FALSE, &constants->modelview.not_blended.normal_matrix._11)); + checkGLcall("glUniformMatrix4fv"); }
static void shader_glsl_ffp_vertex_texmatrix_uniform(const struct wined3d_context_gl *context_gl, @@ -9144,7 +9144,7 @@ static GLuint shader_glsl_generate_ffp_vertex_shader(struct shader_glsl_priv *pr
shader_addline(buffer, "uniform mat4 ffp_modelview_matrix[%u];\n", MAX_VERTEX_BLENDS); shader_addline(buffer, "uniform mat4 ffp_projection_matrix;\n"); - shader_addline(buffer, "uniform mat3 ffp_normal_matrix;\n"); + shader_addline(buffer, "uniform mat4 ffp_normal_matrix;\n"); shader_addline(buffer, "uniform mat4 ffp_texture_matrix[%u];\n", WINED3D_MAX_FFP_TEXTURES);
shader_addline(buffer, "uniform struct\n{\n"); @@ -9261,7 +9261,7 @@ static GLuint shader_glsl_generate_ffp_vertex_shader(struct shader_glsl_priv *pr if (settings->transformed) shader_addline(buffer, "normal = ffp_attrib_normal;\n"); else - shader_addline(buffer, "normal = ffp_normal_matrix * ffp_attrib_normal;\n"); + shader_addline(buffer, "normal = mat3(ffp_normal_matrix) * ffp_attrib_normal;\n"); } else { diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 3a5ac83883b..54bea64afcc 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -3545,7 +3545,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, } else { - compute_normal_matrix(matrices.not_blended.normal_matrix, + compute_normal_matrix(&matrices.not_blended.normal_matrix, device->adapter->d3d_info.wined3d_creation_flags & WINED3D_LEGACY_FFP_LIGHTING, &matrices.not_blended.modelview_matrix);
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index fb732929799..3a13045f625 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -7065,11 +7065,10 @@ static BOOL invert_matrix_3d(struct wined3d_matrix *out, const struct wined3d_ma return TRUE; }
-void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting, +void compute_normal_matrix(struct wined3d_matrix *normal_matrix, BOOL legacy_lighting, const struct wined3d_matrix *modelview) { struct wined3d_matrix mv; - unsigned int i, j;
mv = *modelview; if (legacy_lighting) @@ -7079,9 +7078,16 @@ void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting, /* Tests show that singular modelview matrices are used unchanged as normal * matrices on D3D3 and older. There seems to be no clearly consistent * behavior on newer D3D versions so always follow older ddraw behavior. */ - for (i = 0; i < 3; ++i) - for (j = 0; j < 3; ++j) - normal_matrix[i * 3 + j] = (&mv._11)[j * 4 + i]; + + normal_matrix->_11 = mv._11; + normal_matrix->_12 = mv._21; + normal_matrix->_13 = mv._31; + normal_matrix->_21 = mv._12; + normal_matrix->_22 = mv._22; + normal_matrix->_23 = mv._32; + normal_matrix->_31 = mv._13; + normal_matrix->_32 = mv._23; + normal_matrix->_33 = mv._33; }
static void wined3d_allocator_release_block(struct wined3d_allocator *allocator, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 84cf8f51f26..7de83d3b1cd 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2774,7 +2774,7 @@ struct wined3d_ffp_vs_constants struct { struct wined3d_matrix modelview_matrix; - float normal_matrix[9]; + struct wined3d_matrix normal_matrix; } not_blended; } modelview; struct wined3d_matrix projection_matrix; @@ -4722,7 +4722,7 @@ static inline void wined3d_vec4_transform(struct wined3d_vec4 *dst,
BOOL invert_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m);
-void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting, +void compute_normal_matrix(struct wined3d_matrix *normal_matrix, BOOL legacy_lighting, const struct wined3d_matrix *modelview);
static inline struct wined3d_context *context_acquire(struct wined3d_device *device,