1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Various changes, fixes and features

This commit is contained in:
Gefüllte Taubenbrust 2024-10-27 21:36:40 +01:00
parent b6c099073f
commit 4b88a32c1c
17 changed files with 409 additions and 261 deletions

View file

@ -584,6 +584,11 @@ shadow_soft_radius (Soft shadow radius) float 5.0 1.0 15.0
# Requires: shaders, enable_dynamic_shadows, opengl
shadow_sky_body_orbit_tilt (Sky Body Orbit Tilt) float 0.0 -60.0 60.0
# Tint sunlight during sunrise/sunset.
#
# Requires: shaders, enable_dynamic_shadows, opengl
enable_sun_tint (Tinted sunlight) bool false
[**Post Processing]
# Enables the post processing pipeline.
@ -620,7 +625,7 @@ exposure_compensation (Exposure compensation) float 0.0 -1.0 1.0
# Default: 1.6
#
# Requires: shaders, enable_post_processing, tone_mapping
gamma (Gamma) float 1.6 1.0 5.0
secondstage_gamma (Gamma) float 1.6 1.0 5.0
# Apply ASL CDL color grading to make brighter colors warmer and darker colors cooler.
#
@ -654,6 +659,11 @@ enable_bloom (Enable Bloom) bool false
# Requires: shaders, enable_post_processing, enable_bloom
enable_volumetric_lighting (Volumetric Lighting) bool false
# Make volumetrics weaker against closer objects to emulate physical volumetrics.
#
# Requires: shaders, enable_post_processing, enable_bloom, enable_volumetric_lighting
enable_volumetric_depth_attenuation (Volumetric Depth Attenuation) bool false
[**Other Effects]
# Makes the color of light fog more saturated.

View file

@ -8,7 +8,7 @@ varying mediump vec2 varTexCoord;
void main (void)
{
vec2 uv = varTexCoord;
vec2 uv = varTexCoord.st;
//texture sampling rate
float step = 1.0 / mapSize;
@ -20,19 +20,17 @@ void main (void)
float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r;
float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
float l = texture2D(normalTexture, vec2(uv.x - step, uv.y )).r;
float c = texture2D(normalTexture, vec2(uv.x , uv.y )).r;
float AO = 50.0 * (clamp(t - c, -0.001, 0.001) + clamp(b - c, -0.001, 0.001) + clamp(r - c, -0.001, 0.001) + clamp(l - c, -0.001, 0.001));
float dX = 4.0 * (l - r);
float dY = 4.0 * (t - b);
vec3 bump = normalize(vec3 (dX, dY, 0.1));
float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
vec4 bump = vec4 (normalize(vec3 (dX, dY, 0.1)),1.0);
float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0;
vec4 base = texture2D(baseTexture, uv).rgba;
vec3 L = normalize(vec3(0.0, 0.0, 1.0));
vec3 L = normalize(vec3(0.0, 0.75, 1.0));
float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0);
float diffuse = dot(yawVec, bump);
float diffuse = dot(yawVec, bump.xyz);
vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular + AO) * base.rgb;
vec4 col = vec4(color, base.a);
vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular) * base.rgb;
vec4 col = vec4(color.rgb, base.a);
col *= varColor;
gl_FragColor = vec4(col.rgb, base.a);
}
}

View file

