feat: post-effects array parameters & add gfx.posteffects.set_array & make shadows opacity depending on clouds opacity

This commit is contained in:
MihailRis
2025-06-14 20:06:05 +03:00
parent 02a91e0b72
commit 436a89b066
14 changed files with 223 additions and 78 deletions
+9 -10
View File
@@ -1,8 +1,7 @@
uniform vec3 u_ssaoSamples[64];
int kernelSize = 16;
float radius = 0.25;
float bias = 0.025;
#param vec3 u_ssaoSamples[64]
#param int u_kernelSize = 16
#param float u_radius = 0.25
#param float u_bias = 0.025
vec4 effect() {
vec2 noiseScale = u_screenSize / 4.0;
@@ -17,9 +16,9 @@ vec4 effect() {
mat3 tbn = mat3(tangent, bitangent, normal);
float occlusion = 0.0;
for (int i = 0; i < kernelSize; i++) {
for (int i = 0; i < u_kernelSize; i++) {
vec3 samplePos = tbn * u_ssaoSamples[i];
samplePos = position + samplePos * radius;
samplePos = position + samplePos * u_radius;
vec4 offset = vec4(samplePos, 1.0);
offset = u_projection * offset;
@@ -27,10 +26,10 @@ vec4 effect() {
offset.xyz = offset.xyz * 0.5 + 0.5;
float sampleDepth = texture(u_position, offset.xy).z;
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
float rangeCheck = smoothstep(0.0, 1.0, u_radius / abs(position.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + u_bias ? 1.0 : 0.0) * rangeCheck;
}
occlusion = min(1.0, 1.05 - (occlusion / kernelSize));
occlusion = min(1.0, 1.05 - (occlusion / u_kernelSize));
float z = -position.z * 0.02;
z = max(0.0, 1.0 - z);
+13 -8
View File
@@ -1,10 +1,14 @@
#ifndef SHADOWS_GLSL_
#define SHADOWS_GLSL_
#include <constants>
uniform sampler2DShadow u_shadows[2];
uniform mat4 u_shadowsMatrix[2];
uniform float u_dayTime;
uniform int u_shadowsRes;
uniform float u_shadowsOpacity;
uniform float u_shadowsSoftness;
float calc_shadow() {
if (!u_enableShadows) {
@@ -12,24 +16,25 @@ float calc_shadow() {
}
float step = 1.0 / float(u_shadowsRes);
float s = pow(abs(cos(u_dayTime * 6.283185)), 0.5); // 2*PI precomputed
vec3 normalOffset = a_realnormal * (a_distance > 128.0 ? 0.2 : 0.04);
int shadowIdx = a_distance > 128.0 ? 1 : 0;
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
vec3 normalOffset = a_realnormal * (a_distance > 64.0 ? 0.2 : 0.04);
int shadowIdx = a_distance > 64.0 ? 1 : 0;
vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(a_modelpos.xyz + normalOffset, 1.0);
vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.0001;
projCoords.z -= 0.00001;
float shadow = 0.0;
if (dot(a_realnormal, u_sunDir) < 0.0) {
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec3 offset = vec3(x, y, -(abs(x) + abs(y))) * step;
// 5x5 kernel
for (int y = -2; y <= 2; y++) {
for (int x = -2; x <= 2; x++) {
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.1) * step * 2.0 * u_shadowsSoftness;
shadow += texture(u_shadows[shadowIdx], projCoords + offset);
}
}
shadow /= 9.0;
shadow /= 25.0;
} else {
shadow = 0.5;
}