Mesa (master): glsl: Fix gl_NormalScale.

Brian Paul brianp at kemper.freedesktop.org
Mon Dec 4 04:14:05 UTC 2017


Module: Mesa
Branch: master
Commit: c3ee464d7aa170225b5ec23b53a7f8d07663d428
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c3ee464d7aa170225b5ec23b53a7f8d07663d428

Author: Fabian Bieler <fabianbieler at fastmail.fm>
Date:   Thu Nov 23 13:48:00 2017 -0700

glsl: Fix gl_NormalScale.

GLSL shaders can access the normal scale factor with the built-in
gl_NormalScale.  Mesa's modelspace lighting optimization uses a different
normal scale factor than defined in the spec.  We have to take care not
to use this factor for gl_NormalScale.

Mesa already defines two seperate states: state.normalScale and
state.internal.normalScale.  The first is used by the glsl compiler
while the later is used by the fixed function T&L pipeline.  Previously
the only difference was some component swizzling.  With this commit
state.normalScale always uses the normal scale factor for eyespace
lighting.

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/main/light.c             | 3 +++
 src/mesa/main/mtypes.h            | 3 ++-
 src/mesa/program/prog_statevars.c | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index f52ed8ed25..67faf8a145 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -1032,6 +1032,7 @@ static void
 update_modelview_scale( struct gl_context *ctx )
 {
    ctx->_ModelViewInvScale = 1.0F;
+   ctx->_ModelViewInvScaleEyespace = 1.0F;
    if (!_math_matrix_is_length_preserving(ctx->ModelviewMatrixStack.Top)) {
       const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
       GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
@@ -1040,6 +1041,7 @@ update_modelview_scale( struct gl_context *ctx )
 	 ctx->_ModelViewInvScale = 1.0f / sqrtf(f);
       else
 	 ctx->_ModelViewInvScale = sqrtf(f);
+      ctx->_ModelViewInvScaleEyespace = 1.0f / sqrtf(f);
    }
 }
 
@@ -1216,4 +1218,5 @@ _mesa_init_lighting( struct gl_context *ctx )
    ctx->_NeedEyeCoords = GL_FALSE;
    ctx->_ForceEyeCoords = GL_FALSE;
    ctx->_ModelViewInvScale = 1.0;
+   ctx->_ModelViewInvScaleEyespace = 1.0;
 }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 0e8a05359a..b478f6158e 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -4961,7 +4961,8 @@ struct gl_context
    /** \name Derived state */
    GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
    GLfloat _EyeZDir[3];
-   GLfloat _ModelViewInvScale;
+   GLfloat _ModelViewInvScale; /* may be for model- or eyespace lighting */
+   GLfloat _ModelViewInvScaleEyespace; /* always factor defined in spec */
    GLboolean _NeedEyeCoords;
    GLboolean _ForceEyeCoords; 
 
diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
index 91178e395c..b69895c47f 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -422,7 +422,7 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
       return;
 
    case STATE_NORMAL_SCALE:
-      ASSIGN_4V(value, ctx->_ModelViewInvScale, 0, 0, 1);
+      ASSIGN_4V(value, ctx->_ModelViewInvScaleEyespace, 0, 0, 1);
       return;
 
    case STATE_INTERNAL:




More information about the mesa-commit mailing list