@ -40,6 +40,8 @@ uniform float animationTimer;
varying float perspective_factor;
#endif
uniform vec2 windowSize;
uniform float fov;
varying vec3 vNormal;
varying vec3 vPosition;
@ -98,6 +100,36 @@ vec3 gnoise(vec3 p){
);
}
float snoise(vec3 p)
{
vec3 a = floor(p);
vec3 d = p - a;
d = d * d * (3.0 - 2.0 * d);
vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
vec4 k1 = perm(b.xyxy);
vec4 k2 = perm(k1.xyxy + b.zzww);
vec4 c = k2 + a.zzzz;
vec4 k3 = perm(c);
vec4 k4 = perm(c + 1.0);
vec4 o1 = fract(k3 * (1.0 / 41.0));
vec4 o2 = fract(k4 * (1.0 / 41.0));
vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
return o4.y * d.y + o4.x * (1.0 - d.y);
}
vec3 hnoise(vec3 p) {
vec3 g = gnoise(p);
float s = snoise(p);
g *= 3.0 / (1.0 + exp(-16.0 * (s - 0.5))) - 1.5;
return g;
}
vec2 wave_noise(vec3 p, float off) {
return (gnoise(p + vec3(0.0, 0.0, off)) * 0.4 + gnoise(2.0 * p + vec3(0.0, off, off)) * 0.2 + gnoise(3.0 * p + vec3(0.0, off, off)) * 0.225 + gnoise(4.0 * p + vec3(-off, off, 0.0)) * 0.2).xz;
}
@ -123,7 +155,7 @@ float mtsmoothstep(in float edge0, in float edge1, in float x)
float shadowCutoff(float x) {
#if defined(ENABLE_TRANSLUCENT_FOLIAGE) && MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES
return mtsmoothstep(0.0, 0.002, x);
return mtsmoothstep(0.0, 3.0 / f_shadowfar, x);
#else
return step(0.0, x);
#endif
@ -415,8 +447,26 @@ float getShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance)
}
#endif
#endif
#if (defined(ENABLE_BUMPMAPS) && !defined(MATERIAL_LIQUID))
//This is mostly a placeholder and probably should use proper textures eventually...
vec3 getBumpMap(vec2 uv) {
vec2 dr = vec2(0.25) * texelSize0;
// Sample the texture to then compute the gradient
float fx0y0 = texture2D(baseTexture, uv).r;
float fx1y0 = texture2D(baseTexture, uv + vec2(dr.x, 0.0)).r;
float fx0y1 = texture2D(baseTexture, uv + vec2(0.0, dr.y)).r;
vec2 gradient = 0.1 * vec2((fx1y0 - fx0y0) / dr.x, (fx0y1 - fx0y0) / dr.y) + 0.05 * gnoise(vec3(2.0 * uv / texelSize0, 0.0)).xy;
// Compute a set of orthonormal basis vectors representing the node's surface plane.
vec3 orth1 = normalize(cross(vNormal, mix(vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, -1.0), step(0.9, abs(vNormal.y)))));
vec3 orth2 = normalize(cross(vNormal, orth1));
// The normal is computed using the partial derivatives along the texture space x and y axes.
// These axes in world space are assumed to be parallel to the basis vectors we defined before.
return orth1 * gradient.x + orth2 * gradient.y;
}
#endif
#endif
void main(void)
@ -444,19 +494,15 @@ void main(void)
// Fragment normal, can differ from vNormal which is derived from vertex normals.
vec3 fNormal = vNormal;
vec3 viewVec = normalize(worldPosition + cameraOffset - cameraPosition);
#if ((defined(ENABLE_DYNAMIC_SHADOWS) && defined(ENABLE_BUMPMAPS)) && !defined(MATERIAL_LIQUID))
vec2 dr = vec2(0.25) * texelSize0;
// Sample the texture to then compute the gradient
float fx0y0 = texture2D(baseTexture, uv).r;
float fx1y0 = texture2D(baseTexture, uv + vec2(dr.x, 0.0)).r;
float fx0y1 = texture2D(baseTexture, uv + vec2(0.0, dr.y)).r;
vec2 gradient = 0.1 * vec2((fx1y0 - fx0y0) / dr.x, (fx0y1 - fx0y0) / dr.y) + 0.05 * gnoise(vec3(2.0 * uv / texelSize0, 0.0)).xy;
// Compute a set of orthogonal basis vectors representing the node's surface plane.
vec3 orth1 = normalize(cross(vNormal, mix(vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, -1.0), step(0.9, abs(vNormal.y)))));
vec3 orth2 = normalize(cross(vNormal, orth1));
// The normal is computed using the partial derivatives along the texture space x and y axes.
// These axes in world space are assumed to be parallel to the basis vectors we defined before.
fNormal = normalize(vNormal + orth1 * gradient.x + orth2 * gradient.y);
vec3 bump_normal = getBumpMap(uv);
// When applied to all blocks, these bump maps produce irritating Moiré effects.
// So we hide the bump maps when close up.
float moire_factor = abs(dot(vNormal, viewVec));
bump_normal *= mtsmoothstep(0.4 * moire_factor, 0.2 * moire_factor, length(eyeVec) * fov / windowSize.x);
fNormal = normalize(vNormal + bump_normal);
float adj_cosLight = max(1e-5, dot(fNormal, -v_LightDirection));
#else
float adj_cosLight = cosLight;
@ -526,8 +572,6 @@ void main(void)
vec3 reflect_ray = -normalize(v_LightDirection - fNormal * dot(v_LightDirection, fNormal) * 2.0);
vec3 viewVec = normalize(worldPosition + cameraOffset - cameraPosition);
// Water reflections
#if (defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS))
@ -548,7 +592,7 @@ void main(void)
reflect_ray = -normalize(v_LightDirection - fNormal * dot(v_LightDirection, fNormal) * 2.0);
float fresnel_factor = dot(fNormal, viewVec);
float brightness_factor = 1.0 - adjusted_night_ratio;
float brightness_factor = (1.0 - adjusted_night_ratio) / base.a;
// A little trig hack. We go from the dot product of viewVec and normal to the dot product of viewVec and tangent to apply a fresnel effect.
fresnel_factor = clamp(pow(1.0 - fresnel_factor * fresnel_factor, 8.0), 0.0, 1.0) * 0.8 + 0.2;
@ -557,10 +601,12 @@ void main(void)
// Sky reflection
col.rgb += reflection_color * pow(fresnel_factor, 2.0) * 0.5 * brightness_factor;
vec3 water_reflect_color = 12.0 * sunTint * dayLight * fresnel_factor * mtsmoothstep(0.85, 0.9, pow(clamp(dot(reflect_ray, viewVec), 0.0, 1.0), 32.0)) * max(1.0 - shadow_uncorrected, 0.0);
// This line exists to prevent ridiculously bright reflection colors.
water_reflect_color /= clamp(max(water_reflect_color.r, max(water_reflect_color.g, water_reflect_color.b)) * 0.375, 1.0, 400.0);
// We clip the reflection color if it gets too bright
vec3 water_reflect_color = 6.0 * sunTint * dayLight * fresnel_factor * mtsmoothstep(0.85, 0.9, pow(clamp(dot(reflect_ray, viewVec), 0.0, 1.0), 32.0)) * max(1.0 - shadow_uncorrected, 0.0);
water_reflect_color /= max(0.4 * length(water_reflect_color), 1.0);
// Sun reflection
col.rgb += water_reflect_color * f_adj_shadow_strength * brightness_factor;
#endif
@ -580,7 +626,7 @@ void main(void)
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES) && defined(ENABLE_TRANSLUCENT_FOLIAGE)
// Simulate translucent foliage.
col.rgb += 4.0 * dayLight * base.rgb * normalize(base.rgb * varColor.rgb * varColor.rgb) * f_adj_shadow_strength * pow(max(-dot(v_LightDirection, viewVec), 0.0), 4.0) * max(1.0 - shadow_uncorrected, 0.0);
col.rgb += 4.0 * sunTint * dayLight * base.rgb * normalize(base.rgb * varColor.rgb * varColor.rgb) * f_adj_shadow_strength * pow(max(-dot(v_LightDirection, viewVec), 0.0), 4.0) * max(1.0 - shadow_uncorrected, 0.0);
#endif
}
#endif

