From bb1b1b151e28b87071cdc064af648f8c7d26b1e9 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 20 Jul 2010 17:34:04 +0100 Subject: [PATCH] cogl-material: Don't map the shininess value to [0,1] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In OpenGL the 'shininess' lighting parameter is floating point value limited to the range 0.0→128.0. This number is used to affect the size of the specular highlight. Cogl materials used to only accept a number between 0.0 and 1.0 which then gets multiplied by 128.0 before sending to GL. I think the assumption was that this is just a weird GL quirk so we don't expose it. However the value is used as an exponent to raise the attenuation to a power so there is no conceptual limit to the value. This removes the mapping and changes some of the documentation. http://bugzilla.clutter-project.org/show_bug.cgi?id=2222 --- clutter/cogl/cogl/cogl-material-opengl.c | 6 ++---- clutter/cogl/cogl/cogl-material.c | 4 +++- clutter/cogl/cogl/cogl-material.h | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/clutter/cogl/cogl/cogl-material-opengl.c b/clutter/cogl/cogl/cogl-material-opengl.c index d00d17e65..d1e52f204 100644 --- a/clutter/cogl/cogl/cogl-material-opengl.c +++ b/clutter/cogl/cogl/cogl-material-opengl.c @@ -507,14 +507,12 @@ _cogl_material_flush_color_blend_alpha_depth_state ( CoglMaterialLightingState *lighting_state = &authority->big_state->lighting_state; - /* FIXME - we only need to set these if lighting is enabled... */ - GLfloat shininess = lighting_state->shininess * 128.0f; - GE (glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, lighting_state->ambient)); GE (glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, lighting_state->diffuse)); GE (glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, lighting_state->specular)); GE (glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, lighting_state->emission)); - GE (glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, &shininess)); + GE (glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, + &lighting_state->shininess)); } if (materials_difference & COGL_MATERIAL_STATE_BLEND) diff --git a/clutter/cogl/cogl/cogl-material.c b/clutter/cogl/cogl/cogl-material.c index 981837228..c5896252d 100644 --- a/clutter/cogl/cogl/cogl-material.c +++ b/clutter/cogl/cogl/cogl-material.c @@ -239,6 +239,8 @@ _cogl_material_init_default_material (void) lighting_state->emission[2] = 0; lighting_state->emission[3] = 1.0; + lighting_state->shininess = 0.0f; + /* Use the same defaults as the GL spec... */ alpha_state->alpha_func = COGL_MATERIAL_ALPHA_FUNC_ALWAYS; alpha_state->alpha_func_reference = 0.0; @@ -3620,7 +3622,7 @@ cogl_material_set_shininess (CoglMaterial *material, g_return_if_fail (cogl_is_material (material)); - if (shininess < 0.0 || shininess > 1.0) + if (shininess < 0.0) { g_warning ("Out of range shininess %f supplied for material\n", shininess); diff --git a/clutter/cogl/cogl/cogl-material.h b/clutter/cogl/cogl/cogl-material.h index b72ca3273..989c8cedc 100644 --- a/clutter/cogl/cogl/cogl-material.h +++ b/clutter/cogl/cogl/cogl-material.h @@ -387,11 +387,12 @@ cogl_material_get_specular (CoglMaterial *material, /** * cogl_material_set_shininess: * @material: A #CoglMaterial object - * @shininess: The desired shininess; range: [0.0, 1.0] + * @shininess: The desired shininess; must be >= 0.0 * - * Sets the materials shininess, in the standard OpenGL lighting model, - * which determines how specular highlights are calculated. A higher - * @shininess will produce smaller brigher highlights. + * Sets the shininess of the material, in the standard OpenGL lighting + * model, which determines the size of the specular highlights. A + * higher @shininess will produce smaller highlights which makes the + * object appear more shiny. * * The default value is 0.0 *