summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2000-06-27 15:04:20 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2000-06-27 15:04:20 +0000
commit83670c38ca2637586fb5d6d460141bc54b6d7420 (patch)
tree46622f522f46ff555cb5bba9b0e4618c91de35fd
parent3222cd1397dd946cfbaf71169361d1aa74fcd70b (diff)
backport of lighting and material bug fixes from 3.3
-rw-r--r--src/mesa/main/context.c17
-rw-r--r--src/mesa/main/light.c177
-rw-r--r--src/mesa/main/light.h82
3 files changed, 142 insertions, 134 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 368f11cd1f..6a030f2e1f 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1,10 +1,10 @@
-/* $Id: context.c,v 1.18.2.10 2000/06/23 20:29:15 brianp Exp $ */
+/* $Id: context.c,v 1.18.2.11 2000/06/27 15:04:20 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.1
+ * Version: 3.2
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -2434,14 +2434,9 @@ void gl_update_state( GLcontext *ctx )
ctx->NeedEyeNormals = GL_FALSE;
if (ctx->Light.Enabled) {
- if (ctx->Light.Flags & LIGHT_POSITIONAL) {
- /* Need length for attenuation */
- if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
- ctx->NeedEyeCoords = GL_TRUE;
- } else if (ctx->Light.NeedVertices) {
- /* Need angle for spot calculations */
- if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_ANGLE_PRESERVING))
- ctx->NeedEyeCoords = GL_TRUE;
+ if ((ctx->Light.Flags & LIGHT_POSITIONAL) || ctx->Light.NeedVertices){
+ /* Need length for attenuation or need angle for spotlights */
+ ctx->NeedEyeCoords = GL_TRUE;
}
ctx->NeedEyeNormals = ctx->NeedEyeCoords;
}
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index afc81ede70..f154a9dc82 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -1,10 +1,10 @@
-/* $Id: light.c,v 1.8.2.2 2000/06/24 14:14:29 keithw Exp $ */
+/* $Id: light.c,v 1.8.2.3 2000/06/27 15:04:20 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.1
+ * Version: 3.2
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -418,6 +418,8 @@ GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
* glBegin/glEnd either by calling glMaterial() or by calling glColor()
* when GL_COLOR_MATERIAL is enabled.
*
+ * src[0] is front material, src[1] is back material
+ *
* KW: Added code here to keep the precomputed variables uptodate.
* This means we can use the faster shade functions when using
* GL_COLOR_MATERIAL, and we can also now use the precomputed
@@ -425,41 +427,62 @@ GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
* the cost of doing this here.
*/
void gl_update_material( GLcontext *ctx,
- struct gl_material *src,
+ const struct gl_material src[2],
GLuint bitmask )
{
struct gl_light *light, *list = &ctx->Light.EnabledList;
- GLfloat tmp[4];
if (ctx->Light.ColorMaterialEnabled)
bitmask &= ~ctx->Light.ColorMaterialBitmask;
if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
- fprintf(stderr, "gl_update_material, mask %x\n", bitmask);
+ fprintf(stderr, "gl_update_material, mask 0x%x\n", bitmask);
if (!bitmask)
return;
+ /* update material emission */
+ if (bitmask & FRONT_EMISSION_BIT) {
+ struct gl_material *mat = &ctx->Light.Material[0];
+ COPY_4FV( mat->Emission, src[0].Emission );
+ }
+ if (bitmask & BACK_EMISSION_BIT) {
+ struct gl_material *mat = &ctx->Light.Material[1];
+ COPY_4FV( mat->Emission, src[1].Emission );
+ }
+
+ /* update material ambience */
if (bitmask & FRONT_AMBIENT_BIT) {
struct gl_material *mat = &ctx->Light.Material[0];
- SUB_3V( tmp, src[0].Ambient, mat->Ambient );
- ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp);
+ COPY_4FV( mat->Ambient, src[0].Ambient );
foreach (light, list) {
- ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
+ SCALE_3V( light->MatAmbient[0], light->Ambient, src[0].Ambient);
}
- COPY_4FV( mat->Ambient, src[0].Ambient );
}
if (bitmask & BACK_AMBIENT_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
- SUB_3V( tmp, src[1].Ambient, mat->Ambient );
- ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp);
+ COPY_4FV( mat->Ambient, src[1].Ambient );
foreach (light, list) {
- ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
+ SCALE_3V( light->MatAmbient[1], light->Ambient, src[1].Ambient);
}
- COPY_4FV( mat->Ambient, src[1].Ambient );
}
+
+ /* update BaseColor = emission + scene's ambience * material's ambience */
+ if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) {
+ struct gl_material *mat = &ctx->Light.Material[0];
+ COPY_3V( ctx->Light.BaseColor[0], mat->Emission );
+ ACC_SCALE_3V( ctx->Light.BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient );
+ }
+ if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) {
+ struct gl_material *mat = &ctx->Light.Material[1];
+ COPY_3V( ctx->Light.BaseColor[1], mat->Emission );
+ ACC_SCALE_3V( ctx->Light.BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient );
+ }
+
+ /* update material diffuse values */
if (bitmask & FRONT_DIFFUSE_BIT) {
struct gl_material *mat = &ctx->Light.Material[0];
+ GLfloat tmp[4];
SUB_3V( tmp, src[0].Diffuse, mat->Diffuse );
foreach (light, list) {
ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
@@ -469,6 +492,7 @@ void gl_update_material( GLcontext *ctx,
}
if (bitmask & BACK_DIFFUSE_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
+ GLfloat tmp[4];
SUB_3V( tmp, src[1].Diffuse, mat->Diffuse );
foreach (light, list) {
ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
@@ -476,8 +500,11 @@ void gl_update_material( GLcontext *ctx,
COPY_4FV( mat->Diffuse, src[1].Diffuse );
FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[1], mat->Diffuse[3]);
}
+
+ /* update material specular values */
if (bitmask & FRONT_SPECULAR_BIT) {
struct gl_material *mat = &ctx->Light.Material[0];
+ GLfloat tmp[4];
SUB_3V( tmp, src[0].Specular, mat->Specular );
foreach (light, list) {
if (light->Flags & LIGHT_SPECULAR) {
@@ -490,6 +517,7 @@ void gl_update_material( GLcontext *ctx,
}
if (bitmask & BACK_SPECULAR_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
+ GLfloat tmp[4];
SUB_3V( tmp, src[1].Specular, mat->Specular );
foreach (light, list) {
if (light->Flags & LIGHT_SPECULAR) {
@@ -500,18 +528,7 @@ void gl_update_material( GLcontext *ctx,
}
COPY_4FV( mat->Specular, src[1].Specular );
}
- if (bitmask & FRONT_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- SUB_3V( tmp, src[0].Emission, mat->Emission );
- ACC_3V( ctx->Light.BaseColor[0], tmp );
- COPY_4FV( mat->Emission, src[0].Emission );
- }
- if (bitmask & BACK_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- SUB_3V( tmp, src[1].Emission, mat->Emission );
- ACC_3V( ctx->Light.BaseColor[1], tmp );
- COPY_4FV( mat->Emission, src[1].Emission );
- }
+
if (bitmask & FRONT_SHININESS_BIT) {
GLfloat shininess = ctx->Light.Material[0].Shininess = src[0].Shininess;
gl_compute_shine_table( ctx, 0, shininess );
@@ -522,6 +539,7 @@ void gl_update_material( GLcontext *ctx,
gl_compute_shine_table( ctx, 1, shininess );
gl_compute_shine_table( ctx, 3, shininess * .5 );
}
+
if (bitmask & FRONT_INDEXES_BIT) {
ctx->Light.Material[0].AmbientIndex = src[0].AmbientIndex;
ctx->Light.Material[0].DiffuseIndex = src[0].DiffuseIndex;
@@ -558,43 +576,68 @@ void gl_update_material( GLcontext *ctx,
-
-
+/*
+ * Update the current materials from the given rgba color
+ * according to the bitmask in ColorMaterialBitmask, which is
+ * set by glColorMaterial().
+ */
void gl_update_color_material( GLcontext *ctx,
const GLubyte rgba[4] )
{
struct gl_light *light, *list = &ctx->Light.EnabledList;
GLuint bitmask = ctx->Light.ColorMaterialBitmask;
- GLfloat tmp[4], color[4];
+ GLfloat color[4];
UBYTE_RGBA_TO_FLOAT_RGBA( color, rgba );
-
+
if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
- fprintf(stderr, "gl_update_color_material, mask %x\n", bitmask);
+ fprintf(stderr, "gl_update_color_material, mask 0x%x\n", bitmask);
-
+ /* update emissive colors */
+ if (bitmask & FRONT_EMISSION_BIT) {
+ struct gl_material *mat = &ctx->Light.Material[0];
+ COPY_4FV( mat->Emission, color );
+ }
+
+ if (bitmask & BACK_EMISSION_BIT) {
+ struct gl_material *mat = &ctx->Light.Material[1];
+ COPY_4FV( mat->Emission, color );
+ }
+
+ /* update light->MatAmbient = light's ambient * material's ambient */
if (bitmask & FRONT_AMBIENT_BIT) {
struct gl_material *mat = &ctx->Light.Material[0];
- SUB_3V( tmp, color, mat->Ambient );
- ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp);
foreach (light, list) {
- ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
+ SCALE_3V( light->MatAmbient[0], light->Ambient, color);
}
COPY_4FV( mat->Ambient, color );
}
if (bitmask & BACK_AMBIENT_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
- SUB_3V( tmp, color, mat->Ambient );
- ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp);
foreach (light, list) {
- ACC_SCALE_3V( ctx->Light.BaseColor[1], light->Ambient, tmp );
+ SCALE_3V( light->MatAmbient[1], light->Ambient, color);
}
COPY_4FV( mat->Ambient, color );
}
+ /* update BaseColor = emission + scene's ambience * material's ambience */
+ if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) {
+ struct gl_material *mat = &ctx->Light.Material[0];
+ COPY_3V( ctx->Light.BaseColor[0], mat->Emission );
+ ACC_SCALE_3V( ctx->Light.BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient );
+ }
+
+ if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) {
+ struct gl_material *mat = &ctx->Light.Material[1];
+ COPY_3V( ctx->Light.BaseColor[1], mat->Emission );
+ ACC_SCALE_3V( ctx->Light.BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient );
+ }
+
+ /* update light->MatDiffuse = light's diffuse * material's diffuse */
if (bitmask & FRONT_DIFFUSE_BIT) {
struct gl_material *mat = &ctx->Light.Material[0];
+ GLfloat tmp[4];
SUB_3V( tmp, color, mat->Diffuse );
foreach (light, list) {
ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
@@ -605,6 +648,7 @@ void gl_update_color_material( GLcontext *ctx,
if (bitmask & BACK_DIFFUSE_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
+ GLfloat tmp[4];
SUB_3V( tmp, color, mat->Diffuse );
foreach (light, list) {
ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
@@ -613,8 +657,10 @@ void gl_update_color_material( GLcontext *ctx,
FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[1], mat->Diffuse[3]);
}
+ /* update light->MatSpecular = light's specular * material's specular */
if (bitmask & FRONT_SPECULAR_BIT) {
struct gl_material *mat = &ctx->Light.Material[0];
+ GLfloat tmp[4];
SUB_3V( tmp, color, mat->Specular );
foreach (light, list) {
if (light->Flags & LIGHT_SPECULAR) {
@@ -625,8 +671,10 @@ void gl_update_color_material( GLcontext *ctx,
}
COPY_4FV( mat->Specular, color );
}
+
if (bitmask & BACK_SPECULAR_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
+ GLfloat tmp[4];
SUB_3V( tmp, color, mat->Specular );
foreach (light, list) {
if (light->Flags & LIGHT_SPECULAR) {
@@ -637,18 +685,6 @@ void gl_update_color_material( GLcontext *ctx,
}
COPY_4FV( mat->Specular, color );
}
- if (bitmask & FRONT_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- SUB_3V( tmp, color, mat->Emission );
- ACC_3V( ctx->Light.BaseColor[0], tmp );
- COPY_4FV( mat->Emission, color );
- }
- if (bitmask & BACK_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- SUB_3V( tmp, color, mat->Emission );
- ACC_3V( ctx->Light.BaseColor[1], tmp );
- COPY_4FV( mat->Emission, color );
- }
if (0)
{
@@ -674,7 +710,6 @@ void gl_update_color_material( GLcontext *ctx,
-
void gl_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode )
{
GLuint bitmask;
@@ -1115,52 +1150,53 @@ void gl_update_lighting( GLcontext *ctx )
}
}
+
+
/* Need to seriously restrict the circumstances under which these
* calc's are performed.
*/
void gl_compute_light_positions( GLcontext *ctx )
{
struct gl_light *light;
-
- if (ctx->Light.NeedVertices && !ctx->Light.Model.LocalViewer) {
- GLfloat eye_z[3] = { 0, 0, 1 };
- if (!ctx->NeedEyeCoords) {
- TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m );
- } else {
+
+ if (1 /*ctx->Light.NeedVertices && !ctx->Light.Model.LocalViewer*/) {
+ static const GLfloat eye_z[3] = { 0, 0, 1 };
+ if (ctx->NeedEyeCoords) {
COPY_3V( ctx->EyeZDir, eye_z );
}
+ else {
+ TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m );
+ }
}
foreach (light, &ctx->Light.EnabledList) {
- if (!ctx->NeedEyeCoords) {
+ if (ctx->NeedEyeCoords) {
+ COPY_4FV( light->Position, light->EyePosition );
+ }
+ else {
TRANSFORM_POINT( light->Position, ctx->ModelView.inv,
light->EyePosition );
- } else {
- COPY_4FV( light->Position, light->EyePosition );
}
- if (!(light->Flags & LIGHT_POSITIONAL))
- {
+ if (!(light->Flags & LIGHT_POSITIONAL)) {
/* VP (VP) = Normalize( Position ) */
COPY_3V( light->VP_inf_norm, light->Position );
NORMALIZE_3FV( light->VP_inf_norm );
- if (!ctx->Light.Model.LocalViewer)
- {
+ if (!ctx->Light.Model.LocalViewer) {
/* h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
ADD_3V( light->h_inf_norm, light->VP_inf_norm, ctx->EyeZDir);
NORMALIZE_3FV( light->h_inf_norm );
}
-
light->VP_inf_spot_attenuation = 1.0;
}
- if (light->Flags & LIGHT_SPOT)
- {
+ if (light->Flags & LIGHT_SPOT) {
if (ctx->NeedEyeNormals) {
COPY_3V( light->NormDirection, light->EyeDirection );
- } else {
+ }
+ else {
TRANSFORM_NORMAL( light->NormDirection,
light->EyeDirection,
ctx->ModelView.m);
@@ -1182,8 +1218,9 @@ void gl_compute_light_positions( GLcontext *ctx )
(light->SpotExpTable[k][0] +
(x-k)*light->SpotExpTable[k][1]);
}
- else
+ else {
light->VP_inf_spot_attenuation = 0;
+ }
}
}
}
@@ -1191,8 +1228,6 @@ void gl_compute_light_positions( GLcontext *ctx )
-
-
void gl_update_normal_transform( GLcontext *ctx )
{
GLuint new_flag = 0;
diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h
index fc1ed0be67..006bead070 100644
--- a/src/mesa/main/light.h
+++ b/src/mesa/main/light.h
@@ -1,10 +1,10 @@
-/* $Id: light.h,v 1.2 1999/11/11 01:22:27 brianp Exp $ */
+/* $Id: light.h,v 1.1.1.1.2.1 2000/06/27 15:04:20 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.3
+ * Version: 3.2
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -25,6 +25,9 @@
*/
+
+
+
#ifndef LIGHT_H
#define LIGHT_H
@@ -39,69 +42,44 @@ struct gl_shine_tab {
};
-extern void
-_mesa_ShadeModel( GLenum mode );
-
-extern void
-_mesa_ColorMaterial( GLenum face, GLenum mode );
-
-extern void
-_mesa_Lightf( GLenum light, GLenum pname, GLfloat param );
-
-extern void
-_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params );
+extern void gl_ShadeModel( GLcontext *ctx, GLenum mode );
-extern void
-_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params );
+extern void gl_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode );
-extern void
-_mesa_Lighti( GLenum light, GLenum pname, GLint param );
+extern void gl_Lightfv( GLcontext *ctx,
+ GLenum light, GLenum pname, const GLfloat *params,
+ GLint nparams );
-extern void
-_mesa_LightModelf( GLenum pname, GLfloat param );
+extern void gl_LightModelfv( GLcontext *ctx,
+ GLenum pname, const GLfloat *params );
-extern void
-_mesa_LightModelfv( GLenum pname, const GLfloat *params );
-extern void
-_mesa_LightModeli( GLenum pname, GLint param );
-
-extern void
-_mesa_LightModeliv( GLenum pname, const GLint *params );
-
-extern void
-_mesa_Materialf( GLenum face, GLenum pname, GLfloat param );
-
-extern void
-_mesa_Materialfv( GLenum face, GLenum pname, const GLfloat *params );
+extern GLuint gl_material_bitmask( GLcontext *ctx,
+ GLenum face, GLenum pname,
+ GLuint legal,
+ const char * );
-extern void
-_mesa_Materiali( GLenum face, GLenum pname, GLint param );
+extern void gl_set_material( GLcontext *ctx, GLuint bitmask,
+ const GLfloat *params);
-extern void
-_mesa_Materialiv( GLenum face, GLenum pname, const GLint *params );
+extern void gl_Materialfv( GLcontext *ctx,
+ GLenum face, GLenum pname, const GLfloat *params );
-extern void
-_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params );
-extern void
-_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params );
-extern void
-_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params );
+extern void gl_GetLightfv( GLcontext *ctx,
+ GLenum light, GLenum pname, GLfloat *params );
-extern void
-_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params );
+extern void gl_GetLightiv( GLcontext *ctx,
+ GLenum light, GLenum pname, GLint *params );
+extern void gl_GetMaterialfv( GLcontext *ctx,
+ GLenum face, GLenum pname, GLfloat *params );
-extern GLuint gl_material_bitmask( GLcontext *ctx,
- GLenum face, GLenum pname,
- GLuint legal,
- const char * );
+extern void gl_GetMaterialiv( GLcontext *ctx,
+ GLenum face, GLenum pname, GLint *params );
-extern void gl_set_material( GLcontext *ctx, GLuint bitmask,
- const GLfloat *params);
extern void gl_compute_spot_exp_table( struct gl_light *l );
@@ -115,7 +93,7 @@ extern void gl_compute_light_positions( GLcontext *ctx );
extern void gl_update_normal_transform( GLcontext *ctx );
extern void gl_update_material( GLcontext *ctx,
- struct gl_material *m,
+ const struct gl_material src[2],
GLuint bitmask );
extern void gl_update_color_material( GLcontext *ctx, const GLubyte rgba[4] );