View file

@ -54,6 +54,8 @@ uniform float xyPerspectiveBias0;
uniform float xyPerspectiveBias1;
uniform float zPerspectiveBias;
uniform vec3 beta_r0_l;
#ifdef ENABLE_DYNAMIC_SHADOWS
vec4 getRelativePosition(in vec4 position)
@ -146,19 +148,17 @@ float snoise(vec3 p)
#endif
#ifdef ENABLE_TINTED_SUNLIGHT
vec3 getDirectLightScatteringAtGround(vec3 v_LightDirection)
{
// Based on talk at 2002 Game Developers Conference by Naty Hoffman and Arcot J. Preetham
const float beta_r0 = 1e-5; // Rayleigh scattering beta
// These factors are calculated based on expected value of scattering factor of 1e-5
// for Nitrogen at 532nm (green), 2e25 molecules/m3 in atmosphere
const vec3 beta_r0_l = vec3(3.3362176e-01, 8.75378289198826e-01, 1.95342379700656) * beta_r0; // wavelength-dependent scattering
const float atmosphere_height = 15000.; // height of the atmosphere in meters
// sun/moon light at the ground level, after going through the atmosphere
return exp(-beta_r0_l * atmosphere_height / (1e-5 - dot(v_LightDirection, vec3(0., 1., 0.))));
return exp(-beta_r0_l * beta_r0 * atmosphere_height / (1e-5 - dot(v_LightDirection, vec3(0., 1., 0.))));
}
#endif
void main(void)
{
@ -280,7 +280,9 @@ void main(void)
adj_shadow_strength = f_shadow_strength *
mtsmoothstep(0.21, 0.26, f_timeofday) *
(1.0 - mtsmoothstep(0.743, 0.793, f_timeofday));
#ifdef ENABLE_TINTED_SUNLIGHT
sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), min(1.0, 4.0 * adj_shadow_strength));
#endif
}
}
#endif

View file

@ -432,7 +432,7 @@ void main(void)
// calculate fragment color from components:
col.rgb =
adjusted_night_ratio * col.rgb + // artificial light
(1.0 - adjusted_night_ratio) * ( // natural light
sunTint * (1.0 - adjusted_night_ratio) * ( // natural light
col.rgb * (1.0 - shadow_int * (1.0 - shadow_color)) + // filtered texture color
dayLight * shadow_color * shadow_int); // reflected filtered sunlight/moonlight
}

View file

@ -12,6 +12,14 @@ struct ExposureParams {
float compensationFactor;
};
uniform vec3 cdl_slope;
uniform vec3 cdl_offset;
uniform vec3 cdl_power;
uniform float vignette_dark;
uniform float vignette_bright;
uniform float vignette_power;
uniform sampler2D rendered;
uniform sampler2D bloom;
@ -148,7 +156,7 @@ void main(void)
{
#ifdef ENABLE_VIGNETTE
color.rgb *= 0.8 * pow(1.0 - length(uv - vec2(0.5)) * 1.4, 0.9) + 0.3;
color.rgb *= (vignette_bright - vignette_dark) * (1.0 - pow(length(uv - vec2(0.5)) * 1.4, vignette_power)) + vignette_dark;
#endif
#if ENABLE_TONE_MAPPING
@ -157,13 +165,7 @@ void main(void)
#ifdef ENABLE_COLOR_GRADING
// ASC CDL color grading
const vec3 slope = vec3(1.2, 1.0, 0.8);
const vec3 power = vec3(1.25, 1.0, 0.9);
// Filter out blue pixels, because the color grading tends to wash them out.
float blue_factor = clamp((color.b - max(color.r, color.g)) / max(0.01, min(color.r, color.g)), 0.0, 1.0);
color.rgb = mix(color.rgb, pow(color.rgb * slope, power), 1.);
color.rgb = mix(color.rgb, pow(max(color.rgb * cdl_slope + cdl_offset, 0.0), cdl_power), 1.);
#endif
color.rgb = applySaturation(color.rgb, saturation);
}

View file

@ -24,6 +24,8 @@ varying mediump vec2 varTexCoord;
centroid varying vec2 varTexCoord;
#endif
uniform vec3 beta_r0_l;
const float far = 1000.;
float mapDepth(float depth)
{
@ -46,9 +48,16 @@ float sampleVolumetricLight(vec2 uv, vec3 lightVec, float rawDepth)
if (min(samplepos.x, samplepos.y) > 0. && max(samplepos.x, samplepos.y) < 1.)
result += texture2D(depthmap, samplepos).r < 1. ? 0.0 : 1.0;
}
#ifdef VOLUMETRIC_DEPTH_ATTENUATION
// We use the depth map to approximate the effect of depth on the light intensity.
// The exponent was chosen based on aesthetic preference.
// To make this phsyically accurate, the brightness here should scale linearly with depth,
// but this would make the godrays either too faint or too strong in many cases.
return result / samples * pow(texture2D(depthmap, uv).r, 128.0);
#else
return result / samples;
#endif
}
vec3 getDirectLightScatteringAtGround(vec3 v_LightDirection)
@ -56,13 +65,10 @@ vec3 getDirectLightScatteringAtGround(vec3 v_LightDirection)
// Based on talk at 2002 Game Developers Conference by Naty Hoffman and Arcot J. Preetham
const float beta_r0 = 1e-5; // Rayleigh scattering beta
// These factors are calculated based on expected value of scattering factor of 1e-5
// for Nitrogen at 532nm (green), 2e25 molecules/m3 in atmosphere
const vec3 beta_r0_l = vec3(3.3362176e-01, 8.75378289198826e-01, 1.95342379700656) * beta_r0; // wavelength-dependent scattering
const float atmosphere_height = 15000.; // height of the atmosphere in meters
// sun/moon light at the ground level, after going through the atmosphere
return exp(-beta_r0_l * atmosphere_height / (1e-5 - dot(v_LightDirection, vec3(0., 1., 0.))));
return exp(-beta_r0_l * beta_r0 * atmosphere_height / (1e-5 - dot(v_LightDirection, vec3(0., 1., 0.))));
}
vec3 applyVolumetricLight(vec3 color, vec2 uv, float rawDepth)

View file

@ -8706,6 +8706,21 @@ child will follow movement and rotation of that bone.
* Currently, bloom `intensity` and `strength_factor` affect volumetric
lighting `strength` and vice versa. This behavior is to be changed
in the future, do not rely on it.
* `beta_r0`: the scattering coefficient that controls the tint of sunlight during sunrise and sunset.
* Defaults to { x = 3.3362176e-01, y = 8.75378289198826e-01, z = 1.95342379700656} which is physically accurate.
* This may be used to create effects like differently colored sunsets on alien planets.
* Setting all components to zero effectively disables tinted sunlight.
* `vignette`: is a table that controls the vignette post-processing effect.
* This has no effect on clients who have the "Vignette" effects disabled.
* `dark`: brightness of the vignette's darkest part (default: `0.3`)
* `bright`: brightness of the vignette's brightest part (default: `1.1`)
* `power`: the higher this is set, the more the vignette "retreats" to the edges of the screen (default: `1.1`)
* `cdl`: is a table that controls the ASL CDL color grading effect.
* This has no effect on clients who have the "Color grading" effect disabled.
* The output color follows the equation: `out = pow(in*slope+offset, power)`
* `slope`: "Tints" the scene, affects brighter colors more (default: `{x=1.2, y=1.0, z=0.8}`)
* `offset`: This can be used to brighten or darken the scene (default: `{x=0.0, y=0.0, z=0.0}`)
* `power`: Tints mostly the darker parts of the scene (default: `{x=1.25, y=1.0, z=0.9}`)
* `get_lighting()`: returns the current state of lighting for the player.
* Result is a table with the same fields as `light_definition` in `set_lighting`.

View file

