Hey All,
So I want to write a simple diffuse shader for multiple lights sources (64). I obtain the light source directions and colours by doing a Median Cut on an HDR evironment map. (That part works ok and the light intensities ranges from ca. 0.008 to 12.). The directions and colours are stored as two arrays, which are sent to the vertex shader.
In the vertex shader I do a simple N.L and sum the values, like this:
#define NUM_LIGHTS 64
uniform vec3 lightPos[ NUM_LIGHTS ]; // Stored in World Space
uniform vec3 lightCol[ NUM_LIGHTS ];
uniform float multiplier;
varying vec3 diffuse;
void main()
{
vec3 normal = normalize( gl_NormalMatrix * gl_Normal );
diffuse = vec3(0.);
for( int i = 0; i < NUM_LIGHTS; i++ )
{
vec3 ecLightDir = vec3( gl_ModelViewMatrix * vec4(lightPos[i], 1.) );
float intensity = max( 0., dot(normal, normalize(ecLightDir))) * multiplier;
diffuse += lightCol[i] * intensity;
}
gl_Position = ftransform();
}
In the fragment shader I just multiply material colour with this diffuse term. This should be correct?
However, the result does not resemble a reference shader that uses a simple cube mapped irradience map. The bright parts are too bright and the more shadowy parts are too dark, and thus fail to achieve that smooth diffuse look from image-based lighting.
I can post some screen shots if you like…
Is there something I’m missing? Any ideas?