Hi guys, I’m implementing Blinn-Phong at the moment, doing ambience currently. I’m having a lot of trouble getting the right result!
I’m working on simple ambience using the background colour. I have diffuse working at the moment which is fine, but whenever I add in ambience, it doesn’t actually have the background colour.
This is my vertex shader code. My fragment shader code, for testing purposes is simply gl_Color = ambience; which at the moments gives me a dark gray instead of the ambient colour (the background colour is blue, so I expect to see a shade of blue).
varying float diffuse;
varying float ambience;
varying float specular;
uniform vec3 bg_colour;
void main()
{
gl_Position = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_Position / gl_Position.w;
vec3 light = vec3(3, 4, 1);
vec3 light_dir = gl_ModelViewMatrix * vec4(light, 0.0);
vec3 normal = gl_NormalMatrix * gl_Normal;
vec3 ambient_colour = bg_colour;
float ambient_intensity = 0.5;
float diffuse_intensity = 0.5;
ambience = ambient_colour * ambient_intensity;
diffuse = max(dot(normalize(normal), normalize(light_dir)), 0) * diffuse_intensity;
gl_Position = gl_ProjectionMatrix * gl_Position;
}
As you can see, I pass the background colour in from my C++ code via a uniform variable. I know the problem is something basic that I’m overlooking, but I can’t figure out what it is.
Edit: Playing around with the line “ambience = ambient_colour * ambient_intensity;” I’ve figured out that’s part of the problem. ambient_colour being of type vec3, and ambient_intensity being of type float, the result is of course going to be a scaled vec3, which of course means that ambience gets assigned ambient_colour.x, not the overall colour.
So I guess my question now is, how do I do this correctly?