@ -53,8 +53,7 @@ Clouds::Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc,
m_material.FogEnable = true;
m_material.AntiAliasing = video::EAAM_SIMPLE;
if (m_enable_shaders) {
bool shaded_clouds = g_settings->getBool("soft_clouds") && g_settings->getBool("enable_dynamic_shadows");
auto sid = ssrc->getShader(shaded_clouds ? "soft_clouds" : "cloud_shader", TILE_MATERIAL_ALPHA);
auto sid = ssrc->getShader("cloud_shader", TILE_MATERIAL_ALPHA);
m_material.MaterialType = ssrc->getShaderInfo(sid).material;
} else {
m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@ -226,210 +225,137 @@ void Clouds::updateMesh()
v3f pos(p0.X, m_params.height * BS, p0.Y);
if (shaded_clouds_enabled) {
bool neighbours[4] = {false, false, false, false};
if (INAREA(xi - 1, zi, m_cloud_radius_i))
neighbours[0] = grid[GETINDEX(xi - 1, zi, m_cloud_radius_i)];
if (INAREA(xi, zi - 1, m_cloud_radius_i))
neighbours[1] = grid[GETINDEX(xi, zi - 1, m_cloud_radius_i)];
if (INAREA(xi + 1, zi, m_cloud_radius_i))
neighbours[2] = grid[GETINDEX(xi + 1, zi, m_cloud_radius_i)];
if (INAREA(xi, zi + 1, m_cloud_radius_i))
neighbours[3] = grid[GETINDEX(xi, zi + 1, m_cloud_radius_i)];
video::S3DVertex v[4] = {
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
};
video::S3DVertex v[32];
v[ 0].Pos = core::vector3df( -rx, ry, -rz);
v[ 1].Pos = core::vector3df(-0.75 * rx, ry, -rz);
v[ 2].Pos = core::vector3df( 0.75 * rx, ry, -rz);
v[ 3].Pos = core::vector3df( rx, ry, -rz);
v[ 4].Pos = core::vector3df( -rx, ry, -0.75 * rz);
v[ 5].Pos = core::vector3df(-0.75 * rx, ry, -0.75 * rz);
v[ 6].Pos = core::vector3df( 0.75 * rx, ry, -0.75 * rz);
v[ 7].Pos = core::vector3df( rx, ry, -0.75 * rz);
v[ 8].Pos = core::vector3df( -rx, ry, 0.75 * rz);
v[ 9].Pos = core::vector3df(-0.75 * rx, ry, 0.75 * rz);
v[10].Pos = core::vector3df( 0.75 * rx, ry, 0.75 * rz);
v[11].Pos = core::vector3df( rx, ry, 0.75 * rz);
v[12].Pos = core::vector3df( -rx, ry, rz);
v[13].Pos = core::vector3df(-0.75 * rx, ry, rz);
v[14].Pos = core::vector3df( 0.75 * rx, ry, rz);
v[15].Pos = core::vector3df( rx, ry, rz);
// These normals are intentionally left unnormalized
if (neighbours[0]) {
v[ 0].Normal.X -= 1.0;
v[ 4].Normal.X -= 1.0;
v[ 8].Normal.X -= 1.0;
v[12].Normal.X -= 1.0;
}
if (neighbours[1]) {
v[0].Normal.Z -= 1.0;
v[1].Normal.Z -= 1.0;
v[2].Normal.Z -= 1.0;
v[3].Normal.Z -= 1.0;
}
if (neighbours[2]) {
v[ 3].Normal.X += 1.0;
v[ 7].Normal.X += 1.0;
v[11].Normal.X += 1.0;
v[15].Normal.X += 1.0;
}
if (neighbours[3]) {
v[12].Normal.Z += 1.0;
v[13].Normal.Z += 1.0;
v[14].Normal.Z += 1.0;
v[15].Normal.Z += 1.0;
}
for (int i = 0; i < 16; ++i) {
v[i + 32] = v[i];
v[i + 32].Pos.Y = -ry;
v[i].Normal = core::vector3df(0.0, 1.0, 0.0);
v[i + 32].Normal = core::vector3df(0.0, -1.0, 0.0);
for (u32 i = 0; i < num_faces_to_draw; i++)
{
switch (i)
{
case 0: // top
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(0, 1, 0);
}
v[0].Pos.set(-rx, ry, -rz);
v[1].Pos.set(-rx, ry, rz);
v[2].Pos.set(rx, ry, rz);
v[3].Pos.set(rx, ry, -rz);
break;
case 1: // back
if (INAREA(xi, zi - 1, m_cloud_radius_i)) {
u32 j = GETINDEX(xi, zi - 1, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(0, 0, -1);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_1;
vertex.Normal.set(0, 0, -1);
}
}
v[0].Pos.set(-rx, ry, -rz);
v[1].Pos.set(rx, ry, -rz);
v[2].Pos.set(rx, 0, -rz);
v[3].Pos.set(-rx, 0, -rz);
break;
case 2: //right
if (INAREA(xi + 1, zi, m_cloud_radius_i)) {
u32 j = GETINDEX(xi + 1, zi, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(1, 0, 0);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_2;
vertex.Normal.set(1, 0, 0);
}
}
v[0].Pos.set(rx, ry, -rz);
v[1].Pos.set(rx, ry, rz);
v[2].Pos.set(rx, 0, rz);
v[3].Pos.set(rx, 0, -rz);
break;
case 3: // front
if (INAREA(xi, zi + 1, m_cloud_radius_i)) {
u32 j = GETINDEX(xi, zi + 1, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(0, 0, -1);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_1;
vertex.Normal.set(0, 0, -1);
}
}
v[0].Pos.set(rx, ry, rz);
v[1].Pos.set(-rx, ry, rz);
v[2].Pos.set(-rx, 0, rz);
v[3].Pos.set(rx, 0, rz);
break;
case 4: // left
if (INAREA(xi - 1, zi, m_cloud_radius_i)) {
u32 j = GETINDEX(xi - 1, zi, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(-1, 0, 0);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_2;
vertex.Normal.set(-1, 0, 0);
}
}
v[0].Pos.set(-rx, ry, rz);
v[1].Pos.set(-rx, ry, -rz);
v[2].Pos.set(-rx, 0, -rz);
v[3].Pos.set(-rx, 0, rz);
break;
case 5: // bottom
for (video::S3DVertex& vertex : v) {
vertex.Color = c_bottom;
vertex.Normal.set(0, -1, 0);
}
v[0].Pos.set(rx, 0, rz);
v[1].Pos.set(-rx, 0, rz);
v[2].Pos.set(-rx, 0, -rz);
v[3].Pos.set(rx, 0, -rz);
break;
}
for (video::S3DVertex& vertex : v) {
vertex.Color = shadow.toSColor();
vertex.Pos += pos;
}
//top
}
else {
video::S3DVertex v[4] = {
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
};
for (u32 i = 0; i < num_faces_to_draw; i++)
{
switch (i)
{
case 0: // top
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(0, 1, 0);
}
v[0].Pos.set(-rx, ry, -rz);
v[1].Pos.set(-rx, ry, rz);
v[2].Pos.set(rx, ry, rz);
v[3].Pos.set(rx, ry, -rz);
break;
case 1: // back
if (INAREA(xi, zi - 1, m_cloud_radius_i)) {
u32 j = GETINDEX(xi, zi - 1, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(0, 0, -1);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_1;
vertex.Normal.set(0, 0, -1);
}
}
v[0].Pos.set(-rx, ry, -rz);
v[1].Pos.set(rx, ry, -rz);
v[2].Pos.set(rx, 0, -rz);
v[3].Pos.set(-rx, 0, -rz);
break;
case 2: //right
if (INAREA(xi + 1, zi, m_cloud_radius_i)) {
u32 j = GETINDEX(xi + 1, zi, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(1, 0, 0);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_2;
vertex.Normal.set(1, 0, 0);
}
}
v[0].Pos.set(rx, ry, -rz);
v[1].Pos.set(rx, ry, rz);
v[2].Pos.set(rx, 0, rz);
v[3].Pos.set(rx, 0, -rz);
break;
case 3: // front
if (INAREA(xi, zi + 1, m_cloud_radius_i)) {
u32 j = GETINDEX(xi, zi + 1, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(0, 0, -1);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_1;
vertex.Normal.set(0, 0, -1);
}
}
v[0].Pos.set(rx, ry, rz);
v[1].Pos.set(-rx, ry, rz);
v[2].Pos.set(-rx, 0, rz);
v[3].Pos.set(rx, 0, rz);
break;
case 4: // left
if (INAREA(xi - 1, zi, m_cloud_radius_i)) {
u32 j = GETINDEX(xi - 1, zi, m_cloud_radius_i);
if (grid[j])
continue;
}
if (soft_clouds_enabled) {
for (video::S3DVertex& vertex : v) {
vertex.Normal.set(-1, 0, 0);
}
v[2].Color = c_bottom;
v[3].Color = c_bottom;
}
else {
for (video::S3DVertex& vertex : v) {
vertex.Color = c_side_2;
vertex.Normal.set(-1, 0, 0);
}
}
v[0].Pos.set(-rx, ry, rz);
v[1].Pos.set(-rx, ry, -rz);
v[2].Pos.set(-rx, 0, -rz);
v[3].Pos.set(-rx, 0, rz);
break;
case 5: // bottom
for (video::S3DVertex& vertex : v) {
vertex.Color = c_bottom;
vertex.Normal.set(0, -1, 0);
}
v[0].Pos.set(rx, 0, rz);
v[1].Pos.set(-rx, 0, rz);
v[2].Pos.set(-rx, 0, -rz);
v[3].Pos.set(rx, 0, -rz);
break;
}
for (video::S3DVertex& vertex : v) {
vertex.Pos += pos;
vertices.push_back(vertex);
}
vertices.push_back(vertex);
}
}
}

View file

@ -395,8 +395,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
CachedPixelShaderSetting<float, 16> m_camera_projinv_pixel{"mCameraProjInv"};
CachedVertexShaderSetting<float, 16> m_camera_view_vertex{"mCameraView"};
CachedPixelShaderSetting<float, 16> m_camera_view_pixel{"mCameraView"};
CachedPixelShaderSetting<float> m_camera_near_pixel{"cameraNear"};
CachedPixelShaderSetting<float> m_camera_far_pixel{"cameraFar"};
CachedPixelShaderSetting<SamplerLayer_t> m_texture0{"texture0"};
CachedPixelShaderSetting<SamplerLayer_t> m_texture1{"texture1"};
CachedPixelShaderSetting<SamplerLayer_t> m_texture2{"texture2"};
@ -428,6 +426,18 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
CachedPixelShaderSetting<float> m_moon_brightness_pixel{"moonBrightness"};
CachedPixelShaderSetting<float>
m_volumetric_light_strength_pixel{"volumetricLightStrength"};
CachedPixelShaderSetting<float, 3>
m_volumetric_beta_r0_pixel{ "beta_r0_l" };
CachedVertexShaderSetting<float, 3>
m_volumetric_beta_r0_vertex{ "beta_r0_l" };
CachedPixelShaderSetting<float, 3> m_cdl_slope_pixel{"cdl_slope"};
CachedPixelShaderSetting<float, 3> m_cdl_offset_pixel{"cdl_offset"};
CachedPixelShaderSetting<float, 3> m_cdl_power_pixel{"cdl_power"};
CachedPixelShaderSetting<float> m_vignette_dark_pixel{"vignette_dark"};
CachedPixelShaderSetting<float> m_vignette_bright_pixel{"vignette_bright"};
CachedPixelShaderSetting<float> m_vignette_power_pixel{"vignette_power"};
CachedPixelShaderSetting<float> m_fov_pixel{"fov"};
CachedPixelShaderSetting<float, 2> m_window_size_pixel{"windowSize"};
static constexpr std::array<const char*, 1> SETTING_CALLBACKS = {
"exposure_compensation",
@ -457,6 +467,7 @@ public:
m_user_exposure_compensation = g_settings->getFloat("exposure_compensation", -1.0f, 1.0f);
m_bloom_enabled = g_settings->getBool("enable_bloom");
m_volumetric_light_enabled = g_settings->getBool("enable_volumetric_lighting") && m_bloom_enabled;
m_gamma = g_settings->getFloat("secondstage_gamma");
}
~GameGlobalShaderConstantSetter()
@ -506,10 +517,11 @@ public:
m_camera_view_vertex.set(camera_view, services);
m_camera_view_pixel.set(camera_view, services);
float camera_near = m_client->getCamera()->getCameraNode()->getNearValue();
m_camera_near_pixel.set(&camera_near, services);
float camera_far = m_client->getCamera()->getCameraNode()->getFarValue();
m_camera_far_pixel.set(&camera_far, services);
float fov = m_client->getCamera()->getFovMax();
m_fov_pixel.set(&fov, services);
v2u32 window_size_int = RenderingEngine::getWindowSize();
core::vector2df window_size = core::vector2df(window_size_int.X, window_size_int.Y);
m_window_size_pixel.set(window_size, services);
SamplerLayer_t tex_id;
tex_id = 0;
@ -552,6 +564,26 @@ public:
video::SColorf artificial_light = lighting.artificial_light_color;
m_artificial_light.set(artificial_light, services);
float gamma = m_gamma;
m_gamma_pixel.set(&gamma, services);
if (g_settings->getBool("enable_vignette")) {
const Vignette &vignette_params = lighting.vignette;
m_vignette_dark_pixel.set(&vignette_params.dark, services);
m_vignette_bright_pixel.set(&vignette_params.bright, services);
m_vignette_power_pixel.set(&vignette_params.power, services);
}
if (g_settings->getBool("enable_color_grading")) {
const ColorDecisionList& cdl_params = lighting.cdl;
core::vector3df slope = cdl_params.slope;
m_cdl_slope_pixel.set(slope, services);
core::vector3df offset = cdl_params.offset;
m_cdl_offset_pixel.set(offset, services);
core::vector3df power = cdl_params.power;
m_cdl_power_pixel.set(power, services);
}
if (m_volumetric_light_enabled) {
// Map directional light to screen space
auto camera_node = m_client->getCamera()->getCameraNode();
@ -594,6 +626,10 @@ public:
float volumetric_light_strength = lighting.volumetric_light_strength;
m_volumetric_light_strength_pixel.set(&volumetric_light_strength, services);
core::vector3df beta_r0 = lighting.volumetric_beta_r0;
m_volumetric_beta_r0_vertex.set(beta_r0, services);
m_volumetric_beta_r0_pixel.set(beta_r0, services);
}
}

