52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package glshader
|
|
|
|
// Adapted from the OpenGL Superbible
|
|
|
|
var VertexShaderSource string = `
|
|
#version 330
|
|
|
|
precision mediump float;
|
|
|
|
struct Light {
|
|
vec3 position;
|
|
|
|
vec4 ambient;
|
|
vec4 diffuse;
|
|
vec4 specular;
|
|
};
|
|
|
|
uniform mat4 model; // Model
|
|
uniform mat4 camera; // View
|
|
uniform mat4 projection; // Projection
|
|
uniform Light light;
|
|
|
|
// Inputs
|
|
in vec3 vertPos;
|
|
in vec3 vertNormal;
|
|
in vec2 vertTexCoord;
|
|
|
|
// Outputs
|
|
smooth out vec3 fragNormal;
|
|
out vec2 fragTexCoord;
|
|
smooth out vec3 lightDir;
|
|
|
|
void main() {
|
|
// Get the surface normal in eye coordinates
|
|
fragNormal = mat3(transpose(inverse(model))) * vertNormal;
|
|
fragNormal = normalize(fragNormal);
|
|
|
|
// Get the vertex position in eye coordinates
|
|
vec3 position3 = vec3(model * vec4(vertPos, 1));
|
|
|
|
// Get the vector to the light source(s)
|
|
lightDir = light.position - position3;
|
|
lightDir = normalize(lightDir);
|
|
|
|
// Pass through the texture coordinates
|
|
fragTexCoord = vertTexCoord;
|
|
|
|
// Transform the geometry
|
|
gl_Position = projection * camera * vec4(position3, 1);
|
|
}
|
|
`
|