WIP nether shader

This commit is contained in:
Xonk 2023-07-26 02:10:18 -04:00
parent a70542f2c4
commit d4e8104388
6 changed files with 80 additions and 169 deletions

View File

@ -95,8 +95,6 @@ vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) { vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) {
const int jSteps = 4; const int jSteps = 4;
vec3 sunvec2 = sunVector;
vec3 viewPosition = (sky_planetRadius + eyeAltitude) * upVector; vec3 viewPosition = (sky_planetRadius + eyeAltitude) * upVector;
vec2 aid = rsi(viewPosition, viewVector, sky_atmosphereRadius); vec2 aid = rsi(viewPosition, viewVector, sky_atmosphereRadius);
@ -111,9 +109,8 @@ vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 s
vec3 increment = viewVector * stepSize; vec3 increment = viewVector * stepSize;
vec3 position = viewVector * sd.x + viewPosition; vec3 position = viewVector * sd.x + viewPosition;
position += increment * (0.34*noise); position += increment * (0.34*noise);
vec2 phaseSun = (pow(sky_phase(dot(viewVector, sunVector ), 0.6)*3, vec2(2)) + sky_phase(dot(viewVector, sunVector ), 0.8))/2;
// phaseSun = sky_phase(dot(viewVector, sunVector ), 0.8); vec2 phaseSun = sky_phase(dot(viewVector, sunVector ), 0.8);
vec2 phaseMoon = sky_phase(dot(viewVector, moonVector), sky_mieg); vec2 phaseMoon = sky_phase(dot(viewVector, moonVector), sky_mieg);
vec3 scatteringSun = vec3(0.0); vec3 scatteringSun = vec3(0.0);
@ -122,11 +119,8 @@ vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 s
transmittance = vec3(1.0); transmittance = vec3(1.0);
float high_sun = clamp(pow(sunVector.y+0.6,5),0.0,1.0) * 3.0; // make sunrise less blue, and allow sunset to be bluer
// float low_sun = clamp(pow(1.0-sunVector.y,10.0) + 1.0,1.0, 2.0); float low_sun = clamp(((1.0-abs(sunVector.y))*3.) - high_sun,1.0,2.0) ;
float high_sun = clamp(pow(sunvec2.y+0.6,5),0.0,1.0) * 3.0; // make sunrise less blue, and allow sunset to be bluer
float low_sun = clamp(((1.0-abs(sunvec2.y))*3.) - high_sun,1.0,2.0) ;
for (int i = 0; i < iSteps; ++i, position += increment) { for (int i = 0; i < iSteps; ++i, position += increment) {
vec3 density = sky_density(length(position)); vec3 density = sky_density(length(position));
@ -147,6 +141,6 @@ vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 s
} }
vec3 scattering = scatteringSun * sunColorBase + scatteringAmbient * background + scatteringMoon*moonColorBase ; vec3 scattering = scatteringSun * sunColorBase + scatteringAmbient * background + scatteringMoon*moonColorBase ;
// scattering = vec3(0,high_sun*255.,0);
return scattering; return scattering;
} }

View File

