diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh index bbc4dee..8ec06e8 100644 --- a/shaders/composite1.fsh +++ b/shaders/composite1.fsh @@ -561,47 +561,22 @@ vec3 TangentToWorld(vec3 N, vec3 H, float roughness){ return vec3((T * H.x) + (B * H.y) + (N * H.z)); } -void rtAO(inout vec3 lighting, vec3 normal, vec2 noise, vec3 fragpos, float lightmap, float inShadow){ - int nrays = 4; - float occlude = 0.0; - - float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength); - - for (int i = 0; i < nrays; i++){ - int seed = (frameCounter%40000)*nrays+i; - vec2 ij = fract(R2_samples(seed) + noise.rg); - - - vec3 rayDir = TangentToWorld( normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0) ; - - #ifdef HQ_SSGI - vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 30.); // ssr rt - #else - vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 24.); // choc sspt - #endif - - // vec3 lightDir = normalize(vec3(0.2,0.8,0.2)); - // float skyLightDir = dot(rayDir,lightDir); // the positons where the occlusion happens - - float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens - if (rayHit.z > 1.0) occlude += max(rayDir.y,1-AO_Strength); - - - } - // occlude = mix( occlude,1, inShadow); - // occlude = occlude*0.5 + 0.5; - lighting *= 3.0; - lighting *= mix(occlude/nrays,1.0,0) ; +vec3 applyContrast(vec3 color, float contrast){ + return (color - 0.5) * contrast + 0.5; } -void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmap, vec3 albedo){ - int nrays = RAY_COUNT; - vec3 intRadiance = vec3(0.0); - vec3 occlude = vec3(0.0); - lighting *= 1.50; - float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength); +void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, vec2 lightmaps, vec3 skylightcolor, vec3 torchcolor){ + int nrays = RAY_COUNT; + + vec3 radiance = vec3(0.0); + vec3 occlusion = vec3(0.0); + vec3 skycontribution = vec3(0.0); + float skyLM = 0.0; + vec3 torchlight = vec3(0.0); + DoRTAmbientLighting(torchcolor, lightmaps, skyLM, torchlight, skylightcolor); + for (int i = 0; i < nrays; i++){ int seed = (frameCounter%40000)*nrays+i; vec2 ij = fract(R2_samples(seed) + noise ); @@ -613,23 +588,35 @@ void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightm #else vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt #endif - - float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens - + + #ifdef SKY_CONTRIBUTION_IN_SSRT + skycontribution = (skyCloudsFromTex(rayDir, colortex4).rgb / 15.0) * skyLM + torchlight; + #else + skycontribution = (skylightcolor * skyLM) * max(rayDir.y,1 - AO_Strength) + torchlight; + #endif + if (rayHit.z < 1.){ - vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; - previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; - previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; - if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) - intRadiance = 0 + texture2D(colortex5,previousPosition.xy).rgb * GI_Strength ; - else - intRadiance += lighting*skyLightDir; // make sure ambient light exists but at screen edges when you turn + + #if indirect_effect == 4 + vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; + previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; + previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; + if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ + radiance += applyContrast(texture2D(colortex5,previousPosition.xy).rgb, GI_Strength) + skycontribution; + } else { + radiance += skycontribution; + } + #else + radiance += skycontribution; + #endif + + occlusion += skycontribution; - }else{ - intRadiance += lighting*skyLightDir; + } else { + radiance += skycontribution; } } - lighting = intRadiance/nrays; + lighting = (radiance - occlusion)/nrays; } @@ -1052,14 +1039,18 @@ void main() { if(isGrass) ambientCoefs.y = 0.75; float skylight = clamp(ambientCoefs.y + 0.5,0.25,2.0) * 1.35; - #if indirect_effect == 2 || indirect_effect == 3 || indirect_effect == 4 - if (!hand) skylight = 1.0; - #endif - AmbientLightColor += (lightningEffect * 10) * skylight * pow(lightmap.y,2); #ifndef ambientSSS_view - Indirect_lighting = DoAmbientLighting(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, skylight); + + #if indirect_effect == 2 + skylight = 1.0; + #endif + + #if indirect_effect != 3 || indirect_effect != 4 + Indirect_lighting = DoAmbientLighting(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, skylight); + #endif + #else Indirect_lighting = vec3(0.0); #endif @@ -1085,14 +1076,10 @@ void main() { if (!hand) AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z), fragpos, worldToView(slopednormal), r2, debug) * vec3(1.0); #endif - // RTAO - #if indirect_effect == 3 - if (!hand) rtAO(AO, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.y, NdotL*Shadows); - #endif - - // SSGI - #if indirect_effect == 4 - if (!hand) rtGI(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.y, albedo); + // RTAO and/or SSGI + #if indirect_effect == 3 || indirect_effect == 4 + AO = vec3(1.0); + if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.xy, AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B)); #endif #ifndef AO_in_sunlight diff --git a/shaders/deferred.fsh b/shaders/deferred.fsh index e0ff9ad..e7904ff 100644 --- a/shaders/deferred.fsh +++ b/shaders/deferred.fsh @@ -161,6 +161,9 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+ sky = sky*clouds.a + clouds.rgb/5.0; vec4 VL_Fog = getVolumetricRays(mat3(gbufferModelView)*viewVector*1024., fract(frameCounter/1.6180339887), averageSkyCol); + + if(viewVector.y < -0.025) VL_Fog.rgb *= clamp( exp(viewVector.y) - 1.0,0.25,1.0) ; + sky = sky*VL_Fog.a + VL_Fog.rgb*20; gl_FragData[0] = vec4(sky,1.0); diff --git a/shaders/lang/en_us.lang b/shaders/lang/en_us.lang index 8c9856c..6e987a5 100644 --- a/shaders/lang/en_us.lang +++ b/shaders/lang/en_us.lang @@ -74,6 +74,7 @@ screen.Ambient_light = Ambient Light option.GI_Strength = GI Multiplier option.HQ_SSGI = Long Range SSGI option.Hand_Held_lights = Hand Held Light + option.SKY_CONTRIBUTION_IN_SSRT = High Quality Ambient Light option.ambientOcclusionLevel = Vanilla AO Amount option.ambient_brightness = Ambient Light Brightness option.MIN_LIGHT_AMOUNT = Minimum Light Brightness @@ -323,6 +324,8 @@ screen.Ambient_light.comment = Configure settings related to the lighting in sha option.GI_Strength.comment = Configure the strength of the global illumination created by SSGI. §bWhat is this?§r global illumination in this scenario specifically is the light bouncing off a surface and onto some other area. option.HQ_SSGI.comment = Toggle long range screen-space global illumination. §aPERFORMANCE COST:§r very high option.Hand_Held_lights.comment = Toggle shader-side hand held lightsources. §aPERFORMANCE COST:§r very low + option.SKY_CONTRIBUTION_IN_SSRT.comment = Allow the RTAO or SSGI to take the entire sky and fog into account to create high quality lighting for shaded areas. This may introduce more noise. §aPERFORMANCE COST:§r medium + option.ambientOcclusionLevel.comment = Configure the strength of the ambient occlusion from vanilla minecraft. §bWhat is this?§r This ambient occlusion is in minecraft even without shaders enabled. option.ambient_brightness.comment = Configure the brightnes of lighting in shaded places option.MIN_LIGHT_AMOUNT.comment = Configure the minimum amount of light that can be in shaded places. diff --git a/shaders/lib/diffuse_lighting.glsl b/shaders/lib/diffuse_lighting.glsl index 3027632..97fca9b 100644 --- a/shaders/lib/diffuse_lighting.glsl +++ b/shaders/lib/diffuse_lighting.glsl @@ -21,6 +21,17 @@ vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float sky return SkyLight * skyLightDir + TorchLight; } +void DoRTAmbientLighting (vec3 TorchColor, vec2 Lightmap, inout float SkyLM, inout vec3 TorchLight, inout vec3 SkyLight){ + + float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap.x)),5.0)+0.1)); + TorchLM = pow(TorchLM/4,10) + pow(Lightmap.x,1.5)*0.5; + TorchLight = (TorchColor * TorchLM * 0.75) * TORCH_AMOUNT; + + SkyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5; + + SkyLight = max((SkyLight * ambient_brightness) / 10.0, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)); +} + vec3 DoDirectLighting(vec3 SunColor, float Shadow, float NdotL, float SubsurfaceScattering){ // vec3 SunLight = max(NdotL * Shadow, SubsurfaceScattering) * SunColor; diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 45857c9..7bd121e 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -90,7 +90,9 @@ #define indirect_effect 1 // [0 1 2 3 4] #define AO_in_sunlight -#define AO_Strength 0.8 // [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 AO_Strength 0.9 // [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 SKY_CONTRIBUTION_IN_SSRT // #define HQ_SSGI #define GI_Strength 1.0 // [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 ] @@ -98,6 +100,7 @@ #define STEPS 8 // [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99] #define STEP_LENGTH 12. // [4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30.] + #define SEPARATE_AO const float ambientOcclusionLevel = 1.0; // this controls vanilla minecrafts ambient occlusion. [0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ] diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 953c873..b984a43 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -78,7 +78,7 @@ PhysicsMod_support [LabPBR] ### AMBIENT LIGHT screen.Ambient_light.columns=1 - screen.Ambient_light = [Torch_Colors] [Ambient_Colors] MIN_LIGHT_AMOUNT indirect_effect AO_Strength GI_Strength ambientOcclusionLevel HQ_SSGI Hand_Held_lights + screen.Ambient_light = [Torch_Colors] [Ambient_Colors] MIN_LIGHT_AMOUNT indirect_effect AO_Strength GI_Strength ambientOcclusionLevel HQ_SSGI Hand_Held_lights SKY_CONTRIBUTION_IN_SSRT screen.Torch_Colors.columns=1 screen.Torch_Colors = TORCH_AMOUNT Emissive_Brightness Emissive_Curve TORCH_R TORCH_G TORCH_B