mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Remove volumetrics stuff and some changes
This commit is contained in:
parent
da1a688493
commit
1bf1d0b2ff
21 changed files with 311 additions and 857 deletions
|
@ -1,87 +0,0 @@
|
|||
#define cloudsTexture texture0
|
||||
#define sceneTexture texture1
|
||||
#define depthmap texture2
|
||||
|
||||
uniform sampler2D cloudsTexture;
|
||||
uniform sampler2D sceneTexture;
|
||||
uniform sampler2D depthmap;
|
||||
uniform vec2 texelSize0;
|
||||
|
||||
uniform vec3 dayLight;
|
||||
uniform vec3 cloudColor;
|
||||
|
||||
varying vec2 screenspaceCoordinate;
|
||||
varying vec3 relativePosition;
|
||||
varying vec3 viewDirection;
|
||||
varying vec3 sunTint;
|
||||
varying float auroraFactor;
|
||||
|
||||
uniform vec3 cameraOffset;
|
||||
uniform vec3 cameraPosition;
|
||||
|
||||
uniform float cameraNear;
|
||||
uniform float cameraFar;
|
||||
|
||||
uniform float cloudHeight;
|
||||
uniform float cloudThickness;
|
||||
|
||||
float getDepth(vec2 screenspacePosition) {
|
||||
float depth = texture2D(depthmap, screenspacePosition * 0.5 + 0.5).r;
|
||||
return cameraNear * cameraFar / (cameraFar + depth * (cameraNear - cameraFar));
|
||||
}
|
||||
|
||||
vec4 sampleClouds(vec2 uv) {
|
||||
vec4 cloudsKey = texture2D(cloudsTexture, uv);
|
||||
|
||||
//const vec3 darkColor = vec3(0.05, 0.1, 0.2);
|
||||
vec3 darkColor = vec3(0.2, 0.4, 0.8) * dayLight;
|
||||
const vec3 auroraDark = vec3(0., 0.5, 0.5);
|
||||
const vec3 auroraBright = vec3(0., 0.5, .0);
|
||||
|
||||
//const vec3 auroraDark = vec3(0.);
|
||||
//const vec3 auroraBright = vec3(0.);
|
||||
|
||||
return vec4(
|
||||
mix(auroraDark, auroraBright, cloudsKey.b) * cloudsKey.b * auroraFactor +
|
||||
cloudsKey.r * cloudColor * (darkColor * max(0., 1. - cloudsKey.g) + dayLight * sunTint * cloudsKey.g),
|
||||
cloudsKey.r);
|
||||
}
|
||||
|
||||
vec4 getClouds(vec2 uv) {
|
||||
#if (VOLUMETRICS_UNDERSAMPLING <= 1)
|
||||
return sampleClouds(uv);
|
||||
#else
|
||||
return
|
||||
sampleClouds(uv - texelSize0 * vec2(-1.0, -1.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2( 0.0, -1.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2( 1.0, -1.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2(-1.0, 0.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2( 0.0, 0.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2( 1.0, 0.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2(-1.0, 1.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2( 0.0, 1.0)) / 9.0 +
|
||||
sampleClouds(uv - texelSize0 * vec2( 1.0, 1.0)) / 9.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 viewVec = normalize(relativePosition);
|
||||
|
||||
vec3 position = cameraOffset + cameraPosition;
|
||||
|
||||
float depth = getDepth(screenspaceCoordinate) / normalize(viewDirection).z;
|
||||
float bottomPlaneIntersect = max((cloudHeight - cameraPosition.y) / viewVec.y, 0.);
|
||||
float topPlaneIntersect = max((cloudHeight + cloudThickness - cameraPosition.y) / viewVec.y, 0.);
|
||||
float minPlane = min(bottomPlaneIntersect, topPlaneIntersect);
|
||||
|
||||
vec4 sceneColor = texture2D(sceneTexture, screenspaceCoordinate * 0.5 + 0.5);
|
||||
|
||||
if (depth > minPlane) {
|
||||
vec4 finalColor = getClouds(screenspaceCoordinate * 0.5 + 0.5);
|
||||
|
||||
gl_FragColor = vec4(sceneColor.rgb * (1. - finalColor.a) + finalColor.rgb, 1.);
|
||||
} else {
|
||||
gl_FragColor = sceneColor;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
uniform mat4 mCameraProjInv;
|
||||
uniform mat4 mCameraView;
|
||||
uniform vec3 v_LightDirection;
|
||||
uniform float f_timeofday;
|
||||
|
||||
varying vec3 relativePosition;
|
||||
varying vec3 viewDirection;
|
||||
varying vec2 screenspaceCoordinate;
|
||||
varying vec3 sunTint;
|
||||
varying float auroraFactor;
|
||||
|
||||
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.))));
|
||||
}
|
||||
|
||||
// custom smoothstep implementation because it's not defined in glsl1.2
|
||||
// https://docs.gl/sl4/smoothstep
|
||||
float mtsmoothstep(in float edge0, in float edge1, in float x)
|
||||
{
|
||||
float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
|
||||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 p = mCameraProjInv * inVertexPosition;
|
||||
viewDirection = p.xyz / p.w;
|
||||
relativePosition = (p.xyz / p.w) * mat3(mCameraView);
|
||||
screenspaceCoordinate = inVertexPosition.xy;
|
||||
|
||||
auroraFactor = 1. - mtsmoothstep(0.13, 0.15, f_timeofday) * mtsmoothstep(0.87, 0.85, f_timeofday);
|
||||
|
||||
float tintFactor = mtsmoothstep(0.21, 0.24, f_timeofday) * mtsmoothstep(0.793, 0.753, f_timeofday);
|
||||
|
||||
sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), tintFactor);
|
||||
|
||||
gl_Position = inVertexPosition;
|
||||
}
|
|
@ -59,7 +59,7 @@ varying highp vec3 eyeVec;
|
|||
varying float nightRatio;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
#if ((defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS) && ENABLE_WAVING_WATER) || defined(ENABLE_BUMPMAPS))
|
||||
#if ((defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS)) || defined(ENABLE_BUMPMAPS))
|
||||
vec4 perm(vec4 x)
|
||||
{
|
||||
return mod(((x * 34.0) + 1.0) * x, 289.0);
|
||||
|
@ -450,7 +450,7 @@ void main(void)
|
|||
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.2 * vec2((fx1y0 - fx0y0) / dr.x, (fx0y1 - fx0y0) / dr.y) + 0.1 * gnoise(vec3(2.0 * uv / texelSize0, 0.0)).xy;
|
||||
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));
|
||||
|
@ -529,7 +529,14 @@ void main(void)
|
|||
vec3 viewVec = normalize(worldPosition + cameraOffset - cameraPosition);
|
||||
|
||||
// Water reflections
|
||||
#if (defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS) && ENABLE_WAVING_WATER)
|
||||
#if (defined(MATERIAL_WAVING_LIQUID) && defined(ENABLE_WATER_REFLECTIONS))
|
||||
|
||||
#if !ENABLE_WAVING_WATER
|
||||
#define WATER_WAVE_HEIGHT 0.5
|
||||
#define WATER_WAVE_SPEED 5.0
|
||||
#define WATER_WAVE_LENGTH 10.0
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
@ -560,7 +567,8 @@ void main(void)
|
|||
#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));
|
||||
// This intensity is a placeholder and should be replaced by proper specular maps.
|
||||
float intensity = 4.0 * min(1.0, length(varColor.rgb * base.rgb));
|
||||
const float specular_exponent = 5.0;
|
||||
const float fresnel_exponent = 4.0;
|
||||
|
||||
|
@ -588,6 +596,8 @@ void main(void)
|
|||
// Note: clarity = (1 - fogginess)
|
||||
float clarity = clamp(fogShadingParameter
|
||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||
|
||||
#ifdef ENABLE_TINTED_FOG
|
||||
float fogColorMax = max(max(fogColor.r, fogColor.g), fogColor.b);
|
||||
// Prevent zero division.
|
||||
if (fogColorMax < 0.0000001) fogColorMax = 1.0;
|
||||
|
@ -595,6 +605,10 @@ void main(void)
|
|||
// 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);
|
||||
#else
|
||||
col = mix(fogColor, col, clarity);
|
||||
#endif
|
||||
|
||||
col = vec4(col.rgb, base.a);
|
||||
|
||||
gl_FragData[0] = col;
|
||||
|
|
|
@ -21,7 +21,6 @@ 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,8 +432,8 @@ void main(void)
|
|||
// calculate fragment color from components:
|
||||
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) * (1.0 - shadow_tint)) + // filtered texture color
|
||||
(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
|
||||
}
|
||||
#endif
|
||||
|
@ -450,13 +449,9 @@ void main(void)
|
|||
// Note: clarity = (1 - fogginess)
|
||||
float clarity = clamp(fogShadingParameter
|
||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||
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 = mix(fogColor, col, clarity);
|
||||
|
||||
col = vec4(col.rgb, base.a);
|
||||
|
||||
gl_FragData[0] = col;
|
||||
|
|
22
client/shaders/soft_clouds/opengl_fragment.glsl
Normal file
22
client/shaders/soft_clouds/opengl_fragment.glsl
Normal file
|
@ -0,0 +1,22 @@
|
|||
uniform lowp vec4 fogColor;
|
||||
uniform float fogDistance;
|
||||
uniform float fogShadingParameter;
|
||||
varying highp vec3 eyeVec;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
varying lowp vec3 normal;
|
||||
uniform vec3 v_LightDirection;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
float brightness = max(dot(-v_LightDirection, normal), 0.0);
|
||||
vec4 col = varColor;
|
||||
|
||||
col.rgb *= brightness;
|
||||
|
||||
float clarity = clamp(fogShadingParameter
|
||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||
col.rgb = mix(fogColor.rgb, col.rgb, clarity);
|
||||
|
||||
gl_FragColor = col;
|
||||
}
|
24
client/shaders/soft_clouds/opengl_vertex.glsl
Normal file
24
client/shaders/soft_clouds/opengl_vertex.glsl
Normal file
|
@ -0,0 +1,24 @@
|
|||
uniform lowp vec4 materialColor;
|
||||
|
||||
varying lowp vec4 varColor;
|
||||
|
||||
varying highp vec3 eyeVec;
|
||||
|
||||
varying lowp vec3 normal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = mWorldViewProj * inVertexPosition;
|
||||
|
||||
#ifdef GL_ES
|
||||
vec4 color = inVertexColor.bgra;
|
||||
#else
|
||||
vec4 color = inVertexColor;
|
||||
#endif
|
||||
|
||||
color *= materialColor;
|
||||
varColor = color;
|
||||
normal = inVertexNormal;
|
||||
|
||||
eyeVec = -(mWorldView * inVertexPosition).xyz;
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
#define depthmap texture0
|
||||
#define noiseTexture texture1
|
||||
#define noiseTextureCoarse texture2
|
||||
|
||||
#define PROBING_ITERATIONS 30
|
||||
#define ITERATIONS 50
|
||||
#define LIGHT_ITERATIONS 3
|
||||
#define AURORA_ITERATIONS 80
|
||||
|
||||
// See clouds.cpp
|
||||
#define CLOUD_SIZE 640.0
|
||||
|
||||
uniform sampler2D depthmap;
|
||||
uniform sampler2D noiseTexture;
|
||||
uniform sampler2D noiseTextureCoarse;
|
||||
|
||||
uniform vec2 texelSize0;
|
||||
|
||||
uniform float cloudHeight;
|
||||
uniform float cloudThickness;
|
||||
uniform float cloudDensity;
|
||||
|
||||
varying vec3 relativePosition;
|
||||
varying vec3 viewDirection;
|
||||
uniform vec3 cameraOffset;
|
||||
uniform vec3 cameraPosition;
|
||||
|
||||
uniform float cameraNear;
|
||||
uniform float cameraFar;
|
||||
|
||||
uniform vec2 cloudOffset;
|
||||
uniform float cloudRadius;
|
||||
|
||||
varying vec2 screenspaceCoordinate;
|
||||
varying float sunStrength;
|
||||
|
||||
uniform float fogDistance;
|
||||
uniform float fogShadingParameter;
|
||||
|
||||
uniform vec3 v_LightDirection;
|
||||
|
||||
uniform float animationTimer;
|
||||
|
||||
// Derived From http://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
|
||||
// and https://www.shadertoy.com/view/MslGR8 (5th one starting from the bottom)
|
||||
// NOTE: `frag_coord` is in pixels (i.e. not normalized UV).
|
||||
float screenSpaceDither(highp vec2 frag_coord)
|
||||
{
|
||||
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
|
||||
highp float dither = dot(vec2(171.0, 231.0), frag_coord);
|
||||
dither = fract(dither / 103.0);
|
||||
|
||||
return dither;
|
||||
}
|
||||
|
||||
// custom smoothstep implementation because it's not defined in glsl1.2
|
||||
// https://docs.gl/sl4/smoothstep
|
||||
float mtsmoothstep(in float edge0, in float edge1, in float x)
|
||||
{
|
||||
float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
|
||||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
float toLinearDepth(float depth)
|
||||
{
|
||||
return cameraNear * cameraFar / (cameraFar + depth * (cameraNear - cameraFar));
|
||||
}
|
||||
|
||||
float getDepth(vec2 screenspacePosition)
|
||||
{
|
||||
return texture2D(depthmap, screenspacePosition * 0.5 + 0.5).r;
|
||||
}
|
||||
|
||||
float noise(vec3 p)
|
||||
{
|
||||
float y = floor(p.y);
|
||||
float f1 = texture2D(noiseTexture, p.xz / 256. + y * 0.2).r;
|
||||
float f2 = texture2D(noiseTexture, p.xz / 256. + y * 0.2 + 0.2).r;
|
||||
return mix(f1, f2, fract(p.y));
|
||||
}
|
||||
|
||||
float fnoise(vec3 p)
|
||||
{
|
||||
return noise(p * 4.) * 0.5 + noise(p * 8.) * 0.25;
|
||||
}
|
||||
|
||||
float fnoise3(vec3 p)
|
||||
{
|
||||
return noise(p * 4.) * 0.5 + noise(p * 8.) * 0.25 + noise(p * 16.) * 0.125;
|
||||
}
|
||||
|
||||
float getAuroraDensity(vec3 position)
|
||||
{
|
||||
float density = pow(max(0., 1. - 10. * abs(fnoise3(vec3(position.x * 0.25, animationTimer, position.z * 0.25)) - 0.5)), 4.);
|
||||
return 0.7 * density * mtsmoothstep(0.0, 0.05, position.y - 1.) * pow(1. - mtsmoothstep(0.05, 2.0, position.y - 1.), 4.);
|
||||
}
|
||||
|
||||
float getCoarse(vec3 position) {
|
||||
return texture2D(noiseTextureCoarse, (position.xz - cloudOffset) * 0.5 / CLOUD_SIZE / cloudRadius).r;
|
||||
}
|
||||
|
||||
float getDensity(vec3 position)
|
||||
{
|
||||
float density = texture2D(noiseTextureCoarse, (position.xz - cloudOffset) * 0.5 / CLOUD_SIZE / cloudRadius).r *
|
||||
mtsmoothstep(0.0, cloudThickness * 0.2, position.y - cloudHeight) *
|
||||
(1.0 - mtsmoothstep(cloudThickness * 0.5, cloudThickness, position.y - cloudHeight));
|
||||
|
||||
density = max(0., density - 0.5 * fnoise(position * 0.005));
|
||||
|
||||
return 0.04 * density;
|
||||
}
|
||||
|
||||
float getBrightness(vec3 position, float lightDistance)
|
||||
{
|
||||
float density = 0.;
|
||||
for (int i = 1; i <= LIGHT_ITERATIONS; i++) {
|
||||
vec3 rayPosition = position - v_LightDirection * lightDistance * float(i) / float(LIGHT_ITERATIONS);
|
||||
|
||||
density += getDensity(rayPosition) * float(lightDistance) / float(LIGHT_ITERATIONS);
|
||||
}
|
||||
return exp(-density);
|
||||
}
|
||||
|
||||
float blend(float A, float B, float alphaA, float alphaB)
|
||||
{
|
||||
float alphaC = alphaA + (1. - alphaA) * alphaB;
|
||||
return (alphaA * A + (1. - alphaA) * alphaB * B) / alphaC;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 viewVec = normalize(relativePosition);
|
||||
|
||||
vec3 position = cameraOffset + cameraPosition;
|
||||
|
||||
float depth = toLinearDepth(getDepth(screenspaceCoordinate)) / normalize(viewDirection).z;
|
||||
float bottomPlaneIntersect = clamp((cloudHeight - cameraPosition.y) / viewVec.y, 0., 4. * fogDistance);
|
||||
float topPlaneIntersect = clamp((cloudHeight + cloudThickness - cameraPosition.y) / viewVec.y, 0., 4. * fogDistance);
|
||||
|
||||
#if (VOLUMETRICS_UNDERSAMPLING <= 1)
|
||||
bottomPlaneIntersect = min(depth, bottomPlaneIntersect);
|
||||
topPlaneIntersect = min(depth, topPlaneIntersect);
|
||||
#else
|
||||
if ((bottomPlaneIntersect > depth + 5.0) != (topPlaneIntersect > depth + 5.0)) {
|
||||
bottomPlaneIntersect = min(depth, bottomPlaneIntersect);
|
||||
topPlaneIntersect = min(depth, topPlaneIntersect);
|
||||
}
|
||||
#endif
|
||||
|
||||
float startDepth = min(bottomPlaneIntersect, topPlaneIntersect);
|
||||
float endDepth = max(bottomPlaneIntersect, topPlaneIntersect);
|
||||
|
||||
float bias = screenSpaceDither(gl_FragCoord.xy + animationTimer * 2400.0);
|
||||
|
||||
vec3 color = vec3(0.);
|
||||
|
||||
float density = 0.;
|
||||
|
||||
float auroraStartDepth = min(max(0., 1.0 / viewVec.y), 8.);
|
||||
float auroraEndDepth = min(max(0., 3.0 / viewVec.y), 8.);
|
||||
float rawDepth = getDepth(screenspaceCoordinate);
|
||||
|
||||
if (auroraEndDepth - auroraStartDepth > 0.1 && rawDepth >= 1.0) {
|
||||
for (int i = 0; i < AURORA_ITERATIONS; i++) {
|
||||
vec3 rayPosition = viewVec * (auroraStartDepth + (auroraEndDepth - auroraStartDepth) * (float(i) + bias) / float(AURORA_ITERATIONS));
|
||||
|
||||
float localDensity = getAuroraDensity(rayPosition);
|
||||
|
||||
localDensity *= 1.0 - mtsmoothstep(4.0, 8.0, length(rayPosition));
|
||||
|
||||
density += localDensity;
|
||||
}
|
||||
}
|
||||
|
||||
color.b = density * (auroraEndDepth - auroraStartDepth) / float(AURORA_ITERATIONS);
|
||||
|
||||
float sunlightContribution = 0.;
|
||||
float alpha = 0.;
|
||||
float outScatter = 2. * (dot(v_LightDirection, viewVec) * 0.5 + 0.5);
|
||||
float forwardScatter = 1. + 2. * pow(min(dot(v_LightDirection, viewVec), 0.), 4.);
|
||||
density = 0.;
|
||||
|
||||
float fogDepth = min(4. * fogDistance, startDepth + 2000.);
|
||||
endDepth = min(endDepth, fogDepth);
|
||||
|
||||
float dx = (endDepth - startDepth) / float(ITERATIONS);
|
||||
float lightDistance = cloudThickness * 0.5;
|
||||
|
||||
if (endDepth - startDepth > 0.1) {
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
vec3 rayPosition = cameraPosition + viewVec * (startDepth + (endDepth - startDepth) * (float(i) + bias) / float(ITERATIONS));
|
||||
|
||||
float localDensity = getDensity(rayPosition) * dx;
|
||||
|
||||
if (localDensity < 0.0001) continue;
|
||||
|
||||
float clarity = clamp(fogShadingParameter - fogShadingParameter * length(rayPosition - cameraPosition) / (fogDepth), 0.0, 1.0);
|
||||
float outScatterContribution = exp(-0.5 * outScatter * localDensity);
|
||||
float brightness = getBrightness(rayPosition, lightDistance) * forwardScatter * outScatterContribution * sunStrength + (1. - outScatterContribution);
|
||||
sunlightContribution = blend(sunlightContribution, brightness, 1. - exp(-density), 1. - exp(-localDensity));
|
||||
alpha = blend(alpha, clarity, 1. - exp(-density), 1. - exp(-localDensity));
|
||||
|
||||
density += localDensity;
|
||||
|
||||
if (density > 10.0) break;
|
||||
}
|
||||
}
|
||||
|
||||
color.r = (1. - exp(-density)) * alpha;
|
||||
color.g = sunlightContribution;
|
||||
color.b *= exp(-density);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
uniform mat4 mCameraProjInv;
|
||||
uniform mat4 mCameraView;
|
||||
uniform float f_timeofday;
|
||||
|
||||
varying vec3 relativePosition;
|
||||
varying vec3 viewDirection;
|
||||
|
||||
varying vec2 screenspaceCoordinate;
|
||||
varying float sunStrength;
|
||||
|
||||
float mtsmoothstep(in float edge0, in float edge1, in float x)
|
||||
{
|
||||
float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
|
||||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
screenspaceCoordinate = inVertexPosition.xy;
|
||||
vec4 p = mCameraProjInv * inVertexPosition;
|
||||
viewDirection = p.xyz / p.w;
|
||||
relativePosition = (p.xyz / p.w) * mat3(mCameraView);
|
||||
|
||||
if (f_timeofday < 0.21) {
|
||||
sunStrength =
|
||||
(1.0 - mtsmoothstep(0.18, 0.21, f_timeofday));
|
||||
} else if (f_timeofday >= 0.793) {
|
||||
sunStrength =
|
||||
mtsmoothstep(0.793, 0.823, f_timeofday);
|
||||
} else {
|
||||
sunStrength =
|
||||
mtsmoothstep(0.21, 0.26, f_timeofday) *
|
||||
(1.0 - mtsmoothstep(0.743, 0.793, f_timeofday));
|
||||
}
|
||||
|
||||
gl_Position = inVertexPosition;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue