summaryrefslogtreecommitdiff
path: root/src/mesa/main
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2000-06-26 23:37:46 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2000-06-26 23:37:46 +0000
commitde82d063d4dfaaec06d01a51b1a5b811c61712aa (patch)
treee48b65b64d906c0c762a9b9fbf2c600a1d48d958 /src/mesa/main
parentdaf3778e86dce7c52fbf4db48f62e3e80ed73815 (diff)
updating mat ambient/emissive was broke. always compute ctx->EyeZDir
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/light.c165
-rw-r--r--src/mesa/main/light.h6
2 files changed, 102 insertions, 69 deletions
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index f7278c2c31..3e7b5a3781 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -1,4 +1,4 @@
-/* $Id: light.c,v 1.13 2000/06/19 14:35:17 keithw Exp $ */
+/* $Id: light.c,v 1.14 2000/06/26 23:37:46 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -513,9 +513,6 @@ GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
-
-
-
/*
* Check if the global material has to be updated with info that was
* associated with a vertex via glMaterial.
@@ -523,6 +520,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
@@ -530,41 +529,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 );
@@ -574,6 +594,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 );
@@ -581,8 +602,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) {
@@ -595,6 +619,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) {
@@ -605,18 +630,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 );
@@ -627,6 +641,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;
@@ -663,43 +678,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 );
@@ -710,6 +750,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 );
@@ -718,8 +759,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) {
@@ -730,8 +773,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) {
@@ -742,18 +787,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)
{
@@ -1277,45 +1310,44 @@ 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);
@@ -1337,8 +1369,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;
+ }
}
}
}
diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h
index fc1ed0be67..f5ca08f84e 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.3 2000/06/26 23:37:46 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
- * 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"),
@@ -115,7 +115,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] );