refactor shaders
This commit is contained in:
+4
-28
@@ -12,7 +12,7 @@ in vec3 a_realnormal;
|
||||
in vec4 a_modelpos;
|
||||
|
||||
uniform sampler2D u_texture0;
|
||||
uniform samplerCube u_cubemap;
|
||||
uniform samplerCube u_skybox;
|
||||
uniform sampler2DShadow u_shadows;
|
||||
uniform vec3 u_sunDir;
|
||||
uniform int u_shadowsRes;
|
||||
@@ -25,35 +25,11 @@ uniform bool u_enableShadows;
|
||||
|
||||
uniform mat4 u_shadowsMatrix;
|
||||
|
||||
const int BLUR_SAMPLES = 6;
|
||||
#include <shadows>
|
||||
|
||||
void main() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
|
||||
float shadow = calc_shadow();
|
||||
vec3 fogColor = texture(u_skybox, a_dir).rgb;
|
||||
vec4 texColor = texture(u_texture0, a_texCoord);
|
||||
float alpha = a_color.a * texColor.a;
|
||||
if (u_alphaClip) {
|
||||
|
||||
Reference in New Issue
Block a user