remake and improve underwater lighting. add new method for indirect SSS. improve nametag rendering. fix translucent rendering on DH LODs. begin work on WIP cloud raymarcher

This commit is contained in:
Xonk
2025-01-15 23:08:16 -05:00
parent 5d0ff0856f
commit 6c41c008c0
24 changed files with 701 additions and 693 deletions

View File

@ -161,21 +161,6 @@ uniform int framemod8;
#include "/lib/TAA_jitter.glsl"
// float DH_ld(float dist) {
// return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
// }
// float DH_invLinZ (float lindepth){
// return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
// }
// float linearizeDepthFast(const in float depth, const in float near, const in float far) {
// return (near * far) / (depth * (near - far) + far);
// }
// uniform float far;
vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater){
float quality = mix(5,SSR_STEPS,fresnel);
@ -204,12 +189,11 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
// float sp = DH_inv_ld(sqrt(texelFetch2D(colortex12,ivec2(spos.xy/texelSize/4),0).a/65000.0));
float sp = DH_inv_ld(sqrt(texelFetch2D(colortex12,ivec2(spos.xy/texelSize/4),0).a/64000.0));
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
if(sp < max(minZ,maxZ) && sp > min(minZ,maxZ)) return vec3(spos.xy/RENDER_SCALE,sp);
spos += stepv;
//small bias
minZ = maxZ-0.0000035/DH_ld(spos.z);
minZ = maxZ-0.00005/DH_ld(spos.z);
maxZ += stepv.z;
}
@ -290,7 +274,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
float material = 0.7;
if(iswater) material = 1.0;
vec3 normals = normals_and_materials.xyz;
vec3 normals = normalize(normals_and_materials.xyz);
if (!gl_FrontFacing) normals = -normals;
vec3 worldSpaceNormals = mat3(gbufferModelViewInverse) * normals;
vec3 viewPos = pos.xyz;
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
float transition = exp(-25* pow(clamp(1.0 - length(playerPos)/(far-8),0.0,1.0),2));
@ -305,18 +293,22 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
if(length(playerPos) < clamp(far-16*4, 16, maxOverdrawDistance) ){ discard; return;}
#endif
if(iswater && abs(normals.y) > 0.0){
vec3 posxz = playerPos+cameraPosition;
vec3 waterNormals = worldSpaceNormals;
if(iswater && abs(worldSpaceNormals.y) > 0.1){
vec3 posxz = playerPos+cameraPosition;
vec3 bump = normalize(getWaveNormal(posxz, true));
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
normals.xz = bump.xy;
waterNormals.xz = bump.xy;
}
normals = worldToView(waterNormals);
normals = worldToView(normals);
gl_FragData[0] = gcolor;
// float UnchangedAlpha = gl_FragData[0].a;
@ -346,7 +338,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#ifdef OVERWORLD_SHADER
vec3 DirectLightColor = lightCol.rgb/2400.0;
float NdotL = clamp(dot(normals, normalize(WsunVec2)),0.0,1.0);
float NdotL = clamp(dot(worldSpaceNormals, WsunVec),0.0,1.0);
NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
float Shadows = 1.0;
@ -383,12 +375,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
Direct_lighting = DirectLightColor * NdotL * Shadows;
vec3 AmbientLightColor = averageSkyCol_Clouds/900.0;
vec3 AmbientLightColor = averageSkyCol_Clouds/900.0 ;
vec3 ambientcoefs = normals_and_materials.xyz / dot(abs(normals_and_materials.xyz), vec3(1.0));
vec3 ambientcoefs = worldSpaceNormals.xyz / dot(abs(worldSpaceNormals.xyz), vec3(1.0));
float SkylightDir = ambientcoefs.y*1.5;
float skylight = max(pow(viewToWorld(normals_and_materials.xyz).y*0.5+0.5,0.1) + SkylightDir, 0.2);
float skylight = max(pow(worldSpaceNormals.y*0.5+0.5,0.1) + SkylightDir, 0.2);
AmbientLightColor *= skylight;
#endif
@ -407,7 +399,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 BackgroundReflection = FinalColor;
vec3 SunReflection = vec3(0.0);
float roughness = 0.035;
float roughness = 0.0;
float f0 = 0.02;
// f0 = 0.9;
@ -440,21 +432,19 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
SunReflection = (DirectLightColor * Shadows) * GGX(normalize(normals), -normalize(viewPos), normalize(WsunVec2), roughness, f0) * (1.0-Reflections.a);
#endif
Reflections_Final = mix(BackgroundReflection, Reflections.rgb, Reflections.a) * fresnel;
Reflections_Final = mix(FinalColor, mix(BackgroundReflection, Reflections.rgb, Reflections.a), fresnel);
Reflections_Final += SunReflection;
//correct alpha channel with fresnel
float alpha0 = gl_FragData[0].a;
gl_FragData[0].a = -gl_FragData[0].a * fresnel + gl_FragData[0].a + fresnel;
// prevent reflections from being darkened by buffer blending
gl_FragData[0].rgb = clamp(FinalColor / gl_FragData[0].a*alpha0*(1.0-fresnel) * 0.1 + Reflections_Final / gl_FragData[0].a * 0.1,0.0,65100.0);
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * fresnel;
gl_FragData[0].rgb = clamp(Reflections_Final / gl_FragData[0].a * 0.1,0.0,65000.0);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.0);
#else
gl_FragData[0].rgb = FinalColor*0.1;
#endif
// gl_FragData[0].rgb = normals*0.1;
#ifdef DH_OVERDRAW_PREVENTION
float distancefade = min(max(1.0 - length(playerPos)/clamp(far-16*4, 16, maxOverdrawDistance),0.0)*5,1.0);

View File

