Also, the last line in lightingLight() should be removed:
change to
There's no reason why light sources should specify ambient light, and if they do they do so erroneously. Go to a hardware store, pick up a light bulb, and ask the store owner how much ambient, diffuse and specular light it produces, exactly. Or tell her that you bought a light bulb the previous week that produces too much specular light, but not enough ambient...
These are idiotic idiosyncracies of opengl that are best ignored. A light source produces light. That's it. Period.
On the same vein, remove the seventh input parameter in lightingLight(), from,
Code: Select all
void lightingLight(
in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
in vec4 lightDiffuse, in vec4 lightSpecular, in float lightAtt,
in vec4 diffusemap, in vec4 specmap, in float shininess,
in vec4 ambientProduct,
inout vec3 diffuse, inout vec3 specular, inout vec3 ambient)
{
to
Code: Select all
void lightingLight(
in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
in vec4 lightDiffuse, in float lightAtt,
in vec4 diffusemap, in vec4 specmap, in float shininess,
in vec4 ambientProduct,
inout vec3 diffuse, inout vec3 specular, inout vec3 ambient)
{
and change the second last line (now the last), from,
Code: Select all
specular += pow(clamp(RdotL,0.0,1.0), shininessMap(shininess,specmap)) * lightSpecular.rgb * lightAtt;
to
Code: Select all
specular += pow(clamp(RdotL,0.0,1.0), shininessMap(shininess,specmap)) * lightDiffuse.rgb * lightAtt;
Then change the macro,
Code: Select all
#define lighting(name, lightno_gl, lightno_tex) \
void name( \
in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection, \
in vec4 diffusemap, in vec4 specmap, \
inout vec3 diffuse, inout vec3 specular, inout vec3 ambient) \
{ \
lightingLight( \
normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
gl_FrontLightProduct[lightno_gl].diffuse, \
gl_FrontLightProduct[lightno_gl].specular, \
gl_TexCoord[lightno_tex].w, \
diffusemap, specmap, gl_FrontMaterial.shininess, \
gl_FrontLightProduct[lightno_gl].ambient, \
diffuse, specular, ambient); \
}
to
Code: Select all
#define lighting(name, lightno_gl, lightno_tex) \
void name( \
in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection, \
in vec4 diffusemap, in vec4 specmap, \
inout vec3 diffuse, inout vec3 specular, inout vec3 ambient) \
{ \
lightingLight( \
normalize(gl_TexCoord[lightno_tex].xyz), normal, vnormal, eye, reflection, \
gl_FrontLightProduct[lightno_gl].diffuse, \
gl_TexCoord[lightno_tex].w, \
diffusemap, specmap, gl_FrontMaterial.shininess, \
gl_FrontLightProduct[lightno_gl].ambient, \
diffuse, specular, ambient); \
}
EDIT:
And it keeps looking better and better.
EDIT2:
The last parameter passed to lightingLight() is now not needed. Changing from
Code: Select all
void lightingLight(
in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
in vec4 lightDiffuse, in float lightAtt,
in vec4 diffusemap, in vec4 specmap, in float shininess,
in vec4 ambientProduct,
inout vec3 diffuse, inout vec3 specular, inout vec3 ambient)
{
to
Code: Select all
void lightingLight(
in vec3 light, in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection,
in vec4 lightDiffuse, in float lightAtt,
in vec4 diffusemap, in vec4 specmap, in float shininess,
in vec4 ambientProduct,
inout vec3 diffuse, inout vec3 specular)
{
which means that the last parameter the macro passes is a goner, from,
to
which implies that the last parameter in the function the macro instantiates is dead. Change from,
Code: Select all
#define lighting(name, lightno_gl, lightno_tex) \
void name( \
in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection, \
in vec4 diffusemap, in vec4 specmap, \
inout vec3 diffuse, inout vec3 specular, inout vec3 ambient) \
{ \
to
Code: Select all
#define lighting(name, lightno_gl, lightno_tex) \
void name( \
in vec3 normal, in vec3 vnormal, in vec3 eye, in vec3 reflection, \
in vec4 diffusemap, in vec4 specmap, \
inout vec3 diffuse, inout vec3 specular) \
{ \
And the above results in that we don't need that last parameter in the calls in main(). Change from,
Code: Select all
// Do lighting for every active light
if (light_enabled[0] != 0)
lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular, ambient);
if (light_enabled[1] != 0)
lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular, ambient);
to
Code: Select all
// Do lighting for every active light
if (light_enabled[0] != 0)
lighting0(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
if (light_enabled[1] != 0)
lighting1(normal, vnormal, eye, reflection, diffusemap, specmap, diffuse, specular);
EDIT3:
Hell; even the ugliest ship we got is starting to look, well, not "decent", but at least it looks like something and not nothing...
Too bad I didn't take a "before" screenshot. But, you see?, the specular texture of this course is probably white; but in any case, whereas before it only speculated on the bright side, it didn't much on the dark side, so you couldn't even recognize its being made of any material we're familiar with. Now the environmental reflections are independent of direct light, and it speculates from all directions, so it looks like entirely chrome-plated.
Well, not entirely, because something that's white in specular can't be anything but black in diffuse; but this abomination has specular+diffuse>1 sins all over the place. Whoever textured it should be hanged from the toes for a week, then shot. But I digress; the shader keeps looking better.