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

88 lines
2.6 KiB
GLSL
Raw Normal View History

2020-09-26 22:05:43 +00:00
#version 450 core
2020-09-27 20:25:35 +00:00
#extension GL_ARB_separate_shader_objects : enable
2020-09-26 22:05:43 +00:00
layout (constant_id = 0) const bool FOG = true;
layout (constant_id = 1) const bool PBR = true;
// FS spe
2020-12-03 18:46:47 +00:00
layout (constant_id = 8) const bool DO_CURVATURE = false;
layout (constant_id = 9) const bool CURV_DEPTH = true;
2020-09-26 22:05:43 +00:00
2020-09-29 19:28:11 +00:00
layout (binding = 0) uniform UniformBufferObject {
2020-10-14 10:59:24 +00:00
mat4 view;
mat4 proj;
2020-09-29 19:28:11 +00:00
2020-10-14 10:59:24 +00:00
vec3 lightInvDirection_worldspace;
2020-10-14 10:59:24 +00:00
vec4 fog; //color.rgb depth.a
2020-09-29 19:28:11 +00:00
} UBO;
2020-10-14 10:59:24 +00:00
layout(push_constant) uniform PushConst {
2020-09-27 20:25:35 +00:00
#ifndef INSTANCED
2020-10-14 10:59:24 +00:00
mat4 model;
2020-09-27 20:25:35 +00:00
#endif
2020-10-14 10:59:24 +00:00
vec4 sphereProj;
float curvature;
2020-09-27 20:25:35 +00:00
} 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
2020-09-26 22:05:43 +00:00
2020-09-27 20:25:35 +00:00
layout (location = 0) out VertexData {
2020-09-26 22:05:43 +00:00
vec3 Position_modelspace;
flat uint Texture;
vec3 FaceNormal_modelspace;
vec3 FaceNormal_worldspace;
vec3 EyeDirection_cameraspace;
vec3 LightDirection_cameraspace;
float Depth;
} vs;
2020-09-27 20:25:35 +00:00
void main(){
#ifndef INSTANCED
2020-10-14 10:59:24 +00:00
mat4 Model = Push.model;
2020-09-26 22:05:43 +00:00
#endif
vs.Position_modelspace = Position_modelspace;
if(DO_CURVATURE) {
2020-10-14 10:59:24 +00:00
if(Push.curvature > 0) {
vec3 Position_areaspace = Position_modelspace + Push.sphereProj.xyz;
2020-09-26 22:05:43 +00:00
vec2 sph = vec2(acos(Position_areaspace.z / length(Position_areaspace.xyz)), atan(Position_areaspace.y, Position_areaspace.x));
2020-09-27 20:25:35 +00:00
float radius = CURV_DEPTH ?
max(max(abs(Position_areaspace.x), abs(Position_areaspace.y)), abs(Position_areaspace.z)) :
2020-10-14 10:59:24 +00:00
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);
2020-09-26 22:05:43 +00:00
}
}
2020-10-14 10:59:24 +00:00
vec4 Position_cameraspace = UBO.view * Model * vec4(vs.Position_modelspace, 1);
gl_Position = UBO.proj * Position_cameraspace;
2020-09-26 22:05:43 +00:00
if(FOG) {
2020-10-14 10:59:24 +00:00
vs.Depth = length(Position_cameraspace.xyz) / UBO.fog.a;
2020-09-26 22:05:43 +00:00
}
vs.Texture = Texture_model;
vs.FaceNormal_modelspace = normalize(Normal_modelspace);
2020-09-27 20:25:35 +00:00
if(PBR) {
2020-09-26 22:05:43 +00:00
// 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
2020-10-14 10:59:24 +00:00
vs.LightDirection_cameraspace = (UBO.view * vec4(UBO.lightInvDirection_worldspace,0)).xyz;
2020-09-26 22:05:43 +00:00
}
}