Bug 28577

Summary: Incorrect specular highlights on backfaces
Product: Mesa Reporter: Tim Evans <t.evans>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Test code that reproduces the problem
Patch against mesa-7.8.2 that fixes this problem

Description Tim Evans 2010-06-16 17:36:48 UTC
Created attachment 36323 [details]
Test code that reproduces the problem

When rendering faces with:
 * glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
 * glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
 * glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
 * A infinite distance light.

The specular colour is applied incorrectly to backward faces. The faces show up as the correct colour when they don't have a specular highlight, but as full-intensity white when they have any specular.

Without separate specular the results are correct.

With local-viewer set to true, or with a non-infinite distance light, the results are better but still wrong. The specular highlight doesn't go to full white instantly but it's still brighter than it should be.

I'm attaching some simple code to reproduce the problem. It should show a red and green square rotating on a blue background. As the square rotates the correct specular highlight will show up on the red front face: a gradual lightening from red to pink then back to red again. The green back face instead goes instantly from green to white, then instantly back to green again.
Comment 1 Tim Evans 2010-06-16 17:41:11 UTC
In case it matters, I've reproduced this problem on Mesa 7.7.1 and 7.8.1, both on win32 with the GDI interface, compiled with Visual C++ 2008 with optimisation disabled. My machine is running Windows Vista 64.
Comment 2 Tim Evans 2010-06-17 19:42:28 UTC
Created attachment 36354 [details] [review]
Patch against mesa-7.8.2 that fixes this problem

In ss_tritmp.h, the backface specular values are copied into the vertex attrib array using SS_SPEC. SS_SPEC converts the values from float [0,1] to uint8 [0,255], but the vertex attrib array is float, and the values are used as if they were [0,1] later.  Changing the definition of SS_SPEC to COPY_4V fixes the problem for me.  Attaching a patch to that effect.
Comment 3 Brian Paul 2010-06-21 16:20:21 UTC
Thanks!  Patch committed to master with commit 1f9f650738ed5bc8e8d8eeb43234d2e969621d7f.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.