mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-16 18:01:40 +00:00
Lots of changes
some redundant stuff in vertex shaders needs fixing
This commit is contained in:
parent
ded1b09838
commit
ca4f04ecab
9 changed files with 138 additions and 23 deletions
|
@ -1,4 +1,12 @@
|
|||
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT)
|
||||
#define MATERIAL_WAVING_LIQUID 1
|
||||
#define MATERIAL_LIQUID 1
|
||||
#elif (MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE)
|
||||
#define MATERIAL_LIQUID 1
|
||||
#endif
|
||||
|
||||
uniform sampler2D baseTexture;
|
||||
uniform vec2 texelSize0;
|
||||
|
||||
uniform vec3 dayLight;
|
||||
uniform lowp vec4 fogColor;
|
||||
|
@ -48,6 +56,36 @@ varying float nightRatio;
|
|||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
|
||||
#ifdef ENABLE_BUMPMAPS
|
||||
vec4 perm(vec4 x)
|
||||
{
|
||||
return mod(((x * 34.0) + 1.0) * x, 289.0);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
// assuming near is always 1.0
|
||||
float getLinearDepth()
|
||||
{
|
||||
|
@ -378,6 +416,26 @@ void main(void)
|
|||
vec4 col = vec4(color.rgb * varColor.rgb, 1.0);
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
// Fragment normal, can differ from vNormal which is derived from vertex normals.
|
||||
vec3 fNormal = vNormal;
|
||||
|
||||
#if (defined(ENABLE_BUMPMAPS) && !defined(MATERIAL_LIQUID))
|
||||
vec2 dr = vec2(0.25) * texelSize0;
|
||||
// Sample the texture to then compute the derivative
|
||||
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;
|
||||
// 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 * (fx1y0 - fx0y0) / dr.x + orth2 * (fx0y1 - fx0y0) / dr.y) * 0.25 * snoise(vec3(uv / texelSize0, 0.0)));
|
||||
float adj_cosLight = max(1e-5, dot(fNormal, -v_LightDirection));
|
||||
#else
|
||||
float adj_cosLight = cosLight;
|
||||
#endif
|
||||
|
||||
if (f_shadow_strength > 0.0) {
|
||||
float shadow_int = 0.0;
|
||||
vec3 shadow_color = vec3(0.0, 0.0, 0.0);
|
||||
|
@ -392,14 +450,14 @@ void main(void)
|
|||
|
||||
#ifdef COLORED_SHADOWS
|
||||
vec4 visibility;
|
||||
if (cosLight > 0.0 || f_normal_length < 1e-3)
|
||||
if (adj_cosLight > 0.0 || f_normal_length < 1e-3)
|
||||
visibility = getShadowColor(ShadowMapSampler, posLightSpace.xy, posLightSpace.z);
|
||||
else
|
||||
visibility = vec4(1.0, 0.0, 0.0, 0.0);
|
||||
shadow_int = visibility.r;
|
||||
shadow_color = visibility.gba;
|
||||
#else
|
||||
if (cosLight > 0.0 || f_normal_length < 1e-3)
|
||||
if (adj_cosLight > 0.0 || f_normal_length < 1e-3)
|
||||
shadow_int = getShadow(ShadowMapSampler, posLightSpace.xy, posLightSpace.z);
|
||||
else
|
||||
shadow_int = 1.0;
|
||||
|
@ -417,9 +475,9 @@ void main(void)
|
|||
// Apply self-shadowing when light falls at a narrow angle to the surface
|
||||
// Cosine of the cut-off angle.
|
||||
const float self_shadow_cutoff_cosine = 0.035;
|
||||
if (f_normal_length != 0 && cosLight < self_shadow_cutoff_cosine) {
|
||||
shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
|
||||
shadow_color = mix(vec3(0.0), shadow_color, min(cosLight, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
|
||||
if (f_normal_length != 0 && adj_cosLight < self_shadow_cutoff_cosine) {
|
||||
shadow_int = max(shadow_int, 1 - clamp(adj_cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
|
||||
shadow_color = mix(vec3(0.0), shadow_color, min(adj_cosLight, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
|
||||
}
|
||||
|
||||
shadow_int *= f_adj_shadow_strength;
|
||||
|
|
|
@ -259,16 +259,16 @@ void main(void)
|
|||
shadow_position.z -= z_bias;
|
||||
perspective_factor = pFactor;
|
||||
|
||||
if (f_timeofday < 0.2) {
|
||||
if (f_timeofday < 0.21) {
|
||||
adj_shadow_strength = f_shadow_strength * 0.5 *
|
||||
(1.0 - mtsmoothstep(0.18, 0.2, f_timeofday));
|
||||
} else if (f_timeofday >= 0.8) {
|
||||
(1.0 - mtsmoothstep(0.18, 0.21, f_timeofday));
|
||||
} else if (f_timeofday >= 0.793) {
|
||||
adj_shadow_strength = f_shadow_strength * 0.5 *
|
||||
mtsmoothstep(0.8, 0.83, f_timeofday);
|
||||
mtsmoothstep(0.793, 0.823, f_timeofday);
|
||||
} else {
|
||||
adj_shadow_strength = f_shadow_strength *
|
||||
mtsmoothstep(0.20, 0.25, f_timeofday) *
|
||||
(1.0 - mtsmoothstep(0.7, 0.8, f_timeofday));
|
||||
mtsmoothstep(0.21, 0.26, f_timeofday) *
|
||||
(1.0 - mtsmoothstep(0.743, 0.793, f_timeofday));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -162,16 +162,16 @@ void main(void)
|
|||
shadow_position.z -= z_bias;
|
||||
perspective_factor = pFactor;
|
||||
|
||||
if (f_timeofday < 0.2) {
|
||||
if (f_timeofday < 0.21) {
|
||||
adj_shadow_strength = f_shadow_strength * 0.5 *
|
||||
(1.0 - mtsmoothstep(0.18, 0.2, f_timeofday));
|
||||
} else if (f_timeofday >= 0.8) {
|
||||
(1.0 - mtsmoothstep(0.18, 0.21, f_timeofday));
|
||||
} else if (f_timeofday >= 0.793) {
|
||||
adj_shadow_strength = f_shadow_strength * 0.5 *
|
||||
mtsmoothstep(0.8, 0.83, f_timeofday);
|
||||
mtsmoothstep(0.793, 0.823, f_timeofday);
|
||||
} else {
|
||||
adj_shadow_strength = f_shadow_strength *
|
||||
mtsmoothstep(0.20, 0.25, f_timeofday) *
|
||||
(1.0 - mtsmoothstep(0.7, 0.8, f_timeofday));
|
||||
mtsmoothstep(0.21, 0.26, f_timeofday) *
|
||||
(1.0 - mtsmoothstep(0.743, 0.793, f_timeofday));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,7 @@ uniform vec2 texelSize0;
|
|||
uniform ExposureParams exposureParams;
|
||||
uniform lowp float bloomIntensity;
|
||||
uniform lowp float saturation;
|
||||
uniform float gamma;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
|
@ -69,7 +70,6 @@ vec3 uncharted2Tonemap(vec3 x)
|
|||
vec4 applyToneMapping(vec4 color)
|
||||
{
|
||||
color = vec4(pow(color.rgb, vec3(2.2)), color.a);
|
||||
const float gamma = 1.6;
|
||||
const float exposureBias = 5.5;
|
||||
color.rgb = uncharted2Tonemap(exposureBias * color.rgb);
|
||||
// Precalculated white_scale from
|
||||
|
@ -102,6 +102,11 @@ vec3 screen_space_dither(highp vec2 frag_coord) {
|
|||
}
|
||||
#endif
|
||||
|
||||
float sFunction(float x, float a) {
|
||||
x = 2.0 * x - 1.0;
|
||||
return 0.5 * sign(x) * pow(abs(x), a) + 0.5;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 uv = varTexCoord.st;
|
||||
|
@ -131,8 +136,6 @@ void main(void)
|
|||
#ifdef ENABLE_BLOOM
|
||||
color = applyBloom(color, uv);
|
||||
#endif
|
||||
|
||||
|
||||
color.rgb = clamp(color.rgb, vec3(0.), vec3(1.));
|
||||
|
||||
// return to sRGB colorspace (approximate)
|
||||
|
@ -142,6 +145,15 @@ void main(void)
|
|||
if (uv.x > 0.5 || uv.y > 0.5)
|
||||
#endif
|
||||
{
|
||||
|
||||
#ifdef ENABLE_VIGNETTE
|
||||
color.rgb *= 0.8 * pow(1.0 - length(uv - vec2(0.5)) * 1.4, 0.9) + 0.3;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR_GRADING
|
||||
color.rgb = pow(color.rgb * vec3(1.3, 1.0, 0.8), vec3(1.3, 1.0, 0.9));
|
||||
#endif
|
||||
|
||||
#if ENABLE_TONE_MAPPING
|
||||
color = applyToneMapping(color);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue