add ambient light that takes clouds into account, clean up Deferred programs, clean up unused texture calls for LUT, make sure fog and stuff are all using the right LUT colors. fix clouds not being in reflections

thats a good days work
This commit is contained in:
Xonk
2023-06-26 00:33:31 -04:00
parent c46ac275df
commit deb49da793
20 changed files with 219 additions and 309 deletions

View File

@ -1,29 +1,22 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#include "lib/settings.glsl"
#include "lib/res_params.glsl"
flat varying vec3 ambientUp;
flat varying vec3 ambientLeft;
flat varying vec3 ambientRight;
flat varying vec3 ambientB;
flat varying vec3 ambientF;
flat varying vec3 ambientDown;
flat varying vec3 zenithColor;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec3 averageSkyCol;
flat varying vec3 sunColor;
flat varying vec3 sunColorCloud;
flat varying vec3 moonColor;
flat varying vec3 moonColorCloud;
flat varying vec3 lightSourceColor;
flat varying vec3 avgSky;
flat varying vec3 zenithColor;
flat varying vec2 tempOffsets;
flat varying float exposure;
flat varying float avgBrightness;
flat varying float exposureF;
flat varying float rodExposure;
flat varying float fogAmount;
flat varying float VFAmount;
flat varying float avgL2;
flat varying float centerDepth;
@ -31,64 +24,28 @@ uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D depthtex0;
flat varying vec3 WsunVec;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform vec2 texelSize;
uniform float rainStrength;
uniform float sunElevation;
uniform float nightVision;
uniform float eyeAltitude;
uniform float near;
uniform float far;
uniform float frameTime;
uniform float eyeAltitude;
uniform int frameCounter;
uniform float rainStrength;
// uniform int worldTime;
vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition);
#include "lib/sky_gradient.glsl"
#include "/lib/util.glsl"
#include "/lib/ROBOBO_sky.glsl"
vec3 rodSample(vec2 Xi)
{
float r = sqrt(1.0f - Xi.x*Xi.y);
float phi = 2 * 3.14159265359 * Xi.y;
return normalize(vec3(cos(phi) * r, sin(phi) * r, Xi.x)).xzy;
}
vec3 cosineHemisphereSample(vec2 Xi)
{
float r = sqrt(Xi.x);
float theta = 2.0 * 3.14159265359 * Xi.y;
float x = r * cos(theta);
float y = r * sin(theta);
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter)
{
float alpha = float(sampleNumber+jitter)/nb;
float angle = (jitter+alpha) * (nbRot * 6.28);
float ssR = alpha;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
@ -106,42 +63,46 @@ void main() {
gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize;
gl_Position.xy = gl_Position.xy*2.-1.0;
tempOffsets = R2_samples(frameCounter%10000);
///////////////////////////////////
/// --- AMBIENT LIGHT STUFF --- ///
///////////////////////////////////
ambientUp = vec3(0.0);
ambientDown = vec3(0.0);
ambientLeft = vec3(0.0);
ambientRight = vec3(0.0);
ambientB = vec3(0.0);
ambientF = vec3(0.0);
avgSky = vec3(0.0);
//Integrate sky light for each block side
int maxIT = 20;
averageSkyCol_Clouds = vec3(0.0);
averageSkyCol = vec3(0.0);
vec2 sample3x3[9] = vec2[](
vec2(-1.0, 0.0),
vec2( 0.0, 0.0),
vec2( 1.0, 0.0),
vec2(-1.0, -0.5),
vec2( 0.0, -0.5),
vec2( 1.0, -0.5),
vec2(-1.0, -1.0),
vec2( 0.0, -1.0),
vec2( 1.0, -1.0)
);
// sample in a 3x3 pattern to get a good area for average color
vec3 pos = normalize(vec3(0,1,0));
int maxIT = 9;
for (int i = 0; i < maxIT; i++) {
vec2 ij = R2_samples((frameCounter%1000)*maxIT+i);
vec3 pos = normalize(rodSample(ij));
pos.xy += normalize(sample3x3[i] * vec2(1.0,0.5));
averageSkyCol_Clouds += 2.0*skyCloudsFromTex(pos,colortex4).rgb/maxIT/150.;
pos = normalize(vec3(0,1,0));
}
// only need to sample one spot for this
averageSkyCol += 2.0*skyFromTex(normalize(vec3(0.0,1.0,0.0)),colortex4).rgb/150.;
vec3 samplee = 1.72*skyFromTex(pos,colortex4).rgb/maxIT/150.;
avgSky += samplee/1.72;
ambientUp += samplee*(pos.y+abs(pos.x)/7.+abs(pos.z)/7.);
ambientLeft += samplee*(clamp(-pos.x,0.0,1.0)+clamp(pos.y/7.,0.0,1.0)+abs(pos.z)/7.);
ambientRight += samplee*(clamp(pos.x,0.0,1.0)+clamp(pos.y/7.,0.0,1.0)+abs(pos.z)/7.);
ambientB += samplee*(clamp(pos.z,0.0,1.0)+abs(pos.x)/7.+clamp(pos.y/7.,0.0,1.0));
ambientF += samplee*(clamp(-pos.z,0.0,1.0)+abs(pos.x)/7.+clamp(pos.y/7.,0.0,1.0));
ambientDown += samplee*(clamp(pos.y/6.,0.0,1.0)+abs(pos.x)/7.+abs(pos.z)/7.);
/*
ambientUp += samplee*(pos.y);
ambientLeft += samplee*(clamp(-pos.x,0.0,1.0));
ambientRight += samplee*(clamp(pos.x,0.0,1.0));
ambientB += samplee*(clamp(pos.z,0.0,1.0));
ambientF += samplee*(clamp(-pos.z,0.0,1.0));
ambientDown += samplee*(clamp(pos.y/6.,0.0,1.0))*0;
*/
}
////////////////////////////////////////
/// --- SUNLIGHT/MOONLIGHT STUFF --- ///
////////////////////////////////////////
vec2 planetSphere = vec2(0.0);
vec3 sky = vec3(0.0);
@ -156,56 +117,19 @@ void main() {
sunColor = calculateAtmosphere(vec3(0.0), sunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.0);
sunColor = sunColorBase/4000. * skyAbsorb;
skyAbsorb = vec3(1.0);
float dSun = 0.03;
vec3 modSunVec = sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0);
vec3 modSunVec2 = sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0);
if (modSunVec2.y > modSunVec.y) modSunVec = modSunVec2;
sunColorCloud = calculateAtmosphere(vec3(0.0), modSunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.);
sunColorCloud = sunColorBase/4000. * skyAbsorb ;
skyAbsorb = vec3(1.0);
moonColor = calculateAtmosphere(vec3(0.0), -sunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.5);
moonColor = moonColorBase/4000.0*skyAbsorb;
skyAbsorb = vec3(1.0);
modSunVec = -sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0);
modSunVec2 = -sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0);
if (modSunVec2.y > modSunVec.y) modSunVec = modSunVec2;
moonColorCloud = calculateAtmosphere(vec3(0.0), modSunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.5);
moonColorCloud = moonColorBase/4000.0*0.55;
// #ifndef CLOUDS_SHADOWS
// sunColor *= (1.0-rainStrength*vec3(0.96,0.95,0.94));
// moonColor *= (1.0-rainStrength*vec3(0.96,0.95,0.94));
// #endif
lightSourceColor = sunVis >= 1e-5 ? sunColor * sunVis : moonColor * moonVis;
float lightDir = float( sunVis >= 1e-5)*2.0-1.0;
//Fake bounced sunlight
vec3 bouncedSun = lightSourceColor*0.1/5.0*0.5*clamp(lightDir*sunVec.y,0.0,1.0)*clamp(lightDir*sunVec.y,0.0,1.0);
vec3 cloudAmbientSun = (sunColorCloud)*0.007;
vec3 cloudAmbientMoon = (moonColorCloud)*0.007;
ambientUp += bouncedSun*clamp(-lightDir*sunVec.y+4.,0.,4.0) + cloudAmbientSun*clamp(sunVec.y+2.,0.,4.0) + cloudAmbientMoon*clamp(-sunVec.y+2.,0.,4.0);
ambientLeft += bouncedSun*clamp(lightDir*sunVec.x+4.,0.0,4.) + cloudAmbientSun*clamp(-sunVec.x+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(sunVec.x+2.,0.0,4.)*0.7;
ambientRight += bouncedSun*clamp(-lightDir*sunVec.x+4.,0.0,4.) + cloudAmbientSun*clamp(sunVec.x+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(-sunVec.x+2.,0.0,4.)*0.7;
ambientB += bouncedSun*clamp(-lightDir*sunVec.z+4.,0.0,4.) + cloudAmbientSun*clamp(sunVec.z+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(-sunVec.z+2.,0.0,4.)*0.7;
ambientF += bouncedSun*clamp(lightDir*sunVec.z+4.,0.0,4.) + cloudAmbientSun*clamp(-sunVec.z+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(sunVec.z+2.,0.0,4.)*0.7;
ambientDown += bouncedSun*clamp(lightDir*sunVec.y+4.,0.0,4.)*0.7 + cloudAmbientSun*clamp(-sunVec.y+2.,0.0,4.)*0.5 + cloudAmbientMoon*clamp(sunVec.y+2.,0.0,4.)*0.5;
avgSky += bouncedSun*5.;
vec3 rainNightBoost = moonColorCloud*0.005;
ambientUp += rainNightBoost;
ambientLeft += rainNightBoost;
ambientRight += rainNightBoost;
ambientB += rainNightBoost;
ambientF += rainNightBoost;
ambientDown += rainNightBoost;
avgSky += rainNightBoost;
//////////////////////////////
/// --- EXPOSURE STUFF --- ///
//////////////////////////////
float avgLuma = 0.0;
float m2 = 0.0;