@ -1,39 +1,3 @@
///////////////// POSITION
///////////////// POSITION
///////////////// POSITION
vec3 ManualLightPos = vec3(ORB_X, ORB_Y, ORB_Z);
vec3 lighting_pos = vec3(0, -1, 0);
vec3 lightSource = normalize(lighting_pos);
vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
vec3 WsunVec = normalize(mat3(gbufferModelViewInverse) * viewspace_sunvec);
///////////////// COLOR
///////////////// COLOR
///////////////// COLOR
vec3 LightSourceColor(){
vec3 Color = vec3(1.0,0.75,0.5);
return Color;
}
///////////////// SHAPE
///////////////// SHAPE
///////////////// SHAPE
vec3 LightSourceShape(vec3 WorldPos){
vec3 Shapes = vec3(0.0);
vec3 Origin = WorldPos ;
return Shapes;
}
float densityAtPosFog(in vec3 pos){ float densityAtPosFog(in vec3 pos){
pos /= 18.; pos /= 18.;
pos.xz *= 0.5; pos.xz *= 0.5;
@ -50,119 +14,77 @@ float densityAtPosFog(in vec3 pos){
float cloudVol(in vec3 pos){ float cloudVol(in vec3 pos){
vec3 samplePos = pos*vec3(1.0,1./24.,1.0); vec3 samplePos = pos*vec3(1.0,1./48.,1.0);
// vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0);
// float fog_shape = 1-densityAtPosFog(samplePos * 16.0);
// float fog_eroded = 1-densityAtPosFog(samplePos2 * (200 + fog_shape*25));
// float finalfog = clamp( (fog_shape*2.0 - fog_eroded*0.3) - 1.5, 0.0, 1.0); float finalfog = exp(max(100-pos.y,0.0) / -15) ;
float finalfog = 1-exp(max(samplePos.y - 60,0.0) / -1); float floorfog = pow(exp(max(pos.y-30,0.0) / -3.0),2);
float wind = pow(max(pos.y - 30,0.0) / 15.0,2.1);
float noise_1 = pow(1-texture2D(noisetex, samplePos.xz/256.0 + wind/200).b,2.0);
float noise_2 = pow(densityAtPosFog(samplePos*256 - frameTimeCounter*10 + wind*10),1) * 0.75 +0.25;
float rooffog = exp(max(100-pos.y,0.0) / -5);
finalfog = max(finalfog - noise_1*noise_2 - rooffog, max(floorfog -noise_2*0.2,0.0));
return finalfog; return finalfog;
} }
// float GetCloudShadow(vec3 WorldPos, vec3 LightPos, float noise){ vec4 GetVolumetricFog(
// float Shadow = 0.0; vec3 fragpos,
float dither
// for (int i=0; i < 3; i++){ ){
// // vec3 shadowSamplePos = WorldPos - LightPos.y/abs(LightPos.y) * (0.25 + pow(i,0.75)*0.25);
// vec3 shadowSamplePos = WorldPos + LightPos * (i * 20);
// float Cast = cloudVol(shadowSamplePos);
// Shadow += Cast;
// }
// return clamp(exp(-Shadow*30),0.0,1.0);
// }
//Mie phase function
// float phaseg(float x, float g){
// float gg = g * g;
// return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) /3.14;
// }
mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) {
int SAMPLES = 16; int SAMPLES = 16;
vec3 vL = vec3(0.0);
float absorbance = 1.0;
//project pixel position into projected shadowmap space //project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz; vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz; fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
//project view origin into projected shadowmap space //project view origin into projected shadowmap space
vec3 start = vec3(0.0); vec3 start = toShadowSpaceProjected(vec3(0.));
//rayvector into projected shadow map space //rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection //we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step //however we still have to send it to curved shadow map space every step
vec3 dV = (fragposition-start); vec3 dV = fragposition-start;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),32.0 * 12.0)/length(dVWorld); float maxLength = min(length(dVWorld),far)/length(dVWorld);
dV *= maxLength; dV *= maxLength;
dVWorld *= maxLength; dVWorld *= maxLength;
//apply dither
vec3 progress = start.xyz;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 vL = vec3(0.);
float dL = length(dVWorld); float dL = length(dVWorld);
vec3 fogcolor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01)) ;
vec3 absorbance = vec3(1.0);
float expFactor = 11.0; float expFactor = 11.0;
vec3 fogColor = gl_Fog.color.rgb;
// float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos));
// float OrbMie = phaseg(SdotV, 0.8);
for (int i=0;i<SAMPLES;i++) { for (int i=0;i<SAMPLES;i++) {
float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); float d = (pow(expFactor, float(i+dither)/float(SAMPLES))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0); float dd = pow(expFactor, float(i+dither)/float(SAMPLES)) * log(expFactor) / float(SAMPLES)/(expFactor-1.0);
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld; vec3 progress = start.xyz + d*dV;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
float densityVol = cloudVol(progressW) ; float Density = cloudVol(progressW);
float density = min(densityVol,0.1); Density *= exp(max(progressW.y-80,0.0) / -5);
float air = 0.005;
/// THE OOOOOOOOOOOOOOOOOOOOOORB float Air = 0.01;
vec3 LightColor = LightSourceColor();
// vec3 LightPos = LightSourcePosition(progressW, cameraPosition); // vec3 vL0 = vec3(TORCH_R,TORCH_G,TORCH_B) * exp(max(progressW.y-30,0.0) / -10.0);
// float OrbMie = exp(length(LightPos) * -0.03) * 64.0; vec3 vL0 = vec3(TORCH_R,TORCH_G,TORCH_B) * exp(Density * -50) * exp(max(progressW.y-30,0.0) / -10.0)*25 ;
float OrbMie = clamp(exp((progressW.y - 30) / -10.) * 5,0,1); vL0 += (vec3(0.5,0.5,1.0)/ 5) * exp(max(100-progressW.y,0.0) / -15.0) * (1.0 - exp(Density * -1));
LightColor *= OrbMie; vec3 vL1 = fogcolor / 20.0;
float CastLight = 0.0; vL += (vL0 - vL0*exp(-Density*dd*dL)) * absorbance;
for (int j=0; j < 5; j++){ vL += (vL1 - vL1*exp(-Air*dd*dL)) * absorbance;
vec3 shadowSamplePos = progressW + WsunVec * (0.5 + j * 5);
// vec3 shadowSamplePos = progressW - LightPos.y * (j*30);
float densityVol2 = cloudVol(shadowSamplePos); absorbance *= exp(-(Density+Air)*dd*dL);
CastLight += densityVol2;
} }
return vec4(vL,absorbance);
vec3 CastedLight = LightColor * exp(CastLight * -15);
// #ifdef THE_ORB
// density += clamp((1.0 - length(LightPos) / 10.0) * 10 ,0.0,1.0) ;
// #endif
vec3 AmbientLight = fogColor* exp(density * -25);
vec3 vL0 = AmbientLight;
vec3 vL1 = vec3(1.0,0.75,0.5) * 0.1;
vL += (vL0 - vL0*exp(-density*dd*dL)) * absorbance;
vL += (vL1 - vL1*exp(-air*dd*dL)) * absorbance;
absorbance *= exp(-(density+air)*dd*dL);
}
return mat2x3(vL,absorbance);
} }

View File

@ -89,10 +89,6 @@ vec2 RENDER_SCALE = vec2(1.0);
#include "/lib/nether_fog.glsl"
vec3 normVec (vec3 vec){ vec3 normVec (vec3 vec){

View File

@ -4,20 +4,10 @@
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
flat varying vec4 lightCol;
// 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 float tempOffsets; flat varying float tempOffsets;
flat varying float fogAmount;
flat varying float VFAmount;
uniform sampler2D noisetex; uniform sampler2D noisetex;
uniform sampler2D depthtex0; uniform sampler2D depthtex0;
uniform sampler2D colortex2; uniform sampler2D colortex2;
uniform sampler2D colortex3; uniform sampler2D colortex3;
// uniform sampler2D colortex4; // uniform sampler2D colortex4;
@ -32,10 +22,14 @@ uniform float frameTimeCounter;
uniform int isEyeInWater; uniform int isEyeInWater;
uniform vec2 texelSize; uniform vec2 texelSize;
uniform vec3 previousCameraPosition;
varying vec2 texcoord;
#include "/lib/color_transforms.glsl" #include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl" #include "/lib/color_dither.glsl"
#include "/lib/projections.glsl" #include "/lib/projections.glsl"
#include "/lib/nether_fog.glsl" #include "/lib/nether_fog.glsl"
@ -54,24 +48,20 @@ float blueNoise(){
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
varying vec2 texcoord;
void main() { void main() {
/* DRAWBUFFERS:0 */ /* DRAWBUFFERS:0 */
// if (isEyeInWater == 0){ // if (isEyeInWater == 0){
// vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize; vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
// float z = texture2D(depthtex0,tc).x; float z = texture2D(depthtex0,tc).x;
// vec3 fragpos = toScreenSpace(vec3(tc,z)); vec3 fragpos = toScreenSpace(vec3(tc,z));
// vec3 fragpos_ALT = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); vec4 VolumetricFog = GetVolumetricFog(fragpos, blueNoise());
// float noise = blueNoise(); gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
// mat2x3 vl = getVolumetricRays(noise,fragpos, interleaved_gradientNoise());
// float absorbance = dot(vl[1],vec3(0.22,0.71,0.07));
// gl_FragData[0] = clamp(vec4(vl[0],absorbance),0.000001,65000.);
// } else { // } else {
// gl_FragData[0] = vec4(0.0); // gl_FragData[0] = vec4(0.0);

View File

@ -116,7 +116,7 @@ void main() {
float glassdepth = clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15); float glassdepth = clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15);
// vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth); // vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
float bloomyfogmult = 1.0; float bloomyFogMult = 1.0;
vec4 Translucent_Programs = texture2D(colortex2,texcoord); // the shader for all translucent progams. vec4 Translucent_Programs = texture2D(colortex2,texcoord); // the shader for all translucent progams.
@ -131,7 +131,7 @@ void main() {
vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) ); vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) );
// vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth); vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
#ifdef Refraction #ifdef Refraction
refractedCoord += normals.xy * glassdepth; refractedCoord += normals.xy * glassdepth;
@ -151,17 +151,16 @@ void main() {
color = color*(1.0-Translucent_Programs.a) + Translucent_Programs.rgb; color = color*(1.0-Translucent_Programs.a) + Translucent_Programs.rgb;
} }
if (isEyeInWater == 0){ // if (isEyeInWater == 0){
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); // vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0); // float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0);
bloomyfogmult = 1.0 - fogdistfade*0.5 ; // bloomyFogMult = 1.0 - fogdistfade*0.5 ;
color.rgb = mix(color.rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ; // color.rgb = mix(color.rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ;
} // }
// color *= vl.a; color *= vl.a;
// color += vl.rgb; color += vl.rgb;
// bloomyfogmult *= pow(vl.a,0.1);
@ -169,7 +168,7 @@ void main() {
if (isEyeInWater == 1){ if (isEyeInWater == 1){
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0); float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0);
bloomyfogmult *= fogfade*0.70+0.3 ; bloomyFogMult *= fogfade*0.70+0.3 ;
} }
/// lava. /// lava.
if (isEyeInWater == 2){ if (isEyeInWater == 2){
@ -179,7 +178,7 @@ void main() {
if (isEyeInWater == 3){ if (isEyeInWater == 3){
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
bloomyfogmult = 0.0; bloomyFogMult = 0.0;
} }
// blidnesss // blidnesss
if (blindness > 0.0){ if (blindness > 0.0){
@ -192,7 +191,7 @@ void main() {
color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor);
} }
gl_FragData[0].r = bloomyfogmult; gl_FragData[0].r = vl.a * bloomyFogMult;
#ifdef display_LUT #ifdef display_LUT
vec2 movedTC = texcoord; vec2 movedTC = texcoord;

View File

@ -49,7 +49,6 @@ uniform ivec2 eyeBrightnessSmooth;
#include "/lib/util.glsl" #include "/lib/util.glsl"
#include "/lib/ROBOBO_sky.glsl"
vec3 toShadowSpaceProjected(vec3 p3){ vec3 toShadowSpaceProjected(vec3 p3){
@ -70,6 +69,8 @@ float blueNoise(){
vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.); vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.);
const float[17] Slightmap = float[17](14.0,17.,19.0,22.0,24.0,28.0,31.0,40.0,60.0,79.0,93.0,110.0,132.0,160.0,197.0,249.0,249.0); const float[17] Slightmap = float[17](14.0,17.,19.0,22.0,24.0,28.0,31.0,40.0,60.0,79.0,93.0,110.0,132.0,160.0,197.0,249.0,249.0);
#include "/lib/nether_fog.glsl"
void main() { void main() {
/* DRAWBUFFERS:4 */ /* DRAWBUFFERS:4 */
@ -81,12 +82,21 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0); vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0);
vec3 viewVector = cartToSphere(p); vec3 viewVector = cartToSphere(p);
vec3 BackgroundColor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01)) * 3.0; // vec3 BackgroundColor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01)) / 30.0;
BackgroundColor *= abs(viewVector.y+0.5); // BackgroundColor *= abs(viewVector.y+0.5);
vec3 BackgroundColor = vec3(0.0);
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., fract(frameCounter/1.6180339887));
BackgroundColor += VL_Fog.rgb/5;
gl_FragData[0] = vec4(BackgroundColor,1.0); gl_FragData[0] = vec4(BackgroundColor,1.0);
} }
//Temporally accumulate sky and light values
vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 curr = gl_FragData[0].rgb*150.;
gl_FragData[0].rgb = clamp(mix(temp,curr,0.07),0.0,65000.);
//Exposure values //Exposure values
if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(exposure,avgBrightness,exposureF,1.0); gl_FragData[0] = vec4(exposure,avgBrightness,exposureF,1.0);