View file

@ -727,6 +727,9 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
if (shadow_soft_radius < 1.0f)
shadow_soft_radius = 1.0f;
shaders_header << "#define SOFTSHADOWRADIUS " << shadow_soft_radius << "\n";
if (g_settings->getBool("enable_sun_tint"))
shaders_header << "#define ENABLE_TINTED_SUNLIGHT 1\n";
}
if (g_settings->getBool("enable_bloom")) {
@ -757,6 +760,10 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
shaders_header << "#define VOLUMETRIC_LIGHT 1\n";
}
if (g_settings->getBool("enable_volumetric_depth_attenuation")) {
shaders_header << "#define VOLUMETRIC_DEPTH_ATTENUATION 1\n";
}
shaders_header << "#line 0\n"; // reset the line counter for meaningful diagnostics
std::string common_header = shaders_header.str();

View file

@ -344,12 +344,13 @@ void set_default_settings()
settings->setDefault("enable_auto_exposure", "false");
settings->setDefault("enable_color_grading", "false");
settings->setDefault("enable_vignette", "false");
settings->setDefault("gamma", "1.6");
settings->setDefault("secondstage_gamma", "1.6");
settings->setDefault("debanding", "true");
settings->setDefault("antialiasing", "none");
settings->setDefault("enable_bloom", "false");
settings->setDefault("enable_bloom_debug", "false");
settings->setDefault("enable_volumetric_lighting", "false");
settings->setDefault("enable_volumetric_depth_attenuation", "false");
settings->setDefault("enable_bumpmaps", "false");
settings->setDefault("enable_water_reflections", "false");
settings->setDefault("enable_translucent_foliage", "false");
@ -368,6 +369,7 @@ void set_default_settings()
settings->setDefault("shadow_update_frames", "8");
settings->setDefault("shadow_soft_radius", "5.0");
settings->setDefault("shadow_sky_body_orbit_tilt", "0.0");
settings->setDefault("enable_sun_tint", "false");
// Input
settings->setDefault("invert_mouse", "false");

View file

@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "SColor.h"
#include "vector3d.h"
using namespace irr;
@ -48,14 +49,46 @@ struct AutoExposure
AutoExposure();
};
/**
* Parameters for vignette in post
*
*/
struct Vignette {
/// @brief The darkest part of the vignette will be darkened/brightened by this factor.
float dark = 0.3f;
/// @brief The brightest part of the vignette will be darkened/brightened by this factor.
float bright = 1.1f;
/// @brief Describes the blending between dark and bright. Higher values mean darkening is more intense at the screen edges.
float power = 1.1f;
};
/**
* ASL CDL parameters
*
* Colors in ASL CDL follow the following equation:
*
* out = pow(in * slope + offset, power)
*
*/
struct ColorDecisionList {
core::vector3df slope{1.2, 1.0, 0.8};
core::vector3df offset{0.0, 0.0, 0.0};
core::vector3df power{1.25, 1.0, 0.9};
};
/** Describes ambient light settings for a player
*/
struct Lighting
{
AutoExposure exposure;
Vignette vignette;
ColorDecisionList cdl;
float shadow_intensity {0.0f};
float saturation {1.0f};
float volumetric_light_strength {0.0f};
// These factors are calculated based on expected value of scattering factor of 1e-5
// for Nitrogen at 532nm (green), 2e25 molecules/m3 in atmosphere
core::vector3df volumetric_beta_r0{ 3.3362176e-01, 8.75378289198826e-01, 1.95342379700656 };
video::SColor artificial_light_color{ 255, 133, 133, 133 };
video::SColor shadow_tint {255, 0, 0, 0};
float bloom_intensity {0.05f};

View file

@ -1830,5 +1830,13 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
>> lighting.bloom_radius;
if (pkt->getRemainingBytes() >= 4)
*pkt >> lighting.artificial_light_color;
if (pkt->getRemainingBytes() >= 60)
*pkt >> lighting.volumetric_beta_r0;
*pkt >> lighting.vignette.dark
>> lighting.vignette.bright
>> lighting.vignette.power;
*pkt >> lighting.cdl.slope;
*pkt >> lighting.cdl.offset;
*pkt >> lighting.cdl.power;
}
}

