33 lines
809 B
GLSL
33 lines
809 B
GLSL
|
#version 330 core
|
||
|
|
||
|
// input attributes, different for each vertex
|
||
|
in vec3 position;
|
||
|
|
||
|
// uniform variables, same for all vertices
|
||
|
uniform mat4 projection;
|
||
|
uniform mat4 modelView;
|
||
|
|
||
|
// vertex shader outputs
|
||
|
out vec3 objectPosition;
|
||
|
out vec3 viewPosition;
|
||
|
out vec3 viewNormal;
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
// forward position in object/model space to fragment shader
|
||
|
objectPosition = position;
|
||
|
|
||
|
// compute and forward position in view space to fragment shader
|
||
|
vec4 vp = modelView * vec4(position, 1.0);
|
||
|
viewPosition = vp.xyz;
|
||
|
|
||
|
// compute normal matrix
|
||
|
mat3 normalMatrix = transpose(inverse(mat3(modelView)));
|
||
|
|
||
|
// compute and forward view space normal (unit sphere => object space position = normal)
|
||
|
viewNormal = normalize(normalMatrix * position);
|
||
|
|
||
|
// transform and project position
|
||
|
gl_Position = projection * vp;
|
||
|
}
|