From ab35096ee6996f37190a7037bd88c0543a95f4f9 Mon Sep 17 00:00:00 2001 From: Xonk Date: Mon, 5 Jun 2023 21:16:31 -0400 Subject: [PATCH] ambient SSS related changes tweak overall absorption and stuff, added a standalone version to use with vanilla AO, GTAO, RTAO, and SSGI --- shaders/composite1.fsh | 154 +++++++++++++++++---------------- shaders/gbuffers_all_solid.fsh | 4 +- shaders/gbuffers_all_solid.vsh | 27 +++--- shaders/lang/en_us.lang | 12 ++- shaders/lib/settings.glsl | 2 +- shaders/shaders.properties | 4 +- 6 files changed, 110 insertions(+), 93 deletions(-) diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh index 593a5c4..ef78aa0 100644 --- a/shaders/composite1.fsh +++ b/shaders/composite1.fsh @@ -193,6 +193,8 @@ vec3 decode (vec2 encn){ n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn; return clamp(normalize(n.xyz),-1.0,1.0); } + + vec2 decodeVec2(float a){ const vec2 constant1 = 65535. / vec2( 256., 65536.); const float constant2 = 256. / 255.; @@ -335,37 +337,6 @@ float waterCaustics(vec3 wPos, vec3 lightSource) { // water waves } -// float waterCaustics(vec3 wPos, vec3 lightSource) { -// vec2 movement = vec2(frameTimeCounter*0.05); -// vec2 pos = (wPos + WsunVec/WsunVec.y*max(SEA_LEVEL - wPos.y,0.0)).xz ; -// float caustic = 1.0; -// float weightSum = 0.0; - -// float radiance = 2.39996; -// mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance))); - -// const vec2 wave_size[3] = vec2[]( -// vec2(48.,12.), -// vec2(12.,48.), -// vec2(32.) -// ); - -// float WavesLarge = clamp( pow(1.0-pow(1.0-texture2D(noisetex, pos / 600.0 ).b, 5.0),5.0),0.1,1.0); - -// for (int i = 0; i < 3; i++){ -// pos = rotationMatrix * pos ; - -// float Waves = texture2D(noisetex, pos / (wave_size[i] + (1-WavesLarge)*0.1) + movement).b; - - -// caustic += Waves/3; -// // weightSum += exp2(caustic); -// } -// return exp(1.0-(1.0-pow(1.0-abs((caustic - 1.5)*2.0)*0.5,0.5)) * 30) + 0.5 ; -// } - - - float rayTraceShadow(vec3 dir,vec3 position,float dither){ const float quality = 16.; vec3 clipPosition = toClipSpace3(position); @@ -419,71 +390,62 @@ void ssAO(inout vec3 lighting, inout float sss, vec3 fragpos,float mulfov, vec2 const float tan70 = tan(70.*3.14/180.); float dist = 1.0 + clamp(fragpos.z*fragpos.z/50.0,0,2); // shrink sample size as distance increases - float dist2 = 1-clamp(linZ(fragpos.z)*50,0,1); // shrink sample size as distance increases - float mulfov2 = gbufferProjection[1][1]/(tan70 * dist); float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*5/50.0; - float maxR2_2 = mix(500, fragpos.z*fragpos.z*mulfov2*2./50.0, dist2); - + #ifdef Ambient_SSS + float dist3 = clamp(1.0 - exp( fragpos.z*fragpos.z / -50),0,1); + float maxR2_2 = mix(10.0, fragpos.z*fragpos.z*mulfov2*2./50.0, dist3); + #endif + float rd = mulfov2 * 0.1 ; - //pre-rotate direction - float n = 0.0; - float occlusion = 0.0; - sss = 0.0; vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ; int seed = (frameCounter%40000)*2 + (1+frameCounter); float randomDir = fract(R2_samples(seed).y + noise.x ) * 1.61803398874 ; - vec3 NormalSpecific = viewToWorld(normal); - for (int j = 0; j < 7 ;j++) { + float n = 0.0; + float occlusion = 0.0; + for (int j = 0; j < 7; j++) { vec2 sp = tapLocation_alternate(j, 0.0, 7, 20, randomDir); - // vec2 sp = vogel_disk_7[j]; - float thing = sp.y < 0.0 && clamp(floor(abs(NormalSpecific.y)*2.0),0.0,1.0) < 1.0 ? rd * 10: rd; - - - vec2 sampleOffset = sp*thing; - vec2 sampleOffset2 = sp*rd ; - sampleOffset = min(sampleOffset, sampleOffset2); - // vec2 sampleOffset = sp*rd; + vec2 sampleOffset = sp*rd; ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE); if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) { vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x) * vec3(1.0/RENDER_SCALE, 1.0) ); - vec3 vec = t0.xyz - fragpos; - float dsquared = dot(vec,vec); + vec3 vec = (t0.xyz - fragpos); + float dsquared = dot(vec,vec) ; + if (dsquared > 1e-5){ if (dsquared < maxR2){ float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.); occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0); - } - if (dsquared > maxR2_2){ - float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.); - - sss += NdotV + NdotV*clamp(1.0-maxR2_2/dsquared,0.0,1.0); - - // sss += (1.0 - NdotV) ; - } + #ifdef Ambient_SSS + if(dsquared > maxR2_2){ + float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.); + sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0); + } + #endif n += 1; } } } - occlusion *= mix(2.5, 2.0 , clamp(floor(abs(NormalSpecific.y)*2.0),0.0,1.0)); + #ifdef Ambient_SSS + sss = max(1.0 - sss/n, 0.0) ; + #endif + + occlusion *= 2.0; occlusion = max(1.0 - occlusion/n, 0.0); - sss *= mix(1.0, 1.5 , clamp(floor(abs(NormalSpecific.y)*2.0),0.0,1.0)); - sss = max(1.0 - sss/n, 0.0) ; - lighting = lighting*max(occlusion,pow(lightmap.x,4)); } @@ -681,12 +643,56 @@ vec3 SubsurfaceScattering_sky(vec3 albedo, float Scattering, float Density){ vec3 absorbed = max(luma(albedo) - albedo,0.0); - vec3 scatter = exp(-sqrt(max(Scattering+0.05,0.0) * absorbed * 25)) * exp(Scattering * -5); + // vec3 scatter = exp(-sqrt(max(Scattering+0.05,0.0) * absorbed * 25)) * exp(Scattering * -5); + vec3 scatter = exp(-sqrt(Scattering * absorbed * 5)) * pow((-Scattering+1.0)*1.5,2.0); scatter *= pow(Density,LabSSS_Curve); return scatter; } +void ScreenSpace_SSS(inout float sss, vec3 fragpos, vec2 noise, vec3 normal){ + ivec2 pos = ivec2(gl_FragCoord.xy); + const float tan70 = tan(70.*3.14/180.); + + float dist = 1.0 + (clamp(fragpos.z*fragpos.z/50.0,0,2)); // shrink sample size as distance increases + float mulfov2 = gbufferProjection[1][1]/(tan70 * dist); + + float dist3 = clamp(1-exp( fragpos.z*fragpos.z / -50),0,1); + float maxR2_2 = mix(10, fragpos.z*fragpos.z*mulfov2*2./50.0, dist3); + + float rd = mulfov2 * 0.1; + + + vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ; + + int seed = (frameCounter%40000)*2 + (1+frameCounter); + float randomDir = fract(R2_samples(seed).y + noise.x ) * 1.61803398874 ; + + float n = 0.0; + for (int j = 0; j < 7 ;j++) { + + vec2 sp = tapLocation_alternate(j, 0.0, 7, 20, randomDir); + vec2 sampleOffset = sp*rd; + ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE); + + if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) { + vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x) * vec3(1.0/RENDER_SCALE, 1.0) ); + vec3 vec = t0.xyz - fragpos; + float dsquared = dot(vec,vec); + + if (dsquared > 1e-5){ + if(dsquared > maxR2_2){ + float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.); + sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0); + } + n += 1; + } + } + } + sss = max(1.0 - sss/n, 0.0); +} + + float densityAtPosSNOW(in vec3 pos){ pos /= 18.; pos.xz *= 0.5; @@ -1022,11 +1028,13 @@ void main() { #endif Indirect_lighting *= AO; - - #if indirect_effect == 1 + #ifdef Ambient_SSS + #if indirect_effect != 1 + if (!hand) ScreenSpace_SSS(SkySSS, fragpos, blueNoise(gl_FragCoord.xy).rg, FlatNormals); + #endif Indirect_lighting += SubsurfaceScattering_sky(albedo, SkySSS, LabSSS) * ((AmbientLightColor* 2.0 * ambient_brightness)* 8./150.) * pow(newLightmap.y,3) * pow(1.0-clamp(abs(ambientCoefs.y+0.5),0.0,1.0),0.1) ; - #endif + // Indirect_lighting += SubsurfaceScattering_sky(albedo, SkySSS, LabSSS) * ((AmbientLightColor* 2.0 * ambient_brightness)* 8./150.) * pow(newLightmap.y,3); #endif @@ -1086,14 +1094,12 @@ void main() { #endif #endif - Direct_lighting = DoDirectLighting(DirectLightColor, Shadows, NdotL, 0.0); - - #ifdef ambientLight_only - Direct_lighting = vec3(0.0); + DirectLightColor = vec3(0.0); #endif - + Direct_lighting = DoDirectLighting(DirectLightColor, Shadows, NdotL, 0.0); + //combine all light sources vec3 FINAL_COLOR = Indirect_lighting + Direct_lighting; @@ -1138,7 +1144,9 @@ void main() { // phasefunc = phaseg(clamp(dot(np3, WsunVec),0.0,1.0), 0.5)*10; // if(z < 1) gl_FragData[0].rgb = Custom_GGX(normal, -np3, WsunVec, SpecularTex.r, SpecularTex.g) * vec3(1.0); - // gl_FragData[0].rgb = SubsurfaceScattering_sky(albedo, SkySSS, LabSSS); + // gl_FragData[0].rgb = SubsurfaceScattering_sky(albedo, SkySSS, 1.0); + + // gl_FragData[0].rgb = clamp(1-exp( fragpos.z*fragpos.z / -50),0,1)* vec3(1); /* DRAWBUFFERS:3 */ } \ No newline at end of file diff --git a/shaders/gbuffers_all_solid.fsh b/shaders/gbuffers_all_solid.fsh index 20ae46e..8ba322f 100644 --- a/shaders/gbuffers_all_solid.fsh +++ b/shaders/gbuffers_all_solid.fsh @@ -517,8 +517,10 @@ void main() { if(EMISSIVE > 0) gl_FragData[2].a = 0.9; - if(LIGHTNING > 0.0) gl_FragData[2].a = 0.9; + #ifdef ENTITIES + if(LIGHTNING > 0) gl_FragData[2].a = 0.5; + #endif //////////////////////////////// //////////////////////////////// ALBEDO diff --git a/shaders/gbuffers_all_solid.vsh b/shaders/gbuffers_all_solid.vsh index f0288d1..9bbbe5b 100644 --- a/shaders/gbuffers_all_solid.vsh +++ b/shaders/gbuffers_all_solid.vsh @@ -185,7 +185,7 @@ void main() { vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; - FlatNormals = normalize(gl_NormalMatrix * gl_Normal); + color = gl_Color; VanillaAO = 1.0 - clamp(color.a,0,1); @@ -197,32 +197,32 @@ void main() { #endif normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal), 1.0); + FlatNormals = normalMat.xyz; +// #ifdef ENTITIES -#ifdef ENTITIES - - NameTags = 0; - // try and single out nametag text and then discard nametag background - if( dot(gl_Color.rgb, vec3(0.35)) < 1.0) NameTags = 1; - if(gl_Color.a >= 0.24 && gl_Color.a <= 0.25 ) gl_Position = vec4(10,10,10,1); +// NameTags = 0; +// // try and single out nametag text and then discard nametag background +// if( dot(gl_Color.rgb, vec3(0.35)) < 1.0) NameTags = 1; +// if(gl_Color.a >= 0.24 && gl_Color.a <= 0.25 ) gl_Position = vec4(10,10,10,1); -#endif +// #endif #ifdef WORLD - /////// ----- SSS ----- /////// + /////// ----- SSS ON BLOCKS ----- /////// // strong if(mc_Entity.x == 10001 || mc_Entity.x == 10003 || mc_Entity.x == 10004) SSSAMOUNT = 1.0; // medium - if(mc_Entity.x == 10006 || mc_Entity.x == 200) SSSAMOUNT = 1.0; + if(mc_Entity.x == 10006 || mc_Entity.x == 200) SSSAMOUNT = 0.75; // low - if(mc_Entity.x == 10007 || mc_Entity.x == 10008) SSSAMOUNT = 1.0; + if(mc_Entity.x == 10007 || mc_Entity.x == 10008) SSSAMOUNT = 0.5; #ifdef ENTITIES - /////// ----- SSS ----- /////// + /////// ----- SSS ON MOBS----- /////// // strong - if(entityId == 1100) SSSAMOUNT = 1.0; + if(entityId == 1100) SSSAMOUNT = 0.75; // medium @@ -231,6 +231,7 @@ void main() { #endif #ifdef BLOCKENTITIES + /////// ----- SSS ON BLOCK ENTITIES----- /////// // strong // medium diff --git a/shaders/lang/en_us.lang b/shaders/lang/en_us.lang index aefb9a5..886b397 100644 --- a/shaders/lang/en_us.lang +++ b/shaders/lang/en_us.lang @@ -5,6 +5,15 @@ value.indirect_effect.2 = GTAO value.indirect_effect.3 = RTAO value.indirect_effect.4 = SSGI +option.ambientOcclusionLevel = Vanilla AO Amount +option.ambient_brightness = Ambient Light Brightness +option.MIN_LIGHT_AMOUNT = Minimum Light Brightness + +option.ambient_colortype = Coloring Type +value.ambient_colortype.0 = Temperature +value.ambient_colortype.1 = RGB + + option.SSS_TYPE = SSS Mode value.SSS_TYPE.0 = RTX value.SSS_TYPE.1 = Hardcoded only @@ -14,9 +23,6 @@ option.SSS_TYPE.comment = Hardcoded means that the shader defines what gets SSS -option.ambient_colortype = Coloring Type -value.ambient_colortype.0 = Temperature -value.ambient_colortype.1 = RGB option.DOF_QUALITY=Depth Of Field value.DOF_QUALITY.-1=Off diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 16d5589..3061a9d 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -125,7 +125,7 @@ #define LabPBR_subsurface_scattering #define SSS_TYPE 1 // [0 1 2 3] -#define Ambient_SSS // ONLY WORKS WHEN SSAO IS ENABLED. SSS from the sky on stuff. +#define Ambient_SSS // subsurface scattering from the sky's light. If SSAO is enabled, this costs very little performance. #define LabSSS_Curve 1.0 // i just really like how it looks at 2.0, so i made it an option. [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ] #define Strong_SSS_strength 45 // [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2 3 4 5 6 7 8 9 10 15 20 30 35 40 45 50] #define Medium_SSS_strength 30 // [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2 3 4 5 6 7 8 9 10 15 20 30 35 40 45 50] diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 195f721..5293cea 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -62,14 +62,14 @@ screen = [Direct_Light] [World] [Ambient_light] [Fog] [Post_Processing] [Clouds] screen.Shadows = SCREENSPACE_CONTACT_SHADOWS Stochastic_Transparent_Shadows SHADOW_FRUSTRUM_CULLING CAVE_LIGHT_LEAK_FIX [Filtering] shadowMapResolution shadowDistance shadowDistanceRenderMul screen.Subsurface_Scattering.columns=1 - screen.Subsurface_Scattering = Variable_Penumbra_Shadows SSS_TYPE LabSSS_Curve Ambient_SSS mob_SSS misc_block_SSS + screen.Subsurface_Scattering = Variable_Penumbra_Shadows Ambient_SSS SSS_TYPE LabSSS_Curve mob_SSS misc_block_SSS screen.Filtering.columns=1 screen.Filtering = Variable_Penumbra_Shadows VPS_Search_Samples Min_Shadow_Filter_Radius Max_Shadow_Filter_Radius Max_Filter_Depth SHADOW_FILTER_SAMPLE_COUNT ### AMBIENT LIGHT screen.Ambient_light.columns=1 - screen.Ambient_light = [Torch_Colors] [Ambient_Colors] indirect_effect HQ_SSGI AO_Strength GI_Strength ambientOcclusionLevel + screen.Ambient_light = [Torch_Colors] [Ambient_Colors] Ambient_SSS indirect_effect AO_Strength GI_Strength ambientOcclusionLevel HQ_SSGI screen.Torch_Colors.columns=1 screen.Torch_Colors = TORCH_AMOUNT Emissive_Brightness Emissive_Curve TORCH_R TORCH_G TORCH_B