mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Merge remote-tracking branch 'upstream/master' into Visuals-Vol-2
This commit is contained in:
commit
71e648a776
647 changed files with 60434 additions and 37195 deletions
|
@ -1 +0,0 @@
|
|||
../../irr/media/Shaders
|
75
client/shaders/Irrlicht/OneTextureBlend.fsh
Normal file
75
client/shaders/Irrlicht/OneTextureBlend.fsh
Normal file
|
@ -0,0 +1,75 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform int uTextureUsage0;
|
||||
uniform sampler2D uTextureUnit0;
|
||||
uniform int uBlendType;
|
||||
uniform int uFogEnable;
|
||||
uniform int uFogType;
|
||||
uniform vec4 uFogColor;
|
||||
uniform float uFogStart;
|
||||
uniform float uFogEnd;
|
||||
uniform float uFogDensity;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
float computeFog()
|
||||
{
|
||||
const float LOG2 = 1.442695;
|
||||
float FogFactor = 0.0;
|
||||
|
||||
if (uFogType == 0) // Exp
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
|
||||
}
|
||||
else if (uFogType == 1) // Linear
|
||||
{
|
||||
float Scale = 1.0 / (uFogEnd - uFogStart);
|
||||
FogFactor = (uFogEnd - vFogCoord) * Scale;
|
||||
}
|
||||
else if (uFogType == 2) // Exp2
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
|
||||
}
|
||||
|
||||
FogFactor = clamp(FogFactor, 0.0, 1.0);
|
||||
|
||||
return FogFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color0 = vVertexColor;
|
||||
vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
if (bool(uTextureUsage0))
|
||||
Color1 = texture2D(uTextureUnit0, vTextureCoord0);
|
||||
|
||||
vec4 FinalColor = Color0 * Color1;
|
||||
|
||||
if (uBlendType == 1)
|
||||
{
|
||||
FinalColor.w = Color0.w;
|
||||
}
|
||||
else if (uBlendType == 2)
|
||||
{
|
||||
FinalColor.w = Color1.w;
|
||||
}
|
||||
|
||||
if (bool(uFogEnable))
|
||||
{
|
||||
float FogFactor = computeFog();
|
||||
vec4 FogColor = uFogColor;
|
||||
FogColor.a = 1.0;
|
||||
FinalColor = mix(FogColor, FinalColor, FogFactor);
|
||||
}
|
||||
|
||||
gl_FragColor = FinalColor;
|
||||
}
|
23
client/shaders/Irrlicht/Renderer2D.fsh
Normal file
23
client/shaders/Irrlicht/Renderer2D.fsh
Normal file
|
@ -0,0 +1,23 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform int uTextureUsage;
|
||||
uniform sampler2D uTextureUnit;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
varying vec4 vVertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color = vVertexColor;
|
||||
|
||||
if (bool(uTextureUsage))
|
||||
Color *= texture2D(uTextureUnit, vTextureCoord);
|
||||
|
||||
gl_FragColor = Color;
|
||||
}
|
24
client/shaders/Irrlicht/Renderer2D.vsh
Normal file
24
client/shaders/Irrlicht/Renderer2D.vsh
Normal file
|
@ -0,0 +1,24 @@
|
|||
#version 100
|
||||
|
||||
/* Attributes */
|
||||
|
||||
attribute vec4 inVertexPosition;
|
||||
attribute vec4 inVertexColor;
|
||||
attribute vec2 inTexCoord0;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform float uThickness;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord;
|
||||
varying vec4 vVertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = inVertexPosition;
|
||||
gl_PointSize = uThickness;
|
||||
vTextureCoord = inTexCoord0;
|
||||
vVertexColor = inVertexColor.bgra;
|
||||
}
|
11
client/shaders/Irrlicht/Renderer2D_noTex.fsh
Normal file
11
client/shaders/Irrlicht/Renderer2D_noTex.fsh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Varyings */
|
||||
varying vec4 vVertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vVertexColor;
|
||||
}
|
62
client/shaders/Irrlicht/Solid.fsh
Normal file
62
client/shaders/Irrlicht/Solid.fsh
Normal file
|
@ -0,0 +1,62 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform int uTextureUsage0;
|
||||
uniform sampler2D uTextureUnit0;
|
||||
uniform int uFogEnable;
|
||||
uniform int uFogType;
|
||||
uniform vec4 uFogColor;
|
||||
uniform float uFogStart;
|
||||
uniform float uFogEnd;
|
||||
uniform float uFogDensity;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
float computeFog()
|
||||
{
|
||||
const float LOG2 = 1.442695;
|
||||
float FogFactor = 0.0;
|
||||
|
||||
if (uFogType == 0) // Exp
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
|
||||
}
|
||||
else if (uFogType == 1) // Linear
|
||||
{
|
||||
float Scale = 1.0 / (uFogEnd - uFogStart);
|
||||
FogFactor = (uFogEnd - vFogCoord) * Scale;
|
||||
}
|
||||
else if (uFogType == 2) // Exp2
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
|
||||
}
|
||||
|
||||
FogFactor = clamp(FogFactor, 0.0, 1.0);
|
||||
|
||||
return FogFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color = vVertexColor;
|
||||
|
||||
if (bool(uTextureUsage0))
|
||||
Color *= texture2D(uTextureUnit0, vTextureCoord0);
|
||||
|
||||
if (bool(uFogEnable))
|
||||
{
|
||||
float FogFactor = computeFog();
|
||||
vec4 FogColor = uFogColor;
|
||||
FogColor.a = 1.0;
|
||||
Color = mix(FogColor, Color, FogFactor);
|
||||
}
|
||||
|
||||
gl_FragColor = Color;
|
||||
}
|
37
client/shaders/Irrlicht/Solid.vsh
Normal file
37
client/shaders/Irrlicht/Solid.vsh
Normal file
|
@ -0,0 +1,37 @@
|
|||
#version 100
|
||||
|
||||
/* Attributes */
|
||||
|
||||
attribute vec3 inVertexPosition;
|
||||
attribute vec3 inVertexNormal;
|
||||
attribute vec4 inVertexColor;
|
||||
attribute vec2 inTexCoord0;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform mat4 uWVPMatrix;
|
||||
uniform mat4 uWVMatrix;
|
||||
uniform mat4 uTMatrix0;
|
||||
|
||||
uniform float uThickness;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
|
||||
gl_PointSize = uThickness;
|
||||
|
||||
vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0);
|
||||
vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
|
||||
|
||||
vVertexColor = inVertexColor.bgra;
|
||||
|
||||
vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
|
||||
|
||||
vFogCoord = length(Position);
|
||||
}
|
69
client/shaders/Irrlicht/TransparentAlphaChannel.fsh
Normal file
69
client/shaders/Irrlicht/TransparentAlphaChannel.fsh
Normal file
|
@ -0,0 +1,69 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform float uAlphaRef;
|
||||
uniform int uTextureUsage0;
|
||||
uniform sampler2D uTextureUnit0;
|
||||
uniform int uFogEnable;
|
||||
uniform int uFogType;
|
||||
uniform vec4 uFogColor;
|
||||
uniform float uFogStart;
|
||||
uniform float uFogEnd;
|
||||
uniform float uFogDensity;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
float computeFog()
|
||||
{
|
||||
const float LOG2 = 1.442695;
|
||||
float FogFactor = 0.0;
|
||||
|
||||
if (uFogType == 0) // Exp
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
|
||||
}
|
||||
else if (uFogType == 1) // Linear
|
||||
{
|
||||
float Scale = 1.0 / (uFogEnd - uFogStart);
|
||||
FogFactor = (uFogEnd - vFogCoord) * Scale;
|
||||
}
|
||||
else if (uFogType == 2) // Exp2
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
|
||||
}
|
||||
|
||||
FogFactor = clamp(FogFactor, 0.0, 1.0);
|
||||
|
||||
return FogFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color = vVertexColor;
|
||||
|
||||
if (bool(uTextureUsage0))
|
||||
{
|
||||
Color *= texture2D(uTextureUnit0, vTextureCoord0);
|
||||
|
||||
// TODO: uAlphaRef should rather control sharpness of alpha, don't know how to do that right now and this works in most cases.
|
||||
if (Color.a < uAlphaRef)
|
||||
discard;
|
||||
}
|
||||
|
||||
if (bool(uFogEnable))
|
||||
{
|
||||
float FogFactor = computeFog();
|
||||
vec4 FogColor = uFogColor;
|
||||
FogColor.a = 1.0;
|
||||
Color = mix(FogColor, Color, FogFactor);
|
||||
}
|
||||
|
||||
gl_FragColor = Color;
|
||||
}
|
66
client/shaders/Irrlicht/TransparentAlphaChannelRef.fsh
Normal file
66
client/shaders/Irrlicht/TransparentAlphaChannelRef.fsh
Normal file
|
@ -0,0 +1,66 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform float uAlphaRef;
|
||||
uniform int uTextureUsage0;
|
||||
uniform sampler2D uTextureUnit0;
|
||||
uniform int uFogEnable;
|
||||
uniform int uFogType;
|
||||
uniform vec4 uFogColor;
|
||||
uniform float uFogStart;
|
||||
uniform float uFogEnd;
|
||||
uniform float uFogDensity;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
float computeFog()
|
||||
{
|
||||
const float LOG2 = 1.442695;
|
||||
float FogFactor = 0.0;
|
||||
|
||||
if (uFogType == 0) // Exp
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
|
||||
}
|
||||
else if (uFogType == 1) // Linear
|
||||
{
|
||||
float Scale = 1.0 / (uFogEnd - uFogStart);
|
||||
FogFactor = (uFogEnd - vFogCoord) * Scale;
|
||||
}
|
||||
else if (uFogType == 2) // Exp2
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
|
||||
}
|
||||
|
||||
FogFactor = clamp(FogFactor, 0.0, 1.0);
|
||||
|
||||
return FogFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color = vVertexColor;
|
||||
|
||||
if (bool(uTextureUsage0))
|
||||
Color *= texture2D(uTextureUnit0, vTextureCoord0);
|
||||
|
||||
if (Color.a < uAlphaRef)
|
||||
discard;
|
||||
|
||||
if (bool(uFogEnable))
|
||||
{
|
||||
float FogFactor = computeFog();
|
||||
vec4 FogColor = uFogColor;
|
||||
FogColor.a = 1.0;
|
||||
Color = mix(FogColor, Color, FogFactor);
|
||||
}
|
||||
|
||||
gl_FragColor = Color;
|
||||
}
|
62
client/shaders/Irrlicht/TransparentVertexAlpha.fsh
Normal file
62
client/shaders/Irrlicht/TransparentVertexAlpha.fsh
Normal file
|
@ -0,0 +1,62 @@
|
|||
#version 100
|
||||
|
||||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform int uTextureUsage0;
|
||||
uniform sampler2D uTextureUnit0;
|
||||
uniform int uFogEnable;
|
||||
uniform int uFogType;
|
||||
uniform vec4 uFogColor;
|
||||
uniform float uFogStart;
|
||||
uniform float uFogEnd;
|
||||
uniform float uFogDensity;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
float computeFog()
|
||||
{
|
||||
const float LOG2 = 1.442695;
|
||||
float FogFactor = 0.0;
|
||||
|
||||
if (uFogType == 0) // Exp
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
|
||||
}
|
||||
else if (uFogType == 1) // Linear
|
||||
{
|
||||
float Scale = 1.0 / (uFogEnd - uFogStart);
|
||||
FogFactor = (uFogEnd - vFogCoord) * Scale;
|
||||
}
|
||||
else if (uFogType == 2) // Exp2
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
|
||||
}
|
||||
|
||||
FogFactor = clamp(FogFactor, 0.0, 1.0);
|
||||
|
||||
return FogFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color = vVertexColor;
|
||||
|
||||
if (bool(uTextureUsage0))
|
||||
Color *= texture2D(uTextureUnit0, vTextureCoord0);
|
||||
|
||||
if (bool(uFogEnable))
|
||||
{
|
||||
float FogFactor = computeFog();
|
||||
vec4 FogColor = uFogColor;
|
||||
FogColor.a = 1.0;
|
||||
Color = mix(FogColor, Color, FogFactor);
|
||||
}
|
||||
|
||||
gl_FragColor = Color;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
uniform lowp vec4 emissiveColor;
|
||||
uniform lowp vec4 materialColor;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
|
||||
|
@ -14,7 +14,7 @@ void main(void)
|
|||
vec4 color = inVertexColor;
|
||||
#endif
|
||||
|
||||
color *= emissiveColor;
|
||||
color *= materialColor;
|
||||
varColor = color;
|
||||
|
||||
eyeVec = -(mWorldView * inVertexPosition).xyz;
|
||||
|
|
|
@ -58,11 +58,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define FXAA_SPAN_MAX 8.0
|
||||
#endif
|
||||
|
||||
//optimized version for mobile, where dependent
|
||||
//optimized version for mobile, where dependent
|
||||
//texture reads can be a bottleneck
|
||||
vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 inverseVP,
|
||||
vec2 v_rgbNW, vec2 v_rgbNE,
|
||||
vec2 v_rgbSW, vec2 v_rgbSE,
|
||||
vec2 v_rgbNW, vec2 v_rgbNE,
|
||||
vec2 v_rgbSW, vec2 v_rgbSE,
|
||||
vec2 v_rgbM) {
|
||||
vec4 color;
|
||||
vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;
|
||||
|
@ -111,6 +111,6 @@ void main(void)
|
|||
{
|
||||
vec2 uv = varTexCoord.st;
|
||||
|
||||
gl_FragColor = fxaa(rendered, uv, texelSize0,
|
||||
gl_FragColor = fxaa(rendered, uv, texelSize0,
|
||||
sampleNW, sampleNE, sampleSW, sampleSE, uv);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ varying vec2 sampleSW;
|
|||
varying vec2 sampleSE;
|
||||
|
||||
/*
|
||||
Based on
|
||||
Based on
|
||||
https://github.com/mattdesl/glsl-fxaa/
|
||||
Portions Copyright (c) 2011 by Armin Ronacher.
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ uniform float fogShadingParameter;
|
|||
|
||||
// The cameraOffset is the current center of the visible world.
|
||||
uniform highp vec3 cameraOffset;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float animationTimer;
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
// shadow texture
|
||||
|
@ -30,6 +31,7 @@ uniform float animationTimer;
|
|||
uniform vec4 CameraPos;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform vec3 shadow_tint;
|
||||
|
||||
varying float adj_shadow_strength;
|
||||
varying float cosLight;
|
||||
|
@ -57,6 +59,49 @@ varying highp vec3 eyeVec;
|
|||
varying float nightRatio;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
#if (defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS) && ENABLE_WAVING_WATER)
|
||||
vec4 perm(vec4 x)
|
||||
{
|
||||
return mod(((x * 34.0) + 1.0) * x, 289.0);
|
||||
}
|
||||
|
||||
// Corresponding gradient of snoise
|
||||
vec3 gnoise(vec3 p){
|
||||
vec3 a = floor(p);
|
||||
vec3 d = p - a;
|
||||
vec3 dd = 6.0 * d * (1.0 - d);
|
||||
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);
|
||||
|
||||
vec4 dz1 = (o2 - o1) * dd.z;
|
||||
vec2 dz2 = dz1.yw * d.x + dz1.xz * (1.0 - d.x);
|
||||
|
||||
vec2 dx = (o3.yw - o3.xz) * dd.x;
|
||||
|
||||
return vec3(
|
||||
dx.y * d.y + dx.x * (1. - d.y),
|
||||
(o4.y - o4.x) * dd.y,
|
||||
dz2.y * d.y + dz2.x * (1. - d.y)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BUMPMAPS
|
||||
vec4 perm(vec4 x)
|
||||
|
@ -106,6 +151,14 @@ float mtsmoothstep(in float edge0, in float edge1, in float x)
|
|||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
float shadowCutoff(float x) {
|
||||
#if defined(ENABLE_TRANSLUCENT_FOLIAGE) && MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES
|
||||
return mtsmoothstep(0.0, 0.002, x);
|
||||
#else
|
||||
return step(0.0, x);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef COLORED_SHADOWS
|
||||
|
||||
// c_precision of 128 fits within 7 base-10 digits
|
||||
|
@ -132,10 +185,10 @@ vec4 getHardShadowColor(sampler2D shadowsampler, vec2 smTexCoord, float realDist
|
|||
{
|
||||
vec4 texDepth = texture2D(shadowsampler, smTexCoord.xy).rgba;
|
||||
|
||||
float visibility = step(0.0, realDistance - texDepth.r);
|
||||
float visibility = shadowCutoff(realDistance - texDepth.r);
|
||||
vec4 result = vec4(visibility, vec3(0.0,0.0,0.0));//unpackColor(texDepth.g));
|
||||
if (visibility < 0.1) {
|
||||
visibility = step(0.0, realDistance - texDepth.b);
|
||||
visibility = shadowCutoff(realDistance - texDepth.b);
|
||||
result = vec4(visibility, unpackColor(texDepth.a));
|
||||
}
|
||||
return result;
|
||||
|
@ -146,7 +199,7 @@ vec4 getHardShadowColor(sampler2D shadowsampler, vec2 smTexCoord, float realDist
|
|||
float getHardShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance)
|
||||
{
|
||||
float texDepth = texture2D(shadowsampler, smTexCoord.xy).r;
|
||||
float visibility = step(0.0, realDistance - texDepth);
|
||||
float visibility = shadowCutoff(realDistance - texDepth);
|
||||
return visibility;
|
||||
}
|
||||
|
||||
|
@ -421,7 +474,6 @@ void main(void)
|
|||
// 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;
|
||||
|
@ -474,12 +526,20 @@ void main(void)
|
|||
// Power ratio was measured on torches in MTG (brightness = 14).
|
||||
float adjusted_night_ratio = pow(max(0.0, nightRatio), 0.6);
|
||||
|
||||
float shadow_uncorrected = shadow_int;
|
||||
|
||||
// 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 && 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);
|
||||
|
||||
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES || MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS)
|
||||
// Prevents foliage from becoming insanely bright outside the shadow map.
|
||||
shadow_uncorrected = mix(shadow_int, shadow_uncorrected, clamp(distance_rate * 4.0 - 3.0, 0.0, 1.0));
|
||||
#endif
|
||||
}
|
||||
|
||||
shadow_int *= f_adj_shadow_strength;
|
||||
|
@ -488,8 +548,60 @@ void main(void)
|
|||
col.rgb =
|
||||
adjusted_night_ratio * col.rgb + // artificial light
|
||||
sunTint * (1.0 - adjusted_night_ratio) * ( // natural light
|
||||
col.rgb * (1.0 - shadow_int * (1.0 - shadow_color)) + // filtered texture color
|
||||
col.rgb * (1.0 - shadow_int * (1.0 - shadow_color) * (1.0 - shadow_tint)) + // filtered texture color
|
||||
dayLight * shadow_color * shadow_int); // reflected filtered sunlight/moonlight
|
||||
|
||||
|
||||
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) && ENABLE_WAVING_WATER)
|
||||
vec3 wavePos = worldPosition * vec3(2.0, 0.0, 2.0);
|
||||
float off = animationTimer * WATER_WAVE_SPEED * 10.0;
|
||||
wavePos.x /= WATER_WAVE_LENGTH * 3.0;
|
||||
wavePos.z /= WATER_WAVE_LENGTH * 2.0;
|
||||
|
||||
// This is an analogous method to the bumpmap, except we get the gradient information directly from gnoise.
|
||||
vec2 gradient = wave_noise(wavePos, off);
|
||||
fNormal = normalize(normalize(fNormal) + vec3(gradient.x, 0., gradient.y) * WATER_WAVE_HEIGHT * abs(fNormal.y) * 0.25);
|
||||
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;
|
||||
|
||||
// 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;
|
||||
col.rgb *= 0.5;
|
||||
vec3 reflection_color = mix(vec3(max(fogColor.r, max(fogColor.g, fogColor.b))), fogColor.rgb, f_shadow_strength);
|
||||
|
||||
// Sky reflection
|
||||
col.rgb += reflection_color * pow(fresnel_factor, 2.0) * 0.5 * brightness_factor;
|
||||
vec3 water_reflect_color = 12.0 * 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);
|
||||
col.rgb += water_reflect_color * f_adj_shadow_strength * brightness_factor;
|
||||
#endif
|
||||
|
||||
#if (defined(ENABLE_NODE_SPECULAR) && !defined(MATERIAL_WAVING_LIQUID))
|
||||
// Apply specular to blocks.
|
||||
if (dot(v_LightDirection, vNormal) < 0.0) {
|
||||
float intensity = 2.0 * (1.0 - (base.r * varColor.r));
|
||||
const float specular_exponent = 5.0;
|
||||
const float fresnel_exponent = 4.0;
|
||||
|
||||
col.rgb +=
|
||||
intensity * dayLight * (1.0 - nightRatio) * (1.0 - shadow_uncorrected) * f_adj_shadow_strength *
|
||||
pow(max(dot(reflect_ray, viewVec), 0.0), fresnel_exponent) * pow(1.0 - abs(dot(viewVec, fNormal)), specular_exponent);
|
||||
}
|
||||
#endif
|
||||
|
||||
#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);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -504,7 +616,13 @@ void main(void)
|
|||
// Note: clarity = (1 - fogginess)
|
||||
float clarity = clamp(fogShadingParameter
|
||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||
col = mix(fogColor, col, clarity);
|
||||
float fogColorMax = max(max(fogColor.r, fogColor.g), fogColor.b);
|
||||
// Prevent zero division.
|
||||
if (fogColorMax < 0.0000001) fogColorMax = 1.0;
|
||||
// For high clarity (light fog) we tint the fog color.
|
||||
// For this to not make the fog color artificially dark we need to normalize using the
|
||||
// fog color's brightest value. We then blend our base color with this to make the fog.
|
||||
col = mix(fogColor * pow(fogColor / fogColorMax, vec4(2.0 * clarity)), col, clarity);
|
||||
col = vec4(col.rgb, base.a);
|
||||
|
||||
gl_FragData[0] = col;
|
||||
|
|
|
@ -268,7 +268,9 @@ void main(void)
|
|||
z_bias *= pFactor * pFactor / f_textureresolution / f_shadowfar;
|
||||
|
||||
shadow_position = applyPerspectiveDistortion(m_ShadowViewProj * mWorld * (shadow_pos + vec4(normalOffsetScale * nNormal, 0.0))).xyz;
|
||||
#if !defined(ENABLE_TRANSLUCENT_FOLIAGE) || MATERIAL_TYPE != TILE_MATERIAL_WAVING_LEAVES
|
||||
shadow_position.z -= z_bias;
|
||||
#endif
|
||||
perspective_factor = pFactor;
|
||||
|
||||
sunTint = vec3(1.0);
|
||||
|
|
|
@ -21,6 +21,7 @@ uniform float animationTimer;
|
|||
uniform vec4 CameraPos;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform vec3 shadow_tint;
|
||||
|
||||
varying float adj_shadow_strength;
|
||||
varying float cosLight;
|
||||
|
@ -433,7 +434,7 @@ void main(void)
|
|||
col.rgb =
|
||||
adjusted_night_ratio * col.rgb + // artificial light
|
||||
sunTint * (1.0 - adjusted_night_ratio) * ( // natural light
|
||||
col.rgb * (1.0 - shadow_int * (1.0 - shadow_color)) + // filtered texture color
|
||||
col.rgb * (1.0 - shadow_int * (1.0 - shadow_color) * (1.0 - shadow_tint)) + // filtered texture color
|
||||
dayLight * shadow_color * shadow_int); // reflected filtered sunlight/moonlight
|
||||
}
|
||||
#endif
|
||||
|
@ -449,7 +450,13 @@ void main(void)
|
|||
// Note: clarity = (1 - fogginess)
|
||||
float clarity = clamp(fogShadingParameter
|
||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||
col = mix(fogColor, col, clarity);
|
||||
float fogColorMax = max(max(fogColor.r, fogColor.g), fogColor.b);
|
||||
// Prevent zero division.
|
||||
if (fogColorMax < 0.0000001) fogColorMax = 1.0;
|
||||
// For high clarity (light fog) we tint the fog color.
|
||||
// For this to not make the fog color artificially dark we need to normalize using the
|
||||
// fog color's brightest value. We then blend our base color with this to make the fog.
|
||||
col = mix(fogColor * pow(fogColor / fogColorMax, vec4(2.0 * clarity)), col, clarity);
|
||||
col = vec4(col.rgb, base.a);
|
||||
|
||||
gl_FragData[0] = col;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
uniform mat4 mWorld;
|
||||
uniform vec3 dayLight;
|
||||
uniform float animationTimer;
|
||||
uniform lowp vec4 emissiveColor;
|
||||
uniform lowp vec4 materialColor;
|
||||
|
||||
varying vec3 vNormal;
|
||||
varying vec3 vPosition;
|
||||
|
@ -106,7 +106,7 @@ vec3 getDirectLightScatteringAtGround(vec3 v_LightDirection)
|
|||
|
||||
void main(void)
|
||||
{
|
||||
varTexCoord = (mTexture * inTexCoord0).st;
|
||||
varTexCoord = (mTexture * vec4(inTexCoord0.xy, 1.0, 1.0)).st;
|
||||
gl_Position = mWorldViewProj * inVertexPosition;
|
||||
|
||||
vPosition = gl_Position.xyz;
|
||||
|
@ -130,7 +130,7 @@ void main(void)
|
|||
vec4 color = inVertexColor;
|
||||
#endif
|
||||
|
||||
color *= emissiveColor;
|
||||
color *= materialColor;
|
||||
|
||||
// The alpha gives the ratio of sunlight in the incoming light.
|
||||
nightRatio = 1.0 - color.a;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
uniform lowp vec4 emissiveColor;
|
||||
uniform lowp vec4 materialColor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = emissiveColor;
|
||||
gl_FragColor = materialColor;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,9 @@ 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;
|
||||
}
|
||||
return result / samples;
|
||||
// We use the depth map to approximate the effect of depth on the light intensity.
|
||||
// The exponent was chosen based on aesthetic preference.
|
||||
return result / samples * pow(texture2D(depthmap, uv).r, 128.0);
|
||||
}
|
||||
|
||||
vec3 getDirectLightScatteringAtGround(vec3 v_LightDirection)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue