feat: shadows in fast pipeline & improve lights mix
This commit is contained in:
+1
-1
@@ -58,5 +58,5 @@ function on_hud_open()
|
||||
|
||||
local slot = gfx.posteffects.index("core:default")
|
||||
gfx.posteffects.set_effect(slot, "ssao")
|
||||
gfx.posteffects.set_intensity(slot, 1.0)
|
||||
--gfx.posteffects.set_intensity(slot, 1.0)
|
||||
end
|
||||
|
||||
@@ -12,15 +12,16 @@ float calc_shadow() {
|
||||
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
|
||||
));
|
||||
}
|
||||
const vec3 offsets[4] = vec3[4](
|
||||
vec3(0.5, 0.5, 0.0),
|
||||
vec3(-0.5, 0.5, 0.0),
|
||||
vec3(0.5, -0.5, 0.0),
|
||||
vec3(-0.5, -0.5, 0.0)
|
||||
);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
shadow += texture(u_shadows, projCoords.xyz + offsets[i] / u_shadowsRes);
|
||||
}
|
||||
shadow /= 9;
|
||||
shadow /= 4;
|
||||
shadow = shadow * 0.5 + 0.5;
|
||||
} else {
|
||||
shadow = 0.5;
|
||||
|
||||
@@ -2,7 +2,8 @@ layout (location = 0) out vec4 f_color;
|
||||
layout (location = 1) out vec4 f_position;
|
||||
layout (location = 2) out vec4 f_normal;
|
||||
|
||||
in vec4 a_color;
|
||||
in vec4 a_torchLight;
|
||||
in vec3 a_skyLight;
|
||||
in vec2 a_texCoord;
|
||||
in float a_fog;
|
||||
in vec3 a_position;
|
||||
@@ -31,7 +32,7 @@ void main() {
|
||||
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;
|
||||
float alpha = texColor.a;
|
||||
if (u_alphaClip) {
|
||||
if (alpha < 0.2f)
|
||||
discard;
|
||||
@@ -45,8 +46,8 @@ void main() {
|
||||
else if (u_debugNormals) {
|
||||
texColor.rgb *= a_normal * 0.5 + 0.5;
|
||||
}
|
||||
f_color = a_color * texColor;
|
||||
f_color.rgb *= shadow;
|
||||
f_color = texColor;
|
||||
f_color.rgb *= min(vec3(1.0), a_torchLight.rgb + a_skyLight * shadow);
|
||||
f_color = mix(f_color, vec4(fogColor, 1.0), a_fog);
|
||||
f_color.a = alpha;
|
||||
f_position = vec4(a_position, 1.0);
|
||||
|
||||
@@ -12,7 +12,8 @@ out vec3 a_dir;
|
||||
out vec3 a_normal;
|
||||
out vec3 a_position;
|
||||
out vec3 a_realnormal;
|
||||
out vec4 a_color;
|
||||
out vec4 a_torchLight;
|
||||
out vec3 a_skyLight;
|
||||
out vec4 a_modelpos;
|
||||
|
||||
uniform mat4 u_model;
|
||||
@@ -38,13 +39,14 @@ void main() {
|
||||
|
||||
vec3 light = v_light.rgb;
|
||||
float torchlight = calc_torch_light(a_modelpos.xyz);
|
||||
light += torchlight * u_torchlightColor;
|
||||
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
|
||||
a_torchLight = vec4(pow(light + torchlight * u_torchlightColor, vec3(u_gamma)), 1.0f);
|
||||
|
||||
a_texCoord = v_texCoord;
|
||||
|
||||
a_dir = a_modelpos.xyz - u_cameraPos;
|
||||
vec3 skyLightColor = pick_sky_color(u_skybox);
|
||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*v_light.a);
|
||||
a_skyLight = skyLightColor.rgb*v_light.a;
|
||||
//a_color.rgb = max(a_color.rgb, skyLightColor.rgb*v_light.a);
|
||||
|
||||
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||
a_fog = calc_fog(a_distance / 256.0);
|
||||
|
||||
Reference in New Issue
Block a user