@ -91,17 +91,17 @@ void main() {
// gl_Position = toClipSpace3(position);
normals_and_materials = vec4(normalize(gl_Normal), 1.0);
normals_and_materials = vec4(mat3(gbufferModelView) * gl_Normal, 1.0);
gcolor = gl_Color;
lightmapCoords = gl_MultiTexCoord1.xy;
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
#ifdef OVERWORLD_SHADER
#if defined Daily_Weather
dailyWeatherParams0 = vec4((texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0)/2.0, 0.0);
@ -112,10 +112,6 @@ void main() {
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
WsunVec2 = lightCol.a * normalize(sunPosition);
#ifdef TAA_UPSCALING

View File

@ -63,6 +63,8 @@ uniform vec2 texelSize;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
uniform float nightVision;
uniform float waterEnteredAltitude;
flat varying float HELD_ITEM_BRIGHTNESS;
@ -433,6 +435,10 @@ void main() {
Shadows *= GetCloudShadow(feetPlayerPos+cameraPosition, WsunVec);
#endif
if(isEyeInWater == 1){
float distanceFromWaterSurface = max(-(feetPlayerPos.y + (cameraPosition.y - waterEnteredAltitude)),0.0) ;
directLightColor *= exp(-vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B) * distanceFromWaterSurface);
}
Direct_lighting = directLightColor * Shadows;
// #ifndef LINES

View File

@ -191,6 +191,11 @@ void main() {
gl_Position = ftransform();
#if defined ENTITIES && defined IS_IRIS
// force out of frustum
if (entityId == 1599) gl_Position.z -= 10000;
#endif
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
/////// ----- COLOR STUFF ----- ///////
@ -300,7 +305,7 @@ void main() {
mc_Entity.x == BLOCK_AMETHYST_BUD_MEDIUM || mc_Entity.x == BLOCK_AMETHYST_BUD_LARGE || mc_Entity.x == BLOCK_AMETHYST_CLUSTER ||
mc_Entity.x == BLOCK_BAMBOO || mc_Entity.x == BLOCK_SAPLING || mc_Entity.x == BLOCK_VINE
) {
SSSAMOUNT = 0.0;
SSSAMOUNT = 0.5;
}
// low
#ifdef MISC_BLOCK_SSS

View File

@ -35,6 +35,9 @@ uniform vec4 entityColor;
flat varying float HELD_ITEM_BRIGHTNESS;
#if defined ENTITIES && defined IS_IRIS
flat varying int NAMETAG;
#endif
uniform sampler2D noisetex;
uniform sampler2D depthtex1;
@ -45,6 +48,7 @@ uniform sampler2D depthtex0;
#endif
uniform sampler2D colortex7;
uniform sampler2D colortex12;
uniform sampler2D colortex13;
uniform sampler2D colortex14;
uniform sampler2D colortex5;
uniform sampler2D colortex3;
@ -102,6 +106,8 @@ uniform float sunIntensity;
uniform vec3 sunColor;
uniform vec3 nsunColor;
uniform float waterEnteredAltitude;
#include "/lib/util.glsl"
#include "/lib/Shadow_Params.glsl"
#include "/lib/color_transforms.glsl"
@ -180,13 +186,16 @@ float blueNoise(){
#define PW_POINTS 2 //[2 4 6 8 16 32]
varying vec3 viewVector;
vec3 getParallaxDisplacement(vec3 posxz) {
vec3 getParallaxDisplacement(vec3 playerPos) {
vec3 parallaxPos = posxz;
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
// float waterHeight = (1.0 - (getWaterHeightmap(posxz.xz)*0.5+0.5)) * 2.0 - 1.0;
float waterHeight = getWaterHeightmap(posxz.xz) * 2.0;
parallaxPos.xz -= waterHeight * vec;
float waterHeight = getWaterHeightmap(-playerPos.xz) ;
waterHeight = exp(-20*sqrt(waterHeight));
// waterHeight *= 2.0;
vec3 parallaxPos = playerPos;
parallaxPos.xz += (viewVector.xy / -viewVector.z) * waterHeight;
// parallaxPos.xz -= (viewVec.xy / viewVec.z) * waterHeight * 0.5;
return parallaxPos;
}
@ -516,8 +525,13 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
// TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0);
float nameTagMask = 0.0;
gl_FragData[2] = vec4(encodeVec2(TangentNormal*0.5+0.5), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), 1.0);
#if defined ENTITIES && defined IS_IRIS
if(NAMETAG > 0) nameTagMask = 0.1;
#endif
gl_FragData[2] = vec4(encodeVec2(TangentNormal*0.5+0.5), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), encodeVec2(0.0, nameTagMask));
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SPECULARS /////////////////////////////////////
@ -559,6 +573,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#ifdef OVERWORLD_SHADER
vec3 DirectLightColor = lightCol.rgb/2400.0;
if(isEyeInWater == 1){
float distanceFromWaterSurface = max(-(feetPlayerPos.y + (cameraPosition.y - waterEnteredAltitude)),0.0) ;
DirectLightColor *= exp(-vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B) * distanceFromWaterSurface);
}
float NdotL = clamp(dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse))),0.0,1.0); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
float Shadows = 1.0;
@ -595,18 +615,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#endif
#ifdef END_SHADER
// float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
// vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
// float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
// vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
// float NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
// NdotL *= NdotL;
// Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
@ -651,6 +659,17 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
// vec4 vlBehingTranslucents = texture2D(colortex13, gl_FragCoord.xy*texelSize * VL_RENDER_RESOLUTION).rgba;
// vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);// dirtEpsilon*dirtAmount + waterEpsilon;
// vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
// vec3 transmittance = exp(-totEpsilon * vlBehingTranslucents.a*50);
// FinalColor *= transmittance;
// FinalColor = FinalColor * vlBehingTranslucents.a +vlBehingTranslucents.rgb ;
#if EMISSIVE_TYPE == 2 || EMISSIVE_TYPE == 3
Emission(FinalColor, Albedo, SpecularTex.b, exposure);
#endif
@ -711,9 +730,17 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#else
gl_FragData[0].rgb = FinalColor*0.1;
#endif
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION && !defined HAND
bool WATER = texture2D(colortex7, gl_FragCoord.xy*texelSize).a > 0.0 && length(feetPlayerPos) > far-16*4 && texture2D(depthtex1, gl_FragCoord.xy*texelSize).x >= 1.0;
#if OVERDRAW_MAX_DISTANCE == 0
float maxOverdrawDistance = far;
#else
float maxOverdrawDistance = OVERDRAW_MAX_DISTANCE;
#endif
bool WATER = texture2D(colortex7, gl_FragCoord.xy*texelSize).a > 0.0 && length(feetPlayerPos) > clamp(far-16*4, 16, maxOverdrawDistance) && texture2D(depthtex1, gl_FragCoord.xy*texelSize).x >= 1.0;
if(WATER) gl_FragData[0].a = 0.0;
#endif
@ -735,10 +762,22 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
gl_FragData[0].rgb = Direct_lighting * 0.1;
#endif
// gl_FragData[3].a = clamp(lightmap.y,0.0,1.0);
// gl_FragData[0] = vec4(tbnMatrix * viewPos,1);
gl_FragData[3] = vec4(encodeVec2(lightmap.x, lightmap.y), 1, 1, 1);
#if defined ENTITIES && defined IS_IRIS
if(NAMETAG > 0) {
// WHY DO THEY HAVE TO AHVE LIGHTING AAAAAAUGHAUHGUAHG
#ifndef OVERWORLD_SHADER
lightmap.y = 0.0;
#endif
vec3 nameTagLighting = Albedo.rgb * max(max(lightmap.y*lightmap.y*lightmap.y , lightmap.x*lightmap.x*lightmap.x), 0.025);
// in vanilla they have a special blending mode/no blending, or something. i cannot change the buffer blend mode without changing the rest of the entities :/
gl_FragData[0] = vec4(nameTagLighting.rgb * 0.1, UnchangedAlpha * 0.75);
}
#endif
}
}

View File

