#version 460 layout(packed, binding=0) buffer model_list { mat4 models[]; }; in vec3 in_vertex; in vec3 in_normal; in vec2 in_texcoord; uniform mat4 mvp; uniform float factor; out vec2 f_texcoord; out vec3 light; void main(void) { // gl_Position = mvp * models[gl_InstanceID] * vec4(in_vertex + (clamp(factor, 0, 1) * in_normal), 1.0); gl_Position = mvp * models[gl_InstanceID] * vec4(in_vertex, 1.0); // This ONLY works because we have a sphere! vec3 normal = (models[gl_InstanceID] * vec4(in_normal, 0)).xyz; // This is the diffuse color AND the ambient color // They don't have to be the same vec3 material = vec3(1, 1, 1); vec3 light_position = vec3(0, 0, (10 * factor)); vec3 Direction = -1 * (gl_Position.xyz - light_position); // Light direction vec3 I = vec3(1, 1, 1); // Light Intensity vec3 R = material * I * clamp(dot(normalize(Direction), normalize(normal)), 0, 1); // vec3 Direction2 = vec3(10, -5, 3); // Light direction // vec3 I2 = vec3(.3, .3, .9); // Light Intensity // If you don't use clamp, then you can do this instead // float dp = dot(normalize(Direction2), normalize(normal)); // if(dp < 0) // dp = 0; // vec3 R2 = material * I2 * dp; vec3 A = material * vec3(.2, .2, .2); light = R + A; f_texcoord = in_texcoord; }