1
0
Fork 0
Univerxel/content/shaders/Main.vs

50 lines
1.4 KiB
GLSL

#version 330 core
layout(location = 0) in vec3 Position_modelspace;
layout(location = 1) in uint Material_model;
layout(location = 2) in vec3 Normal_modelspace;
out VertexData {
vec3 Position_worldspace;
flat uint Material;
vec3 FaceNormal_modelspace;
#ifdef PBR
vec3 FaceNormal_worldspace;
vec3 EyeDirection_cameraspace;
vec3 LightDirection_cameraspace;
#endif
#ifdef FOG
float Depth;
#endif
} vs;
uniform mat4 MVP;
uniform mat4 Model;
uniform mat4 View;
uniform vec3 LightInvDirection_worldspace;
uniform float FogDepth;
void main(){
gl_Position = MVP * vec4(Position_modelspace, 1);
vs.Position_worldspace = (Model * vec4(Position_modelspace,1)).xyz;
#ifdef FOG
vs.Depth = length((View * vec4(vs.Position_worldspace,1)).xyz) / FogDepth;
#endif
vs.Material = Material_model;
vs.FaceNormal_modelspace = normalize(Normal_modelspace);
#ifdef PBR
vs.FaceNormal_worldspace = normalize((Model * vec4(vs.FaceNormal_modelspace, 0)).xyz);
// Vector that goes from the vertex to the camera, in camera space.
// In camera space, the camera is at the origin (0,0,0).
vs.EyeDirection_cameraspace = vec3(0,0,0) - (View * Model * vec4(Position_modelspace,1)).xyz;
// Vector that goes from the vertex to the light, in camera space
vs.LightDirection_cameraspace = (View * vec4(LightInvDirection_worldspace,0)).xyz;
#endif
}