@ -46,6 +46,9 @@ uniform mat4 gbufferModelView;
varying vec3 viewVector;
flat varying int glass;
#if defined ENTITIES && defined IS_IRIS
flat varying int NAMETAG;
#endif
attribute vec4 at_tangent;
attribute vec4 mc_Entity;
@ -140,6 +143,7 @@ void main() {
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * CURVATURE_AMOUNT;
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
gl_Position = toClipSpace3(position);
@ -169,6 +173,11 @@ void main() {
// translucent blocks
if (mc_Entity.x >= 301 && mc_Entity.x <= 321) mat = 0.7;
#if defined ENTITIES && defined IS_IRIS
NAMETAG = 0;
if (entityId == 1600) NAMETAG = 1;
#endif
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
@ -212,7 +221,12 @@ void main() {
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#if defined ENTITIES && defined IS_IRIS
// remove jitter for nametags lol
if (entityId != 1600) gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#else
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
#endif
#if DOF_QUALITY == 5

View File

@ -197,6 +197,7 @@ vec2 SpiralSample(
return vec2(x, y);
}
vec2 CleanSample(
int samples, float totalSamples, float noise
){
@ -250,21 +251,21 @@ float convertHandDepth_2(in float depth, bool hand) {
}
vec2 SSAO(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
vec3 viewPos, vec3 normal, vec3 flatnormal, bool hand, bool leaves, float noise
){
int samples = 7;
int samples = 14;
float occlusion = 0.0;
float sss = 0.0;
float THING = 0.0;
vec3 normalizedNormals = normalize(normal);
vec2 jitterOffsets = TAA_Offset*texelSize*0.5 * RENDER_SCALE - texelSize*0.5;
// scale the offset radius down as distance increases.
float linearViewDistance = length(viewPos);
float distanceScale = hand ? 30.0 : mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale * 0.5;
float leaf = leaves ? -0.5 : 0.0;
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale ;
// float leaf = leaves ? -0.5 : 0.0;
int n = 0;
for (int i = 0; i < samples; i++) {
@ -287,23 +288,34 @@ vec2 SSAO(
vec3 viewPosDiff = offsetViewPos - viewPos;
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
float threshHold = max(1.0 - viewPosDiffSquared/depthCancelation, 0.0);
if (viewPosDiffSquared > 1e-5){
if(viewPosDiffSquared < depthCancelation){
float NdotV = clamp(dot(viewPosDiff*inversesqrt(viewPosDiffSquared), normalizedNormals),0.0,1.0);
occlusion += NdotV * clamp(1.0-(viewPosDiffSquared/depthCancelation),0.0,1.0);
}
n += 1;
float preAo = 1.0 - clamp(dot(normalize(viewPosDiff), flatnormal)*25.0,0.0,1.0);
occlusion += max(0.0, dot(normalize(viewPosDiff), normal) - preAo) * threshHold;
#ifdef Ambient_SSS
sss += clamp(0.0 - dot(viewPosDiff, normalizedNormals),0.0,1.0) * exp(-10.0 * occlusion);
#ifdef OLD_INDIRECT_SSS
sss += clamp(-dot(normalize(viewPosDiff), flatnormal),0.0,1.0) * exp(-10*occlusion);
#else
sss += clamp(-dot(normalize(viewPosDiff), flatnormal) - occlusion/n,0.0,1.0) * 0.25
+ min(-normalize(mat3(gbufferModelViewInverse) * viewPosDiff).y - occlusion/n,1.0) * threshHold;
// + min(-dot(normalize(mat3(gbufferModelViewInverse) * viewPosDiff),clamp(normalize(WsunVec),-vec3(0.35,1.0,0.35),vec3(0.35,1.0,0.35))) - occlusion/n,1.0) * threshHold;
#endif
#endif
n += 1;
}
}
}
return max(1.0 - vec2(occlusion*AO_Strength, sss)/n, 0.0);
float finaalAO = max(1.0 - occlusion*AO_Strength/n, 0.0);
float finalSSS = sss/n;
return vec2(finaalAO, finalSSS);
}
float ScreenSpace_SSS(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
){
@ -343,6 +355,7 @@ float ScreenSpace_SSS(
if (viewPosDiffSquared > 1e-5){
sss += clamp(leaf - dot(viewPosDiff, normalizedNormals),0.0,1.0);
// sss += -(normalize(mat3(gbufferModelViewInverse)*viewPosDiff) + occlusion/n) * threshHold;
n += 1;
}
}
@ -350,6 +363,77 @@ float ScreenSpace_SSS(
return max(1.0 - sss/n, 0.0);
}
vec2 spiralSampling(
int samples, float totalSamples, float noise
){
// this will be used to make 1 full rotation of the spiral. the mulitplication is so it does nearly a single rotation, instead of going past where it started
float variance = noise * 0.897;
// for every sample input, it will have variance applied to it.
float variedSamples = float(samples) + variance;
// for every sample, the sample position must change its distance from the origin.
// otherwise, you will just have a circle.
float spiralShape = variedSamples / (totalSamples + variance);
float shape = 2.26;
float theta = variedSamples * (PI * shape);
float x = cos(theta) * spiralShape;
float y = sin(theta) * spiralShape;
return vec2(x, y);
}
// vec3 getViewPos(in vec2 uv, in float depth, in mat4 inverseProj ){
// }
float getNoise(in vec2 fragCoord){
return fract(0.75487765 * fragCoord.x + 0.56984026 * fragCoord.y);
}
float calculateSSAO(
vec2 fragCoord, vec2 uv, vec3 viewPos, vec3 normal, in mat4 inverseProj
){
// SETTINGS
int SAMPLES = 50;
float RADIUS = 0.0005;
vec2 SCALE_RADIUS = vec2(1280.0, 720.0 * aspectRatio);
float linearViewDistance = length(viewPos);
float distanceScale = mix(40.0, 1.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale;
float noise = getNoise(fragCoord);
float average = 0.0;
float occlusion = 0.0;
for (int i = 0; i < SAMPLES; i++) {
vec2 offsets = (spiralSampling(i, float(SAMPLES - 1), noise) / distanceScale) * RADIUS * SCALE_RADIUS;
vec2 offsetUV = uv + offsets;
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x <= 1.0 && offsetUV.y <= 1.0 ) {
float sampleDepth = texture(depthtex0, offsetUV).x;
// vec3 offsetViewPos = getViewPos(offsetUV, sampleDepth, inverseProj);
vec3 offsetViewPos = toScreenSpace(vec3(offsetUV, sampleDepth));
vec3 viewPosDiff = offsetViewPos - viewPos;
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
float threshHold = max(1.0 - viewPosDiffSquared/depthCancelation, 0.0);
if (viewPosDiffSquared > 1e-5){
occlusion += max(0.0, dot(normalize(viewPosDiff), normal)) * threshHold;
average += 1.0;
}
}
}
float finalAO = max(1.0 - occlusion / average, 0.0);
finalAO = finalAO*finalAO*finalAO*finalAO;
return finalAO;
}
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
@ -469,7 +553,8 @@ void main() {
float noise = R2_dither();
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex1,texcoord).x;
float z = texture(depthtex1,texcoord).x;
// float z = texelFetch2D(depthtex1,ivec2(gl_FragCoord.xy),0).x;
#ifdef DISTANT_HORIZONS
float DH_depth1 = texture2D(dhDepthTex1,texcoord).x;
@ -534,8 +619,12 @@ void main() {
if(z >= 1.0) FlatNormals = normal;
vec2 SSAO_SSS = SSAO(viewPos, worldToView(FlatNormals), hand, isLeaf, noise);
vec2 SSAO_SSS = SSAO(viewPos, worldToView(normal),worldToView(FlatNormals), hand, isLeaf, noise);
#ifndef OLD_INDIRECT_SSS
SSAO_SSS.y = clamp(SSAO_SSS.y + 0.5 * lightmap.y*lightmap.y,0.0,1.0);
#endif
// SSAO_SSS.y = clamp(SSAO_SSS.y + 0.5,0.0,1.0);
if(swappedDepth >= 1.0) SSAO_SSS = vec2(1.0,0.0);
gl_FragData[1].xy = SSAO_SSS;

View File

@ -9,6 +9,7 @@
#extension GL_ARB_shading_language_packing: enable
#endif
#include "/lib/util.glsl"
#include "/lib/res_params.glsl"
@ -100,6 +101,7 @@ uniform mat4 gbufferPreviousModelView;
// uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform float updateFadeTime;
// uniform float far;
uniform float near;
@ -133,6 +135,7 @@ flat varying float exposure;
uniform int heldItemId;
uniform int heldItemId2;
#endif
uniform float waterEnteredAltitude;
void convertHandDepth(inout float depth) {
@ -343,7 +346,6 @@ float blueNoise(){
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
// vec3 toShadowSpaceProjected(vec3 feetPlayerPos){
// mat4 DH_shadowProjection = DH_shadowProjectionTweak(shadowProjection);
@ -825,7 +827,6 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa
// float scatterDepth = max(1.0 - Scattering/density,0.0);
// scatterDepth = exp((1.0-scatterDepth) * -7.0);
// scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
// // this is for SSS when there is no shadow blocker depth
// #if defined BASIC_SHADOW_FILTER && defined Variable_Penumbra_Shadows
@ -851,14 +852,18 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa
// float scatterDepth = Scattering;//max(1.0 - Scattering/density,0.0);
float scatterDepth = max(1.0 - Scattering/density, 0.0);
scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
scatterDepth *= exp(-7.0 * (1.0-scatterDepth));
vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -(20.0 - 19*scatterDepth) * sss_absorbance_multiplier);
// vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -(20.0 - 19*scatterDepth) * sss_absorbance_multiplier);
scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
// scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);// * vec3(1.0);
// vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);// * vec3(1.0);
vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -20.0);
vec3 scatter = scatterDepth * mix(absorbColor, vec3(1.0), scatterDepth) * pow(Density, LabSSS_Curve);
scatter *= 1.0 + CustomPhase(lightPos)*6.0; // ~10x brighter at the peak
@ -867,18 +872,17 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa
vec3 SubsurfaceScattering_sky(vec3 albedo, float Scattering, float Density){
// Scattering *= sss_density_multiplier;
float scatterDepth = 1.0 - pow(Scattering, 0.5 + Density * 2.5);
// float scatterDepth = 1.0 - Scattering;
#ifdef OLD_INDIRECT_SSS
float scatterDepth = 1.0 - pow(1.0-Scattering, 0.5 + Density * 2.5);
vec3 absorbColor = vec3(1.0) * exp(-(15.0 - 10.0*scatterDepth) * sss_absorbance_multiplier * 0.01);
vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);
#else
float scatterDepth = pow(Scattering,4);
scatterDepth = 1-pow(1-scatterDepth,5);
// PBR at its finest :clueless:
// vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -20.0 * sss_absorbance_multiplier);
// vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.0,1.2), 0.0) * -20.0);
vec3 absorbColor = vec3(1.0) * exp(-(15.0 - 10.0*scatterDepth) * sss_absorbance_multiplier * 0.01);
vec3 scatter = scatterDepth * absorbColor * pow(Density, LabSSS_Curve);
vec3 absorbColor = exp(max(luma(albedo) - albedo*vec3(1.0,1.1,1.2), 0.0) * -1.0 * sss_absorbance_multiplier);
vec3 scatter = scatterDepth * mix(absorbColor, vec3(1.0), scatterDepth) * pow(Density, LabSSS_Curve);
#endif
return scatter;
}
@ -910,32 +914,45 @@ uniform float wetness;
void applyPuddles(
in vec3 worldPos, in vec3 flatNormals, in float lightmap, in bool isWater, inout vec3 albedo, inout vec3 normals, inout float roughness, inout float f0
){
vec3 unchangedNormals = normals;
float halfWet = min(wetnessAmount,1.0);
float fullWet = clamp(wetnessAmount - 2.0,0.0,1.0);
// halfWet = 1.0;
// fullWet = 0.0;
// fullWet = 1.0;
float noise = texture2D(noisetex, worldPos.xz * 0.02).b;
float puddles = max(halfWet - noise,0.0);
puddles = clamp(halfWet - exp(-20.0 * puddles*puddles*puddles*puddles*puddles),0.0,1.0);
// puddles *= halfWet;
float lightmapMax = min(max(lightmap - 0.9,0.0) * 10.0,1.0);
float lightmapMin = min(max(lightmap - 0.8,0.0) * 5.0,1.0);
float lightmapMax = min(max(lightmap - 0.9,0.0) * 10.0,1.0) ;
float lightmapMin = min(max(lightmap - 0.8,0.0) * 5.0,1.0) ;
lightmap = clamp(lightmapMax + noise*lightmapMin*2.0,0.0,1.0);
lightmap = pow(1.0-pow(1.0-lightmap,3.0),2.0);
float wetnessStages = mix(puddles, 1.0, fullWet) * lightmap;
// if(isWater || (!isWater && isEyeInWater == 1)) wetnessStages = 1.0;
float puddles = max(halfWet - noise,0.0);
puddles = clamp(halfWet - exp(-25.0 * puddles*puddles*puddles*puddles*puddles),0.0,1.0);
float wetnessStages = mix(puddles, 1.0, fullWet) * lightmap;
if(isWater) wetnessStages = 0.0;
normals = mix(normals, flatNormals, puddles * lightmap * clamp(flatNormals.y,0.0,1.0));
roughness = mix(roughness, 1.0, wetnessStages);
if(f0 < 229.5/255.0 ) albedo = pow(albedo * (1.0 - 0.08*wetnessStages), vec3(1.0 + 0.7*wetnessStages));
//////////////// snow
// float upnormal = clamp(-(normals / dot(abs(normals),vec3(1.0))).y+clamp(flatNormals.y,0.5,1.0),0,1);
// halfWet = clamp(halfWet - upnormal - (1.0-lightmap),0.0,1.0);
// float snow = max(halfWet - noise,0.0);
// snow = clamp(halfWet - exp(-20.0 * snow*snow*snow*snow*snow),0.0,1.0);
// if(isWater || f0 > 229.5/255.0) snow = 0.0;
// normals = mix(normals, unchangedNormals, snow);
// roughness = mix(roughness, 0.5, snow);
// albedo = mix(albedo, vec3(1.0), snow);
}
vec2 smoothfilterUV(in vec2 uv)
@ -957,6 +974,63 @@ vec2 smoothfilterUV(in vec2 uv)
return uv;
}
float calculateSSAO(
vec3 viewPos, vec3 normal, float noise
){
int samples = 50;
float occlusion = 0.0;
float sss = 0.0;
vec2 jitterOffsets = TAA_Offset*texelSize * 0.5 * RENDER_SCALE - texelSize*0.5;
// scale the offset radius down as distance increases.
float linearViewDistance = length(viewPos);
float distanceScale = mix(40.0, 10.0, pow(clamp(1.0 - linearViewDistance/50.0,0.0,1.0),2.0));
float depthCancelation = (linearViewDistance*linearViewDistance) / distanceScale ;
int n = 0;
for (int i = 0; i < samples; i++) {
vec2 offsets = CleanSample(i, samples - 1, noise) / distanceScale;
ivec2 offsetUV = ivec2(gl_FragCoord.xy + offsets*vec2(viewWidth, viewHeight*aspectRatio)*RENDER_SCALE);
if (offsetUV.x >= 0 && offsetUV.y >= 0 && offsetUV.x < viewWidth*RENDER_SCALE.x && offsetUV.y < viewHeight*RENDER_SCALE.y ) {
float sampleDepth = texelFetch2D(depthtex1, offsetUV, 0).x;
vec2 scaledUV = (offsetUV*texelSize - jitterOffsets) * (1.0/RENDER_SCALE);
vec3 offsetViewPos = toScreenSpace(vec3(scaledUV, sampleDepth));
vec3 viewPosDiff = offsetViewPos - viewPos;
vec3 viewPosDiff_world = mat3(gbufferModelViewInverse) * viewPosDiff;
float viewPosDiffSquared = dot(viewPosDiff, viewPosDiff);
float threshHold = clamp(1.0 - viewPosDiffSquared/depthCancelation, 0.0,1.0);
if (viewPosDiffSquared > 1e-5){
n += 1;
occlusion += max(0.0, dot(normalize(viewPosDiff), normal) - 0.5) * threshHold;
// vec3 dir = (-normalize(viewPosDiff_world) * threshHold + 0.5) * (1.0-occlusion/n);
vec3 dir = -(normalize(viewPosDiff_world) + occlusion/n) * threshHold;
sss += dir.y;
}
}
}
float finalAO = max(1.0 - occlusion / n, 0.0);
float finalSSS = sss/n;
finalAO = pow(finalAO,10);
return finalAO;
}
void main() {
vec3 DEBUG = vec3(1.0);
@ -975,8 +1049,12 @@ void main() {
// float noise = fract(R2_samples(3).y + bnoise.y);
// #endif
float z0 = texture2D(depthtex0,texcoord).x;
float z = texture2D(depthtex1,texcoord).x;
// float z0 = texture2D(depthtex0,texcoord).x;
// float z = texture2D(depthtex1,texcoord).x;
float z0 = texelFetch2D(depthtex0, ivec2(gl_FragCoord.xy), 0).x;
float z = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy), 0).x;
float swappedDepth = z;
bool isDHrange = z >= 1.0;
@ -1098,12 +1176,12 @@ void main() {
////// --------------- COLORS --------------- //////
float dirtAmount = Dirt_Amount;
// float dirtAmount = Dirt_Amount;
// float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon * dirtAmount + waterEpsilon;
// vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);//dirtEpsilon * dirtAmount + waterEpsilon;
vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 Absorbtion = vec3(1.0);
vec3 AmbientLightColor = vec3(0.0);
@ -1169,30 +1247,44 @@ void main() {
float Vdiff = distance(feetPlayerPos, playerPos0);
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y);// assuming water plane
float viewerWaterDepth = Vdiff * (1.0 - clamp(exp(-Vdiff),0.0,1.0));
// float viewerWaterDepth = Vdiff;// * (1.0 - clamp(exp(-Vdiff),0.0,1.0));
// force the absorbance to start way closer to the water surface in low light areas, so the water is visible in caves and such.
#if MINIMUM_WATER_ABSORBANCE > -1
float minimumAbsorbance = MINIMUM_WATER_ABSORBANCE*0.1;
#else
float minimumAbsorbance = (1.0 - lightLeakFix)*0.75;
float minimumAbsorbance = (1.0 - lightLeakFix);
#endif
viewerWaterDepth += max(estimatedDepth - 1.0, minimumAbsorbance);
// viewerWaterDepth += max(estimatedDepth - 1.0, minimumAbsorbance);
Absorbtion = exp( -2.0 * totEpsilon * viewerWaterDepth);
Absorbtion = exp(-totEpsilon * max(Vdiff, minimumAbsorbance));
// Absorbtion = exp( -2.0 * totEpsilon * viewerWaterDepth);
// brighten up the fully absorbed parts of water when night vision activates.
// if( nightVision > 0.0 ) Absorbtion += exp( -50.0 * totEpsilon) * 50.0 * 7.0 * nightVision;
if( nightVision > 0.0 ) Absorbtion += exp( -30.0 * totEpsilon) * 10.0 * nightVision * 10.0;
// if( nightVision > 0.0 ) Absorbtion += exp( -30.0 * totEpsilon) * 10.0 * nightVision * 10.0;
// things to note about sunlight in water
// sunlight gets absorbed by water on the way down to the floor, and on the way back up to your eye. im gonna ingore the latter part lol
// based on the angle of the sun, sunlight will travel through more/less water to reach the same spot. scale absorbtion depth accordingly
vec3 sunlightAbsorbtion = exp(-totEpsilon * (estimatedDepth/abs(WsunVec.y)));
if (isEyeInWater == 1){
estimatedDepth = 1.0;
viewerWaterDepth = max(0.9-lightmap.y,0.0)*3.0;
Absorbtion = exp( -2.0 * totEpsilon * viewerWaterDepth);
DirectLightColor *= Absorbtion;
// viewerWaterDepth = max(0.9-lightmap.y,0.0)*3.0;
float distanceFromWaterSurface = max(-(feetPlayerPos.y + (cameraPosition.y - waterEnteredAltitude)),0.0) ;
Absorbtion = exp(-totEpsilon * distanceFromWaterSurface);
sunlightAbsorbtion = exp(-totEpsilon * (distanceFromWaterSurface/abs(WsunVec.y)));
}
DirectLightColor *= sunlightAbsorbtion;
if( nightVision > 0.0 ) Absorbtion += exp(-totEpsilon * 25.0) * nightVision;
// apply caustics to the lighting, and make sure they dont look weird
DirectLightColor *= mix(1.0, waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS + 0.25, clamp(estimatedDepth,0,1));
@ -1257,9 +1349,11 @@ void main() {
float shadowMapFalloff2 = shadowmapFade;
#endif
// shadowMapFalloff = 1.0;
// shadowMapFalloff2 = 1.0;
if(isEyeInWater == 1){
shadowMapFalloff = 1.0;
shadowMapFalloff2 = 1.0;
}
// un-distort
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
@ -1362,14 +1456,26 @@ void main() {
// skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) ));
// #endif
float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y;
// vec3 lastLightPos = feetPlayerPos + (cameraPosition - lastKnownLightlevel);// - vec3(0,0,0);
// lastLightPos.y = min(lastLightPos.y,0.0);
vec3 indirectNormal = slopednormal / dot(abs(slopednormal),vec3(1.0));
//(slopednormal / dot(abs(slopednormal),vec3(1.0))).y;
float SkylightDir = indirectNormal.y;
if(isGrass) SkylightDir = 1.0;
SkylightDir = clamp(SkylightDir*0.7+0.3, 0.0, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) * 0.7 + 0.3);
SkylightDir = clamp(SkylightDir*0.7+0.3, 0.0, pow(1-pow(1-SSAO_SSS.x, 0.5),4.0) * 0.7 + 0.3);
// SkylightDir = SkylightDir*0.7+0.3;
// float indirectPointLight = clamp(dot(slopednormal, -normalize(lastLightPos)),0,1);
// float lightAttenuation = 1.0-clamp(1.0-length(lastLightPos)/16,0,1);
// SkylightDir = mix(mix(SkylightDir, indirectPointLight, updateFadeTime), SkylightDir, max(lightAttenuation,min(max(lightmap.y-0.9,0)/0.1,1)));
// skylight = mix(0.2, 2.5, SkylightDir);
skylight = mix(0.2 + 2.3*(1.0-lightmap.y), 2.5, SkylightDir);
skylight = mix(0.2 + 2.3*(1.0-lightmap.y), 2.5, SkylightDir);
// skylight = 2.5;
#endif
@ -1435,10 +1541,11 @@ void main() {
SkySSS = SSAO_SSS.y;
float vanillaAO_curve = pow(1.0 - vanilla_AO*vanilla_AO,5.0);
float SSAO_curve = pow(SSAO_SSS.x,6.0);
float SSAO_curve = pow(SSAO_SSS.x,4.0);
// use the min of vanilla ao so they dont overdarken eachother
AO = vec3( min(vanillaAO_curve, SSAO_curve) );
// AO = vec3( min(vanillaAO_curve, SSAO_curve) );
AO = vec3( SSAO_curve );
Indirect_lighting *= AO;
#endif
@ -1468,13 +1575,15 @@ void main() {
///////////////////////////// SKY SSS /////////////////////////////
#if defined Ambient_SSS && defined OVERWORLD_SHADER && indirect_effect == 1
if (!hand){
vec3 ambientColor = AmbientLightColor * mix(0.2,2.5,lightmap.y*lightmap.y) * ambient_brightness; // x2.5 to match the brightness of upfacing skylight
vec3 ambientColor = AmbientLightColor * ambientsss_brightness * 3.0;//mix(0.2,2.5,lightmap.y*lightmap.y); // x2.5 to match the brightness of upfacing skylight
Indirect_SSS = SubsurfaceScattering_sky(albedo, SkySSS, LabSSS);
Indirect_SSS *= lightmap.y*lightmap.y;//*lightmap.y;
Indirect_SSS *= lightmap.y;
// if(texcoord.x>0.5) oIndirect_SSS *= 0.0;
// apply to ambient light.
Indirect_lighting = max(Indirect_lighting, Indirect_SSS * ambientColor * ambientsss_brightness);
Indirect_lighting = max(Indirect_lighting, Indirect_SSS * ambientColor );
// Indirect_lighting += Indirect_SSS * ambientColor;
// #ifdef OVERWORLD_SHADER
// if(LabSSS > 0.0) Indirect_lighting += (1.0-SkySSS) * LightningPhase * lightningEffect * pow(lightmap.y,10);
@ -1487,6 +1596,9 @@ void main() {
/////////////////////////////////////////////////////////////////////////
// shadowColor *= 0.0;
// SSSColor *= 0.0;
#ifdef SSS_view
albedo = vec3(1);
NdotL = 0;
@ -1495,11 +1607,14 @@ void main() {
Direct_lighting *= AO;
#endif
#ifdef OVERWORLD_SHADER
// Direct_lighting = max(shadowColor*NdotL, SSSColor);
#ifdef AO_in_sunlight
Direct_lighting = (shadowColor*NdotL + SSSColor) * (AO*0.7+0.3);
// Direct_lighting = max(shadowColor*NdotL * (AO*0.7+0.3), SSSColor);
Direct_lighting = shadowColor*NdotL*(AO*0.7+0.3) + SSSColor * (1.0-NdotL);
#else
Direct_lighting = shadowColor*NdotL + SSSColor;
// Direct_lighting = max(shadowColor*NdotL, SSSColor);
Direct_lighting = shadowColor*NdotL + SSSColor * (1.0-NdotL);
#endif
#endif
@ -1515,17 +1630,13 @@ void main() {
#if defined DEFERRED_SPECULAR
vec3 specularNoises = vec3(BN.xy, blueNoise());
// DoSpecularReflections(FINAL_COLOR, viewPos, feetPlayerPos_normalized, WsunVec, specularNoises, normal, SpecularTex.r, SpecularTex.g, albedo, shadowColor, lightmap.y, hand);
FINAL_COLOR = specularReflections(viewPos, feetPlayerPos_normalized, WsunVec, specularNoises, normal, SpecularTex.r, SpecularTex.g, albedo, FINAL_COLOR, shadowColor, lightmap.y, hand, isWater || (!isWater && isEyeInWater == 1));
vec3 specularNormal = slopednormal;
if (dot(slopednormal, (feetPlayerPos_normalized)) > 0.0) specularNormal = FlatNormals;
FINAL_COLOR = specularReflections(viewPos, feetPlayerPos_normalized, WsunVec, specularNoises, specularNormal, SpecularTex.r, SpecularTex.g, albedo, FINAL_COLOR, shadowColor, lightmap.y, hand, isWater || (!isWater && isEyeInWater == 1));
#endif
gl_FragData[0].rgb = FINAL_COLOR;
// gl_FragData[0].rgb = vec3(1) * Absorbtion;
}else{
vec3 Background = vec3(0.0);
@ -1613,11 +1724,22 @@ void main() {
gl_FragData[0].rgb = viewPos * 0.001;
#endif
#if DEBUG_VIEW == debug_FILTERED_STUFF
// if(hideGUI == 1){
// gl_FragData[0].rgb = texture2D(colortex14, texcoord).xyz;
if(hideGUI == 1) gl_FragData[0].rgb = vec3(1) * (1.0 - SSAO_SSS.y);
if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * pow(SSAO_SSS.x,6.0);
if(swappedDepth >= 1.0) gl_FragData[0].rgb = vec3(0.5);
// gl_FragData[0].rgb = vec3(1) * pow(1-texture2D(colortex14, texcoord).y,1);
// gl_FragData[0].rgb = vec3(1) * texture2D(colortex14, texcoord).x;
float value = SSAO_SSS.y;
value = pow(value,5);
value = 1-pow(1-value,5);
// value = calculateSSAO(viewPos,worldToView(testNorm),R2_dither());
if(hideGUI == 1) value = pow(SSAO_SSS.x,6);
gl_FragData[0].rgb = vec3(value);
if(swappedDepth >= 1.0) gl_FragData[0].rgb = vec3(1.0);
// }
// if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * exp(-10*filteredShadow.y);//exp(-7*(1-clamp(1.0 - filteredShadow.x,0.0,1.0)));
#endif
// gl_FragData[0].rgb = albedo*30;
@ -1630,5 +1752,6 @@ void main() {
// gl_FragData[0].rgb = vec3(1) * filteredShadow.y;
// if(swappedDepth >= 1.0) gl_FragData[0].rgb += vec3(0.5);
/* RENDERTARGETS:3 */
}

View File

@ -255,7 +255,9 @@ void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEn
}
vec3 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
uniform float waterEnteredAltitude;
vec4 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = 8;
vec3 start = toShadowSpaceProjected(rayStart);
@ -274,6 +276,16 @@ vec3 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither,
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
// float distanceFromWaterSurface = -(normalize(dVWorld).y + (cameraPosition.y - waterEnteredAltitude)/(waterEnteredAltitude/2)) * 0.5 + 0.5;
// distanceFromWaterSurface = clamp(distanceFromWaterSurface, 0.0,1.0);
// distanceFromWaterSurface = exp(-7.0*distanceFromWaterSurface*distanceFromWaterSurface);
// float distanceFromWaterSurface2 = normalize(dVWorld).y + (cameraPosition.y - waterEnteredAltitude)/waterEnteredAltitude;
// distanceFromWaterSurface2 = clamp(-distanceFromWaterSurface2,0.0,1.0);
// distanceFromWaterSurface2 = exp(-7*pow(distanceFromWaterSurface2,1.5));
#ifdef OVERWORLD_SHADER
float lowlightlevel = clamp(eyeBrightnessSmooth.y/240.0,0.1,1.0);
float phase = fogPhase(VdotL) * 5.0;
@ -289,6 +301,8 @@ vec3 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither,
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
float distanceFromWaterSurface = max(-(progressW.y - waterEnteredAltitude),0.0);
vec3 sh = vec3(1.0);
#ifdef OVERWORLD_SHADER
vec3 spPos = start.xyz + dV*d;
@ -318,27 +332,33 @@ vec3 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither,
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow(progressW, WsunVec);
sh *= GetCloudShadow(progressW, WsunVec * lightCol.a);
#endif
#endif
float bubble = exp2(-10.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0));
float caustics = mix(max(max(waterCaustics(progressW, WsunVec), phase*0.5) * mix(0.5, 200.0, bubble), phase), 1.0, lowlightlevel);
// float caustics = mix(max(max(waterCaustics(progressW, WsunVec), phase*0.5) * mix(0.5, 200.0, bubble), phase), 1.0, lowlightlevel);
// float caustics = max(max(waterCaustics(progressW, WsunVec), phase*0.5) * mix(0.5, 200.0, bubble), phase);
float caustics = max(max(waterCaustics(progressW, WsunVec), phase*0.5) * mix(0.5, 1.5, bubble), phase) ;//* abs(WsunVec.y);
vec3 Directlight = lightSource * sh * phase * caustics*abs(WsunVec.y) * lowlightlevel;
vec3 Indirectlight = ambient * lowlightlevel;
vec3 WaterAbsorbance = exp(-waterCoefs * rayLength * d);
vec3 sunAbsorbance = exp(-waterCoefs * (distanceFromWaterSurface/abs(WsunVec.y)));
vec3 WaterAbsorbance = exp(-waterCoefs * distanceFromWaterSurface);
vec3 light = (Indirectlight + Directlight) * WaterAbsorbance * scatterCoef;
vec3 Directlight = lightSource * sh * phase * caustics * sunAbsorbance;
vec3 Indirectlight = ambient * WaterAbsorbance;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
vec3 volumeCoeff = exp(-waterCoefs * rayLength * dd);
vec3 volumeCoeff = exp(-waterCoefs * length(dd*dVWorld));
vL += (light - light * volumeCoeff) / waterCoefs * absorbance;
absorbance *= volumeCoeff;
}
return vL;
return vec4(vL, dot(absorbance,vec3(0.335)));
}
vec4 blueNoise(vec2 coord){
@ -370,127 +390,101 @@ float encodeVec2(vec2 a){
uniform int framemod8;
#include "/lib/TAA_jitter.glsl"
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
{
vec2 du = vec2(texelSize.x*2., 0.0);
vec2 dv = vec2(0.0, texelSize.y*2.);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x);
vec3 dmin = dmc;
dmin = dmin.z > dtr.z ? dtr : dmin;
dmin = dmin.z > dtl.z ? dtl : dmin;
dmin = dmin.z > dbl.z ? dbl : dmin;
dmin = dmin.z > dbr.z ? dbr : dmin;
#ifdef TAA_UPSCALING
dmin.xy = dmin.xy/RENDER_SCALE;
#endif
return dmin;
}
vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) {
#ifdef DISTANT_HORIZONS
mat4 projectionMatrix = depthCheck ? dhPreviousProjection : gbufferPreviousProjection;
return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
#else
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
#endif
}
vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
vec4 viewPos = vec4(0.0);
vec3 feetPlayerPos = vec3(0.0);
vec4 iProjDiag = vec4(0.0);
#ifdef DISTANT_HORIZONS
if (depthCheck) {
iProjDiag = vec4(dhProjectionInverse[0].x, dhProjectionInverse[1].y, dhProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + dhProjectionInverse[3];
viewPos.xyz /= viewPos.w;
} else {
#endif
iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3];
viewPos.xyz /= viewPos.w;
#ifdef DISTANT_HORIZONS
}
#endif
return viewPos.xyz;
}
vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, vec4 color){
vec2 texcoord = gl_FragCoord.xy * texelSize;
vec2 VLtexCoord = texcoord/VL_RENDER_RESOLUTION;
// vec3 closestToCamera = closestToCamera5taps(texcoord, depthtex0);
// vec3 viewPos_5tap = toScreenSpace(closestToCamera);
// get previous frames position stuff for UV
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - VLtexCoord/RENDER_SCALE;
previousPosition.xy = VLtexCoord + velocity;
vec4 currentFrame = color;
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame;
// vec4 col0 = currentFrame; // can use this because its the center sample.
// vec4 col1 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, texelSize.y));
// vec4 col2 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, -texelSize.y));
// vec4 col3 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, -texelSize.y));
// vec4 col4 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, texelSize.y));
// vec4 col5 = texture2D(colortex0, VLtexCoord + vec2( 0.0, texelSize.y));
// vec4 col6 = texture2D(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y));
// vec4 col7 = texture2D(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0));
// vec4 col8 = texture2D(colortex0, VLtexCoord + vec2( texelSize.x, 0.0));
// vec4 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8))))))));
// vec4 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8))))))));
// // colMin = 0.5 * (colMin + min(col0,min(col5,min(col6,min(col7,col8)))));
// // colMax = 0.5 * (colMax + max(col0,max(col5,max(col6,max(col7,col8)))));
vec4 frameHistory = texture2D(colortex10, previousPosition.xy*VL_RENDER_RESOLUTION);
vec4 clampedFrameHistory = frameHistory;
// vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax);
float blendFactor = 0.25;
blendFactor = clamp(length(velocity/texelSize),blendFactor,0.2);
// if(min(frameHistory.a,rejection) > 0.0) blendFactor = 1.0;
return mix(clampedFrameHistory, currentFrame, blendFactor);
}
float convertHandDepth(float depth) {
float ndcDepth = depth * 2.0 - 1.0;
ndcDepth /= MC_HAND_DEPTH;
return ndcDepth * 0.5 + 0.5;
}
vec3 alterCoords(in vec3 coords, bool lighting){
float theDistance = length(coords + (lighting ? vec3(0.0) : cameraPosition));
coords.x = max(coords.x,0.0);
coords.y = coords.y;
coords.z = coords.z/3;
return coords;
}
vec4 raymarchTest(
in vec3 viewPosition,
in vec2 dither
){
vec3 color = vec3(0.0);
float totalAbsorbance = 1.0;
float expFactor = 16.0;
float minHeight = 250.0;
float maxHeight = minHeight + 100.0;
#if defined DISTANT_HORIZONS
float maxdist = dhFarPlane - 16.0;
#else
float maxdist = far*4;
#endif
float referenceDistance = length(viewPosition) < maxdist ? length(viewPosition) - 1.0 : 100000000.0;
int SAMPLECOUNT = 8;
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * viewPosition + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = wpos - gbufferModelViewInverse[3].xyz;
vec3 dVWorldN = normalize(dVWorld);
// dVWorld *= dVWorldN/abs(dVWorldN.y);
// float maxLength = min(length(dVWorld), 16 * 8)/length(dVWorld);
// dVWorld *= maxLength;
// float cloudRange = max(minHeight - cameraPosition.y,0.0);
float cloudRange = max(minHeight - cameraPosition.y, 0.0);
vec3 rayDirection = dVWorldN.xyz * ( (maxHeight - minHeight) / length(alterCoords(dVWorldN, false)) / SAMPLECOUNT);
// float cloudRange = mix(max(cameraPosition.y - maxHeight,0.0), max(minHeight - cameraPosition.y,0.0), clamp(rayDirection.y,0.0,1.0));
vec3 rayProgress = rayDirection*dither.x + cameraPosition + (rayDirection / length(alterCoords(rayDirection, false))) * 200;
float dL = length(rayDirection);
// vec3 rayDirection = dVWorldN.xyz * ( (maxHeight - minHeight) / abs(dVWorldN.y) / SAMPLECOUNT);
// float flip = mix(max(cameraPosition.y - maxHeight,0.0), max(minHeight - cameraPosition.y,0.0), clamp(rayDirection.y,0.0,1.0));
// vec3 rayProgress = rayDirection*dither.x + cameraPosition + (rayDirection / abs(rayDirection.y)) *flip;
// float dL = length(rayDirection);
for (int i = 0; i < SAMPLECOUNT; i++) {
if(length(rayProgress - cameraPosition) > referenceDistance) break;
float d = (pow(expFactor, float(i + dither.x)/float(SAMPLECOUNT))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i + dither.y)/float(SAMPLECOUNT)) * log(expFactor) / float(SAMPLECOUNT)/(expFactor-1.0);
float theDistance = length(alterCoords(rayProgress-cameraPosition, true));
float fogDensity = min(max(texture2D(noisetex, rayProgress.xz/2048).b-0.5,0.0)*2.0,1.0) * clamp((minHeight+50) - theDistance, 0.0, clamp(theDistance-minHeight,0,1));
float fogVolumeCoeff = exp(-fogDensity*dd*dL);
// vec3 lighting = vec3(1.0) * (1.0-clamp((minHeight-50) - theDistance,0,1));
vec3 lighting = vec3(1.0) * clamp(minHeight - theDistance/1.2,0,1);
color += (lighting - lighting * fogVolumeCoeff) * totalAbsorbance;
totalAbsorbance *= fogVolumeCoeff;
rayProgress += rayDirection;
}
return vec4(color, totalAbsorbance);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -529,13 +523,14 @@ void main() {
#endif
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 viewPos0_water = toScreenSpace(vec3(tc/RENDER_SCALE, z0));
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos0 + gbufferModelViewInverse[3].xyz;
vec3 playerPos_normalized = normalize(playerPos);
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 directLightColor = lightCol.rgb / 2400.0;
@ -575,11 +570,18 @@ void main() {
#endif
if (isEyeInWater == 1){
vec3 underWaterFog = waterVolumetrics(vec3(0.0), viewPos0, length(viewPos0), BN, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor , dot(normalize(viewPos0), normalize(sunVec* lightCol.a ) ));
// vec3 underWaterFog = waterVolumetrics(vec3(0.0), viewPos0, length(viewPos0), BN, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor , dot(normalize(viewPos0), normalize(sunVec* lightCol.a ) ));
// VolumetricFog = vec4(underWaterFog, 1.0);
vec4 underWaterFog = waterVolumetrics(vec3(0.0), viewPos0_water, length(viewPos0_water), BN, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor , dot(normalize(viewPos0_water), normalize(sunVec* lightCol.a ) ));
VolumetricFog = vec4(underWaterFog, 1.0);
// VolumetricFog.rgb = underWaterFog.rgb;
VolumetricFog = vec4(underWaterFog.rgb, 1.0);
}
// VolumetricFog = raymarchTest(viewPos0, BN);
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);

View File

@ -82,7 +82,7 @@ void main() {
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition) ;
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
refractedSunVec = refract(lightCol.a*WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;

View File

@ -389,9 +389,7 @@ vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){
vec2 velocity = previousPosition.xy - texcoord/RENDER_SCALE;
previousPosition.xy = texcoord + velocity;
// vec4 currentFrame = texture2D_bicubic(colortex0, VLtexCoord);
vec4 currentFrame = texture2D(colortex0, VLtexCoord );
// vec4 currentFrame = texelFetch2D(colortex0, ivec2(VLtexCoord/texelSize),0);
vec4 currentFrame = texture2D(colortex0, VLtexCoord);
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame;
@ -406,29 +404,13 @@ vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){
vec4 colMax = max(currentFrame,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8))))))));
vec4 colMin = min(currentFrame,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8))))))));
// colMin = 0.5 * (colMin + min(currentFrame,min(col5,min(col6,min(col7,col8)))));
// colMax = 0.5 * (colMax + max(currentFrame,max(col5,max(col6,max(col7,col8)))));
// vec4 col0 = texture(colortex0, VLtexCoord + vec2( texelSize.x, 0.0));
// vec4 col1 = texture(colortex0, VLtexCoord + vec2( 0.0, texelSize.y));
// vec4 col2 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0));
// vec4 col3 = texture(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y));
// vec4 colMin = min(currentFrame, min(col0, min(col1, min(col2, col3))));
// vec4 colMax = max(currentFrame, max(col0, max(col1, max(col2, col3))));
vec4 frameHistory = texture2D(colortex10, previousPosition.xy);
vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax);
float blendingFactor = 0.1;
// if((min(max(clampedFrameHistory.a - frameHistory.a,0.0) / 0.0000001, 1.0)) > 0.0) blendingFactor = 1.0;
// if(abs(clampedFrameHistory.a-frameHistory.a) > 0.1 && abs(currentFrame.a-frameHistory.a) > 0.1) blendingFactor = 1.0;
// if(abs(currentFrame.a - frameHistory.a) > 0.6) blendingFactor = 1.0;
if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0;
// blendingFactor = clamp(blendingFactor + abs(clampedFrameHistory.a - frameHistory.a),0.0,1.0);
// DEBUG = abs(clampedFrameHistory.a - frameHistory.a) > 0.1 ? 0. : 1.0;
// DEBUG = clamp(abs(clampedFrameHistory.a - frameHistory.a),0.0,1.0);
@ -436,6 +418,8 @@ vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){
return clamp(mix(clampedFrameHistory, currentFrame, blendingFactor),0.0,65000.0);
}
uniform float waterEnteredAltitude;
void main() {
/* RENDERTARGETS:7,3,10 */
@ -468,9 +452,13 @@ void main() {
vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth0);
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 playerPos_normalized = normVec(playerPos);
vec3 playerPos222 = mat3(gbufferModelViewInverse) * toScreenSpace_DH(texcoord/RENDER_SCALE, 1.0,1.0) + gbufferModelViewInverse[3].xyz ;
vec3 viewPos_alt = toScreenSpace(vec3(texcoord/RENDER_SCALE, z2));
vec3 playerPos_alt = mat3(gbufferModelViewInverse) * viewPos_alt + gbufferModelViewInverse[3].xyz;
float linearDistance = length(playerPos);
float linearDistance_cylinder = length(playerPos.xz);
@ -484,10 +472,14 @@ void main() {
////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- //////
vec4 data = texelFetch2D(colortex11,ivec2(texcoord/texelSize),0).rgba;
vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ;
vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ;
vec4 unpack1 = vec4(decodeVec2(data.b),decodeVec2(data.a)) ;
vec4 albedo = vec4(unpack0.ba,unpack1.rg);
vec2 tangentNormals = unpack0.xy*2.0-1.0;
bool nameTagMask = abs(unpack1.a - 0.1) < 0.01;
float nametagbackground = nameTagMask ? 0.25 : 1.0;
if(albedo.a < 0.01) tangentNormals = vec2(0.0);
@ -522,7 +514,7 @@ void main() {
// #endif
// vec4 temporallyFilteredVL = vl;
// vec4 temporallyFilteredVL = texture2D(colortex10, texcoord*VL_RENDER_RESOLUTION);
// temporallyFilteredVL = texture2D(colortex0, texcoord*VL_RENDER_RESOLUTION);
float bloomyFogMult = 1.0;
@ -542,11 +534,11 @@ void main() {
vec4 TranslucentShader = texture2D(colortex2, texcoord);
// color = vec3(texcoord-0.5,0.0) * mat3(gbufferModelViewInverse);
// apply block breaking effect.
if(albedo.a > 0.01 && !isWater && TranslucentShader.a <= 0.0 && !isEntity) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb;
// if(albedo.a > 0.01 && !isWater && TranslucentShader.a <= 0.0 && !isEntity) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb;
////// --------------- BLEND TRANSLUCENT GBUFFERS
//////////// and do border fog on opaque and translucents
#if defined BorderFog
#ifdef DISTANT_HORIZONS
float fog = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance_cylinder / dhRenderDistance,0.0)*3.0,1.0) );
@ -571,17 +563,20 @@ void main() {
float fog = 0.0;
#endif
if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint
if(!isWater) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ;
// if(!isWater) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(fog, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ;
#endif
#ifdef BorderFog
TranslucentShader = mix(TranslucentShader, vec4(0.0), fog);
#endif
// #ifdef BorderFog
// TranslucentShader = mix(TranslucentShader, vec4(0.0), fog);
// #endif
color *= (1.0-TranslucentShader.a);
color += TranslucentShader.rgb*10.0;
color += TranslucentShader.rgb*10.0 ;
}
////// --------------- VARIOUS FOG EFFECTS (behind volumetric fog)
@ -611,36 +606,40 @@ void main() {
////// --------------- underwater fog
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
// float dirtAmount = Dirt_Amount;
// vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
// vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);// dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 absorption = exp(-2.0 * totEpsilon * linearDistance);
vec3 fixedAbsorption = exp(-30.0 * totEpsilon) ;
vec3 finalAbsorption = (absorption + fixedAbsorption * 5.0 * (1.0 + nightVision*10));
// vec3 finalAbsorption = absorption;
float distanceFromWaterSurface = normalize(playerPos).y + 1.0 + (cameraPosition.y - waterEnteredAltitude)/waterEnteredAltitude;
distanceFromWaterSurface = clamp(distanceFromWaterSurface, 0.0,1.0);
linearDistance = length(vec3(playerPos.x,max(-playerPos.y,0.0),playerPos.z));
vec3 transmittance = exp(-totEpsilon * linearDistance);
color.rgb *= transmittance;
// in vanilla, the water fog has a max distance of ~7 chunks
float fogfade = max(1.0 - linearDistance / min(far, 16.0*7.0), 0.0);
fogfade *= fogfade;
// fogfade = exp(-5.0* (1.0-fogfade));
vec3 transmittance2 = exp(-totEpsilon * 25.0);
float fogfade = 1.0 - max((1.0 - linearDistance / min(far, 16.0*7.0) ),0);
color.rgb += (transmittance2 * scatterCoef) * fogfade;
color.rgb = mix(fixedAbsorption, color.rgb * finalAbsorption, fogfade);
// color.rgb = color.rgb * finalAbsorption;
bloomyFogMult *= 0.4;
bloomyFogMult *= 0.5;
}
////// --------------- BLEND FOG INTO SCENE
//////////// apply VL fog over opaque and translucents
bloomyFogMult *= temporallyFilteredVL.a;
color *= temporallyFilteredVL.a;
color += temporallyFilteredVL.rgb;
#if defined IS_IRIS
color *= min(temporallyFilteredVL.a + (1-nametagbackground),1.0);
color += temporallyFilteredVL.rgb * nametagbackground;
#else
color *= temporallyFilteredVL.a ;
color += temporallyFilteredVL.rgb ;
#endif
// color.rgb = vec3(nameTagMask);
////// --------------- VARIOUS FOG EFFECTS (in front of volumetric fog)
//////////// blindness, nightvision, liquid fogs and misc fogs
@ -690,6 +689,7 @@ void main() {
// color.rgb = vec3(DEBUG);
gl_FragData[0].r = bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0);
// gl_FragData[1].rgb = vec3(tangentNormals.xy,0.0) * 0.1 ;
// gl_FragData[1].rgb = vec3(1.0) * ld( (data.a > 0.0 ? data.a : texture2D(depthtex0, texcoord).x ) ) ;
// gl_FragData[1].rgb = gl_FragData[1].rgb * (1.0-TranslucentShader.a) + TranslucentShader.rgb*10.0;

View File

@ -419,8 +419,7 @@ vec4 computeTAA(vec2 texcoord, bool hand){
if(hand) blendingFactor = clamp(length(velocity/texelSize),blendingFactor,1.0);
////// Increases blending factor when far from AABB, reduces ghosting
// blendingFactor = min(blendingFactor + luma(min(max(clampedframeHistory-frameHistory,0.0) / frameHistory, 1.0)),1.0);
// blendingFactor = min(blendingFactor + luma(abs(clampedframeHistory - frameHistory)/clampedframeHistory) ,1.0);
blendingFactor = clamp(blendingFactor + luma(abs(clampedframeHistory - frameHistory)/clampedframeHistory),0.0,1.0);
// if(luma(abs(clampedframeHistory - frameHistory)) > 0.01) blendingFactor = 1.0;

View File

@ -44,8 +44,9 @@ uniform vec3 sunPosition;
uniform vec3 cameraPosition;
// uniform float far;
uniform ivec2 eyeBrightnessSmooth;
// uniform ivec2 eyeBrightness;
uniform float caveDetection;
uniform int isEyeInWater;
vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.);
@ -53,6 +54,7 @@ vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.);
#include "/lib/ROBOBO_sky.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/Shadow_Params.glsl"
#include "/lib/waterBump.glsl"
vec3 WsunVec = mat3(gbufferModelViewInverse)*sunVec;
// vec3 WsunVec = normalize(LightDir);
@ -95,6 +97,7 @@ uniform float near;
uniform float dhFarPlane;
uniform float dhNearPlane;
#include "/lib/DistantHorizons_projections.glsl"
vec3 DH_toScreenSpace(vec3 p) {

View File

@ -207,7 +207,7 @@ float fogPhase2(float lightPoint){
return exponential;
}
vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL, float lightleakFix){
vec4 waterVolumetrics( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL, float lightleakFix){
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
@ -238,8 +238,16 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
ambient = max(ambient * (normalize(wpos).y*0.3+0.7),0.0);
// ambient = max(ambient * (normalize(wpos).y*0.3+0.7),0.0);
float expFactor = 11.0;
vec3 sh = vec3(1.0);
// do this outside raymarch loop, masking the water surface is good enough
#if defined VL_CLOUDS_SHADOWS && defined OVERWORLD_SHADER
sh *= GetCloudShadow(wpos+cameraPosition, WsunVec);
#endif
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
@ -248,7 +256,6 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
vec3 progressW = gbufferModelViewInverse[3].xyz + cameraPosition + d*dVWorld;
vec3 sh = vec3(1.0);
#ifdef OVERWORLD_SHADER
vec3 spPos = start.xyz + dV*d;
@ -272,17 +279,14 @@ vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float
if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001);
}
#else
sh = vec3(shadow2D(shadow, pos).x);
sh *= vec3(shadow2D(shadow, pos).x);
#endif
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow(progressW, WsunVec);
#endif
#endif
vec3 sunAbsorbance = exp(-waterCoefs * estSunDepth * d);
vec3 ambientAbsorbance = exp(-waterCoefs * estEndDepth * d);
// vec3 WaterAbsorbance = exp(-waterCoefs * rayLength * d);
vec3 Directlight = lightSource * sh * phase * sunAbsorbance;
vec3 Indirectlight = ambient * ambientAbsorbance;
@ -394,25 +398,21 @@ void main() {
// float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon * dirtAmount + waterEpsilon;
vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);//dirtEpsilon * dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
#ifdef BIOME_TINT_WATER
// yoink the biome tint written in this buffer for water only.
if(iswater){
vec2 translucentdata = texelFetch2D(colortex11,ivec2(tc/texelSize),0).gb;
vec3 wateralbedo = normalize(vec3(decodeVec2(translucentdata.x),decodeVec2(translucentdata.y).x)+0.00001) * 0.5 + 0.5;
scatterCoef = dirtAmount * wateralbedo / 3.14;
vec2 data = texelFetch2D(colortex11,ivec2(tc/texelSize),0).gb;
vec3 wateralbedo = vec3(decodeVec2(data.x),decodeVec2(data.y).r);
scatterCoef = dirtAmount * normalize(wateralbedo.rgb+1e-7) / 3.14;
}
#endif
// vec3 directLightColor = lightCol.rgb / 2400.0;
// vec3 indirectLightColor = averageSkyCol / 1500.0;
// vec3 indirectLightColor_dynamic = averageSkyCol_Clouds / 900.0;
vec3 directLightColor = lightCol.rgb / 2400.0;
vec3 indirectLightColor = averageSkyCol / 1200.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds / 900.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds / 1200.0;
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
@ -422,13 +422,7 @@ void main() {
vec3 playerPos0 = mat3(gbufferModelViewInverse) * viewPos0;
#ifdef OVERWORLD_SHADER
// vec2 lightmap = decodeVec2(texture2D(colortex14, tc).a);
// vec2 lightmap = vec2(0.0,texture2D(colortex14, tc).a);
vec2 lightmap = decodeVec2(texelFetch2D(colortex14,ivec2(tc/texelSize),0).x);
#ifdef DISTANT_HORIZONS
if(z >= 1.0) lightmap.y = 0.99;
@ -438,17 +432,9 @@ void main() {
lightmap.y = 1.0;
#endif
// float Vdiff = distance(viewPos1, viewPos0) * 2.0;
// float VdotU = playerPos.y;
// float estimatedDepth = Vdiff * abs(VdotU); //assuming water plane
float Vdiff = distance(viewPos1, viewPos0);
float estimatedDepth = Vdiff * abs(normalize(playerPos).y);
float estimatedSunDepth = (Vdiff * 0.5) / abs(WsunVec.y); //assuming water plane
Vdiff *= 2.0;
// Vdiff = Vdiff * (1.0 - clamp(exp(-Vdiff),0.0,1.0)) + max(estimatedDepth - 1.0,0.0);
// estimatedDepth = max(estimatedDepth - 1.0,0.0);
float estimatedSunDepth = Vdiff / abs(WsunVec.y); //assuming water plane
indirectLightColor_dynamic *= ambient_brightness * lightmap.y*lightmap.y;
@ -461,24 +447,17 @@ void main() {
if(!iswater){
#ifdef OVERWORLD_SHADER
vec4 VolumetricClouds = GetVolumetricClouds(viewPos1, vec2(noise_1, noise_2), WsunVec, directLightColor, indirectLightColor);
float atmosphereAlpha = 1.0;
vec4 VolumetricFog = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor, indirectLightColor_dynamic, atmosphereAlpha, VolumetricClouds.rgb);
finalVolumetrics = VolumetricClouds;
// VolumetricClouds.a *= atmosphereAlpha;
finalVolumetrics.rgb += VolumetricClouds.rgb;
#endif
#if defined NETHER_SHADER || defined END_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos1, noise_1, noise_2);
#endif
// #if defined OVERWORLD_SHADER
// vec4 VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a);
// #endif
finalVolumetrics.rgb = finalVolumetrics.rgb * VolumetricFog.a + VolumetricFog.rgb;
finalVolumetrics.a *= VolumetricFog.a;
}
@ -486,9 +465,8 @@ void main() {
vec4 underwaterVlFog = vec4(0,0,0,1);
float lightleakfix = clamp(lightmap.y + (1-caveDetection),0.0,1.0);
if(iswater && isEyeInWater != 1) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) ,lightleakfix);
finalVolumetrics.rgb += underwaterVlFog.rgb;
if(iswater && isEyeInWater != 1) finalVolumetrics = waterVolumetrics(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) ,lightleakfix);
gl_FragData[0] = clamp(finalVolumetrics, 0.0, 65000.0);
}