mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
Introduce shadow mapping using a dedicated depth framebuffer and shader. The block fragment shader now performs percentage-closer filtering (PCF) with Poisson disk sampling and random rotation for soft shadows. The vertex shader outputs light-space coordinates. A new depth shader pair handles rendering from the light's perspective, discarding transparent fragments. The renderer sets up the light projection based on the camera position and sun direction, and applies the shadow factor to diffuse lighting. Day/night cycle can now be toggled off in the world server thread.
75 lines
1.6 KiB
GLSL
75 lines
1.6 KiB
GLSL
#version 460
|
|
|
|
layout (location = 0) in vec3 pos;
|
|
layout (location = 1) in vec2 texCoord;
|
|
layout (location = 2) in float layer;
|
|
layout (location = 3) in vec3 aNormal;
|
|
out vec2 tc;
|
|
out vec3 normal;
|
|
out vec3 vert_pos;
|
|
flat out int tex_layer;
|
|
out vec4 FragPosLightSpace;
|
|
|
|
mat4 buildRotateX(float rad);
|
|
mat4 buildRotateY(float rad);
|
|
mat4 buildRotateZ(float rad);
|
|
mat4 buildTranslate(float x, float y, float z);
|
|
|
|
uniform mat4 mv_matrix;
|
|
uniform mat4 proj_matrix;
|
|
uniform mat4 norm_matrix;
|
|
uniform mat4 lightSpaceMatrix;
|
|
|
|
void main(void) {
|
|
vec4 viewPos = mv_matrix * vec4(pos, 1.0);
|
|
|
|
vert_pos = pos;
|
|
|
|
tc = texCoord;
|
|
|
|
tex_layer = int(layer);
|
|
|
|
normal = mat3(norm_matrix) * aNormal;
|
|
FragPosLightSpace = lightSpaceMatrix * vec4(pos, 1.0);
|
|
gl_Position = proj_matrix * viewPos;
|
|
}
|
|
|
|
mat4 buildTranslate(float x, float y, float z) {
|
|
mat4 trans = mat4(
|
|
1.0, 0.0, 0.0, 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
0.0, 0.0, 1.0, 0.0,
|
|
x, y, z, 1.0
|
|
);
|
|
return trans;
|
|
}
|
|
|
|
mat4 buildRotateX(float rad) {
|
|
mat4 xrot = mat4(
|
|
1.0, 0.0, 0.0, 0.0,
|
|
0.0, cos(rad), -sin(rad), 0.0,
|
|
0.0, sin(rad), cos(rad), 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
return xrot;
|
|
}
|
|
|
|
mat4 buildRotateY(float rad) {
|
|
mat4 yrot = mat4(
|
|
cos(rad), 0.0, sin(rad), 0.0,
|
|
0.0, 1.0, 0.0, 0.0,
|
|
-sin(rad), 0.0, cos(rad), 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
return yrot;
|
|
}
|
|
|
|
mat4 buildRotateZ(float rad) {
|
|
mat4 zrot = mat4(
|
|
cos(rad), -sin(rad), 0.0, 0.0,
|
|
sin(rad), cos(rad), 0.0, 0.0,
|
|
0.0, 0.0,1.0 , 0.0,
|
|
0.0, 0.0, 0.0, 1.0
|
|
);
|
|
return zrot;
|
|
} |