0
votes
        #version 150 core
in vec3 pos;
in vec3 vshade;
in vec3 normal;
out vec3 cshade;
out float shadescale_o;
out vec3 v_o;
out vec3 locallight_o;
out vec3 n;
uniform float pscale;
uniform mat3 rotation_projection;
uniform vec3 objcentre_to_eye_projected;
uniform vec3 light_in_object_coords;
uniform vec3 view_in_object_coords;
void main()
{
//do it all without homogenous co-ords
    vec3 transpos;
    vec3 h,v;   
    vec3 locallight=light_in_object_coords-pos; //subtract because of light direction
    transpos.xyz=rotation_projection*pos.xyz+objcentre_to_eye_projected;
    gl_Position.w= transpos.z;
    transpos.z-=pscale;
    gl_Position.xyz=transpos;
    v=view_in_object_coords+pos;
    n=normal;
    v_o=v;
    v=normalize(v);
    locallight_o=locallight;
    locallight=normalize(locallight);
    h=v-locallight; //light direction shines from source to object
    h=normalize(h);
    shadescale_o= dot(h,normal); //inward normal
    if (shadescale_o<0)
        shadescale_o=0;
    shadescale_o*=shadescale_o;
    shadescale_o*=shadescale_o;

    shadescale_o= dot(locallight,normal);//diffuse

    cshade=vshade;//*(shadescale_o);

}

This is my shader code that is fed into a program as a string and basically just displays a cube with a local light.

I need to know how to implement ambient lighting through this code, so as to light up the whole cube (and anything else in the scene).

It's based on an openGL framework and everything displayed is effected by this code... yes it is homework!!

1
Is vshade your ambient light color? Does using cshade=vshade; produce a single color? - Tugrul Ates

1 Answers

1
votes

You're calculating the diffuse factors for each color anyway (at least I assume that is correct, it's your homework) so you can just add a constant ambient factor as well.