feat: post-effects array parameters & add gfx.posteffects.set_array & make shadows opacity depending on clouds opacity
This commit is contained in:
+22
-4
@@ -1,3 +1,25 @@
|
||||
local function configure_SSAO()
|
||||
local slot = gfx.posteffects.index("core:default")
|
||||
gfx.posteffects.set_effect(slot, "ssao")
|
||||
gfx.posteffects.set_intensity(slot, 1.0)
|
||||
|
||||
-- Generating random SSAO samples
|
||||
local buffer = Bytearray(0)
|
||||
for i = 0, 63 do
|
||||
local x = math.random() * 2.0 - 1.0
|
||||
local y = math.random() * 2.0 - 1.0
|
||||
local z = math.random()
|
||||
local len = math.sqrt(x * x + y * y + z * z)
|
||||
if len > 0 then
|
||||
x = x / len
|
||||
y = y / len
|
||||
z = z / len
|
||||
end
|
||||
Bytearray.append(buffer, byteutil.pack("fff", x, y, z))
|
||||
end
|
||||
gfx.posteffects.set_array(slot, "u_ssaoSamples", Bytearray_as_string(buffer))
|
||||
end
|
||||
|
||||
function on_hud_open()
|
||||
input.add_callback("player.pick", function ()
|
||||
if hud.is_paused() or hud.is_inventory_open() then
|
||||
@@ -55,8 +77,4 @@ function on_hud_open()
|
||||
player.set_vel(pid, 0, 1, 0)
|
||||
end
|
||||
end)
|
||||
|
||||
local slot = gfx.posteffects.index("core:default")
|
||||
gfx.posteffects.set_effect(slot, "ssao")
|
||||
gfx.posteffects.set_intensity(slot, 1.0)
|
||||
end
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user