1
0
Fork 0
Univerxel/resource/shaders-src/Voxel.vert

87 lines
2.6 KiB
GLSL

#version 450 core
#extension GL_ARB_separate_shader_objects : enable
layout (constant_id = 0) const bool FOG = true;
layout (constant_id = 1) const bool PBR = true;
// FS spe
layout (constant_id = 5) const bool DO_CURVATURE = false;
layout (constant_id = 6) const bool CURV_DEPTH = true;
layout(push_constant) uniform PushConstants {
mat4 Proj;
mat4 View;
#ifndef INSTANCED
mat4 Model;
#endif
vec4 SphereProj;
float Curvature;
//MAYBE: extract
vec3 FogColor;
float FogDepth;
vec3 LightInvDirection_worldspace;
} Push;
layout (location = 0) in vec3 Position_modelspace;
layout (location = 1) in uint Texture_model;
layout (location = 2) in vec3 Normal_modelspace;
#ifdef INSTANCED
layout (location = 6) in mat4 Model;
#endif
layout (location = 0) out VertexData {
vec3 Position_modelspace;
flat uint Texture;
vec3 FaceNormal_modelspace;
vec3 FaceNormal_worldspace;
vec3 EyeDirection_cameraspace;
vec3 LightDirection_cameraspace;
float Depth;
} vs;
void main(){
#ifndef INSTANCED
mat4 Model = Push.Model;
#endif
vs.Position_modelspace = Position_modelspace;
if(DO_CURVATURE) {
if(Push.Curvature > 0) {
vec3 Position_areaspace = Position_modelspace + Push.SphereProj.xyz;
vec2 sph = vec2(acos(Position_areaspace.z / length(Position_areaspace.xyz)), atan(Position_areaspace.y, Position_areaspace.x));
float radius = CURV_DEPTH ?
max(max(abs(Position_areaspace.x), abs(Position_areaspace.y)), abs(Position_areaspace.z)) :
Push.SphereProj.w;
vs.Position_modelspace = mix(vs.Position_modelspace, vec3(sin(sph.x)*cos(sph.y), sin(sph.x)*sin(sph.y), cos(sph.x)) * radius - Push.SphereProj.xyz, Push.Curvature);
}
}
vec4 Position_cameraspace = Push.View * Model * vec4(vs.Position_modelspace, 1);
gl_Position = Push.Proj * Position_cameraspace;
if(FOG) {
vs.Depth = length(Position_cameraspace.xyz) / Push.FogDepth;
}
vs.Texture = Texture_model;
vs.FaceNormal_modelspace = normalize(Normal_modelspace);
if(PBR) {
// TODO: correct normal curvature
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) - Position_cameraspace.xyz;
// Vector that goes from the vertex to the light, in camera space
vs.LightDirection_cameraspace = (Push.View * vec4(Push.LightInvDirection_worldspace,0)).xyz;
}
}