mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 23:41:50 +00:00
refactor shaders
This commit is contained in:
parent
36e5ff2472
commit
30a0b81680
9 changed files with 128 additions and 88 deletions
32
res/shaders/lib/shadows.glsl
Normal file
32
res/shaders/lib/shadows.glsl
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef SHADOWS_GLSL_
|
||||
#define SHADOWS_GLSL_
|
||||
|
||||
float calc_shadow() {
|
||||
float shadow = 1.0;
|
||||
if (u_enableShadows) {
|
||||
vec4 mpos = u_shadowsMatrix * vec4(a_modelpos.xyz + a_realnormal * 0.08, 1.0);
|
||||
vec3 projCoords = mpos.xyz / mpos.w;
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
projCoords.z -= 0.0001;
|
||||
|
||||
shadow = 0.0;
|
||||
|
||||
if (dot(a_realnormal, u_sunDir) < 0.0) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
shadow += texture(u_shadows, projCoords.xyz + vec3(
|
||||
x * (1.0 / u_shadowsRes),
|
||||
y * (1.0 / u_shadowsRes), 0.0
|
||||
));
|
||||
}
|
||||
}
|
||||
shadow /= 9;
|
||||
shadow = shadow * 0.5 + 0.5;
|
||||
} else {
|
||||
shadow = 0.5;
|
||||
}
|
||||
}
|
||||
return shadow;
|
||||
}
|
||||
|
||||
#endif // SHADOWS_GLSL_
|
||||
Loading…
Add table
Add a link
Reference in a new issue