Funny days with GLSL
Currently I am working on an intro for the TUM Demoparty. Keep code small and portable seems to be tricky. I know there are issues in code between platforms like Windows and Mac OS X. But I always expected the shader language to be portable. But I never had such problems with the OpenGL Shading Language.There are two usable versions of GLSL: implicit version 1.10 and version 1.20.Both specifications have in common that no cast operator is defined. Instead the constructor is used to convert types.
GLSL cast and conversation:
int i = 100;
float x = (float)i; // Invalid cast
float y = float(i); // Valid conversions via constructor
Version 1.20 defines conversions for matrices also. A downsizing cast should take a the upper left matrix part and casting from mat4 (mat4×4) to mat3 (mat3×3) is useful when only the rotation should be applied to a vector.
Matrix conversation:
#version 120
vec3 dir = vec3(0.0, 0.0, -1.0);
dir = mat3x3(gl_ModelViewMatrix) * dir;
This works fine on my MacBook Pro, but only when I work with windows. It took me a look time to determine this problem on Mac OS X, because no warnings where generated.
Vertex Shader
#version 120
varying vec3 dir;
void main() {
#if DEBUG
dir = vec3(gl_Vertex.xyz * 0.5);
#elif CORRECT_IMPLEMENTATION
dir = mat3(gl_ModelViewMatrix) * dir;
#else
dir = mat3(
gl_ModelViewMatrix[0].xyz,
gl_ModelViewMatrix[1].xyz,
gl_ModelViewMatrix[2].xyz
) * dir;
#endif
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Fragment Shader:
varying vec3 dir;
void main() {
gl_FragColor = vec4(abs(dir), 1.0);
}
The first branch simple maps the coords. The second and third are equal on Windows. But the Mac OS X drivers are buggy.
The next two images show the results on my Mac. The bug is inside the Apple software renderer too.
I will send a bug report to Apple and NVIDIA. I am not sure who is responsible.

on December 11th, 2007 at 3:58
lol…
I will send a bug report to Apple and NVIDIA
wonder what they will say
anyways good luck
on December 11th, 2007 at 10:47
Good Luck on the Demoparty! ;-)