// Pseudo-instancingvec3 position = vec3( dot(gl_MultiTexCoord5, gl_Vertex), dot(gl_MultiTexCoord6, gl_Vertex), dot(gl_MultiTexCoord7, gl_Vertex));gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);#if CALC_EYE_VECTOR vec3 eyePos = CAM_POS.xyz - gl_Vertex.xyz; vec4 eyeVector = vec4(eyePos, dot(eyePos, eyePos)); eyeVector.xyz *= inversesqrt(eyeVector.w); // Normalized vector & distance^2 VAR_fogCoord = getFogCoord(eyeVector.w); lightingPassVaryings(TANGENT, BINORMAL, gl_Normal, eyeVector.xyz);#else VAR_fogCoord = getFogCoord(lengthSQ3f(gl_Vertex, CAM_POS)); lightingPassVaryings(TANGENT, BINORMAL, gl_Normal);#endif
mat3 tangentBasis = mat3(tangent, binormal, normal);vec4 lightVector;lightVector.xyz = LIGHT_POS * tangentBasis;lightVector.w = clamp(lightVector.z * 8.0, 0.0, 1.0);VAR_lightVector = lightVector;#if CALC_EYE_VECTOR eyeVector.xyz = eyeVector.xyz * tangentBasis; #if PARALLAX_MAPPING VAR_eyeVector = half3(eyeVector.xyz); #endif #if SPECULAR_MAPPING VAR_lightHalfAngle = half3(normalize(eyeVector.xyz + lightVector.xyz)); #endif#endif
1) I'm always confused by OpenGL lighting - I fully understand object space (being the space you build your model in) If you want a stationary light (like the sun or a street light) you set the camera view then the glLight position, this gives you a gl_LightSource.position in world space (i.e. multiplied by the modelview) So how do you specify a light position (or direction) in object space, per object but have the scene lit consistently when each object is transformed by different modelView matrices?
2) When you say "gl_LightSource.position.xyz will be the light direction in world-space" is this just a terminology thing and world space is the same as eye space ? (OpenGL docs seem to state that world space is a non-openGL concept being the model transforms without the view)
3) "For performance reasons, you should use a custom uniform that defines the light direction in object space" can you elaborate? Is it use of a uniform over a built in gl uniform like gl_LightSource.position ?
I assume you work out the camera pos in object space by applying the current inverse modelview matrix to a vector of 0,0,0 ?
Do you calculate your tangents/binormals in code or take them from model files?
I wonder if it's my tangents that are causing a problem. You don't have access to a model with tangents that you know render correctly do you? (That way I could eliminate tangent creation as an issue)
I bet it's some trivial error, these things usually are!