View file

@ -58,6 +58,7 @@
Rename TOCLIENT_DEATHSCREEN to TOCLIENT_DEATHSCREEN_LEGACY
Rename TOSERVER_RESPAWN to TOSERVER_RESPAWN_LEGACY
Support float animation frame numbers in TOCLIENT_LOCAL_PLAYER_ANIMATIONS
Add beta_r0, vignette and cdl parameters to Lighting packets
[scheduled bump for 5.10.0]
*/

View file

@ -2654,6 +2654,12 @@ int ObjectRef::l_set_lighting(lua_State *L)
if (lua_istable(L, -1)) {
getfloatfield(L, -1, "strength", lighting.volumetric_light_strength);
lighting.volumetric_light_strength = rangelim(lighting.volumetric_light_strength, 0.0f, 1.0f);
lua_getfield(L, -1, "beta_r0");
if (!lua_isnil(L, -1)) {
lighting.volumetric_beta_r0 = read_v3f(L, -1);
}
lua_pop(L, 1); // beta_r0
}
lua_pop(L, 1); // volumetric_light
@ -2664,6 +2670,31 @@ int ObjectRef::l_set_lighting(lua_State *L)
lighting.bloom_radius = getfloatfield_default(L, -1, "radius", lighting.bloom_radius);
}
lua_pop(L, 1); // bloom
lua_getfield(L, 2, "vignette");
if (lua_istable(L, -1)) {
lighting.vignette.dark = getfloatfield_default(L, -1, "dark", lighting.vignette.dark);
lighting.vignette.bright = getfloatfield_default(L, -1, "bright", lighting.vignette.bright);
lighting.vignette.power = getfloatfield_default(L, -1, "power", lighting.vignette.power);
}
lua_pop(L, 1); // vignette
lua_getfield(L, 2, "cdl");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "slope");
if (!lua_isnil(L, -1))
lighting.cdl.slope = read_v3f(L, -1);
lua_pop(L, 1); // slope
lua_getfield(L, -1, "offset");
if (!lua_isnil(L, -1))
lighting.cdl.offset = read_v3f(L, -1);
lua_pop(L, 1); // offset
lua_getfield(L, -1, "power");
if (!lua_isnil(L, -1))
lighting.cdl.power = read_v3f(L, -1);
lua_pop(L, 1); // power
}
lua_pop(L, 1); // cdl
}
getServer(L)->setLighting(player, lighting);
@ -2709,6 +2740,8 @@ int ObjectRef::l_get_lighting(lua_State *L)
lua_newtable(L); // "volumetric_light"
lua_pushnumber(L, lighting.volumetric_light_strength);
lua_setfield(L, -2, "strength");
push_v3f(L, lighting.volumetric_beta_r0);
lua_setfield(L, -2, "beta_r0");
lua_setfield(L, -2, "volumetric_light");
lua_newtable(L); // "bloom"
lua_pushnumber(L, lighting.bloom_intensity);
@ -2718,6 +2751,22 @@ int ObjectRef::l_get_lighting(lua_State *L)
lua_pushnumber(L, lighting.bloom_radius);
lua_setfield(L, -2, "radius");
lua_setfield(L, -2, "bloom");
lua_newtable(L); // "vignette"
lua_pushnumber(L, lighting.vignette.dark);
lua_setfield(L, -2, "dark");
lua_pushnumber(L, lighting.vignette.bright);
lua_setfield(L, -2, "bright");
lua_pushnumber(L, lighting.vignette.power);
lua_setfield(L, -2, "power");
lua_setfield(L, -2, "vignette");
lua_newtable(L); // "cdl"
push_v3f(L, lighting.cdl.slope);
lua_setfield(L, -2, "slope");
push_v3f(L, lighting.cdl.offset);
lua_setfield(L, -2, "offset");
push_v3f(L, lighting.cdl.power);
lua_setfield(L, -2, "power");
lua_setfield(L, -2, "cdl");
return 1;
}

View file

@ -1913,7 +1913,7 @@ void Server::SendOverrideDayNightRatio(session_t peer_id, bool do_override,
Send(&pkt);
}
void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
void Server::SendSetLighting(session_t peer_id, const Lighting & lighting)
{
NetworkPacket pkt(TOCLIENT_SET_LIGHTING,
4, peer_id);
@ -1932,6 +1932,13 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
pkt << lighting.bloom_intensity << lighting.bloom_strength_factor <<
lighting.bloom_radius;
pkt << lighting.artificial_light_color;
pkt << lighting.volumetric_beta_r0;
pkt << lighting.vignette.dark
<< lighting.vignette.bright
<< lighting.vignette.power;
pkt << lighting.cdl.slope;
pkt << lighting.cdl.offset;
pkt << lighting.cdl.power;
Send(&pkt);
}