improve gtao/rtao/ssgi in all dimensions/lighting situations. improve RP sky support,.

This commit is contained in:
Xonk 2024-06-25 20:34:45 -04:00
parent 38c514c2b3
commit 7607c0ff41
14 changed files with 432 additions and 231 deletions

View File

@ -364,7 +364,8 @@ void main() {
vec3 Albedo = toLinear(TEXTURE.rgb); vec3 Albedo = toLinear(TEXTURE.rgb);
vec2 lightmap = lmtexcoord.zw; vec2 lightmap = clamp(lmtexcoord.zw,0.0,1.0);
#ifndef OVERWORLD_SHADER #ifndef OVERWORLD_SHADER
lightmap.y = 1.0; lightmap.y = 1.0;

View File

@ -902,32 +902,18 @@ void main() {
MinimumLightColor = MinimumLightColor + 0.7 * MinimumLightColor * dot(slopednormal, feetPlayerPos_normalized); MinimumLightColor = MinimumLightColor + 0.7 * MinimumLightColor * dot(slopednormal, feetPlayerPos_normalized);
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// FILTER STUFF //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
vec3 filteredShadow = vec3(1.412,1.0,0.0);
vec2 SSAO_SSS = vec2(1.0);
#if defined DISTANT_HORIZONS && defined DH_AMBIENT_OCCLUSION
BilateralUpscale_REUSE_Z(colortex3, colortex14, colortex12, gl_FragCoord.xy-1.5, DH_mixedLinearZ, SSAO_SSS, filteredShadow, hand);
#else
BilateralUpscale_REUSE_Z(colortex3, colortex14, depthtex0, gl_FragCoord.xy-1.5, ld(z0), SSAO_SSS, filteredShadow, hand);
#endif
float ShadowBlockerDepth = filteredShadow.y;
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// START DRAW //////////////////////////////////////// //////////////////////////////// START DRAW ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
if (swappedDepth >= 1.0) { if (swappedDepth >= 1.0) {
vec3 Background = vec3(0.0);
#ifdef OVERWORLD_SHADER #ifdef OVERWORLD_SHADER
vec3 Background = vec3(0.0);
#if RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 0 float atmosphereGround = 1.0 - exp2(-50.0 * pow(clamp(feetPlayerPos_normalized.y+0.025,0.0,1.0),2.0) ); // darken the ground in the sky.
#if RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 0 || RESOURCEPACK_SKY == 3
// vec3 orbitstar = vec3(feetPlayerPos_normalized.x,abs(feetPlayerPos_normalized.y),feetPlayerPos_normalized.z); orbitstar.x -= WsunVec.x*0.2; // vec3 orbitstar = vec3(feetPlayerPos_normalized.x,abs(feetPlayerPos_normalized.y),feetPlayerPos_normalized.z); orbitstar.x -= WsunVec.x*0.2;
vec3 orbitstar = normalize(mat3(gbufferModelViewInverse) * toScreenSpace(vec3(texcoord/RENDER_SCALE,1.0))); vec3 orbitstar = normalize(mat3(gbufferModelViewInverse) * toScreenSpace(vec3(texcoord/RENDER_SCALE,1.0)));
float radiance = 2.39996 - (worldTime + worldDay*24000.0) / 24000.0; float radiance = 2.39996 - (worldTime + worldDay*24000.0) / 24000.0;
// float radiance = 2.39996 + frameTimeCounter; // float radiance = 2.39996 + frameTimeCounter;
@ -936,43 +922,57 @@ void main() {
orbitstar.xy *= rotationMatrix; orbitstar.xy *= rotationMatrix;
Background += stars(orbitstar) * 10.0 * clamp(-unsigned_WsunVec.y*2.0,0.0,1.0); Background += stars(orbitstar) * 10.0 * clamp(-unsigned_WsunVec.y*2.0,0.0,1.0);
#endif
#if RESOURCEPACK_SKY == 2 #if !defined ambientLight_only && (RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 0)
Background += toLinear(texture2D(colortex10, texcoord).rgb * (255.0 * 2.0));
#else
#if RESOURCEPACK_SKY == 1
Background += toLinear(texture2D(colortex10, texcoord).rgb * (255.0 * 2.0));
#endif
#ifndef ambientLight_only
Background += drawSun(dot(lightCol.a * WsunVec, feetPlayerPos_normalized),0, DirectLightColor,vec3(0.0)); Background += drawSun(dot(lightCol.a * WsunVec, feetPlayerPos_normalized),0, DirectLightColor,vec3(0.0));
Background += drawMoon(feetPlayerPos_normalized, lightCol.a * WsunVec, DirectLightColor*20, Background); Background += drawMoon(feetPlayerPos_normalized, lightCol.a * WsunVec, DirectLightColor*20, Background);
#endif #endif
#endif
#ifdef SKY_GROUND Background *= atmosphereGround;
Background *= 1.0 - exp2(-50.0 * pow(clamp(feetPlayerPos_normalized.y+0.025,0.0,1.0),2.0) ); // darken the ground in the sky.
#endif #endif
vec3 Sky = skyFromTex(feetPlayerPos_normalized, colortex4)/30.0 * Sky_Brightness; vec3 Sky = skyFromTex(feetPlayerPos_normalized, colortex4)/30.0 * Sky_Brightness;
Background += Sky; Background += Sky;
#if defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN #endif
vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise, RENDER_SCALE.x);
Background = Background * Clouds.a + Clouds.rgb; #if RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 2 || RESOURCEPACK_SKY == 3
vec3 resourcePackskyBox = toLinear(texture2D(colortex10, texcoord).rgb * 5.0) * 15.0 * clamp(unsigned_WsunVec.y*2.0,0.1,1.0);
#ifdef SKY_GROUND
resourcePackskyBox *= atmosphereGround;
#endif #endif
gl_FragData[0].rgb = clamp(fp10Dither(Background, triangularize(noise_2)), 0.0, 65000.); Background += resourcePackskyBox;
#endif #endif
#if defined NETHER_SHADER || defined END_SHADER #if defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN
gl_FragData[0].rgb = vec3(0); vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise, RENDER_SCALE.x);
Background = Background * Clouds.a + Clouds.rgb;
#endif #endif
gl_FragData[0].rgb = clamp(fp10Dither(Background, triangularize(noise_2)), 0.0, 65000.);
} else { } else {
feetPlayerPos += gbufferModelViewInverse[3].xyz; feetPlayerPos += gbufferModelViewInverse[3].xyz;
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// FILTER STUFF //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
vec3 filteredShadow = vec3(1.412,1.0,0.0);
vec2 SSAO_SSS = vec2(1.0);
#if defined DISTANT_HORIZONS && defined DH_AMBIENT_OCCLUSION
BilateralUpscale_REUSE_Z(colortex3, colortex14, colortex12, gl_FragCoord.xy-1.5, DH_mixedLinearZ, SSAO_SSS, filteredShadow, hand);
#else
BilateralUpscale_REUSE_Z(colortex3, colortex14, depthtex0, gl_FragCoord.xy-1.5, ld(z0), SSAO_SSS, filteredShadow, hand);
#endif
float ShadowBlockerDepth = filteredShadow.y;
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// MAJOR LIGHTSOURCE STUFF //////////////////////// ///////////////////////////// MAJOR LIGHTSOURCE STUFF ////////////////////////
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
@ -1006,7 +1006,7 @@ void main() {
vec3 cubicRadius = clamp( min((1.0-shadowEdgePos)*fadeLength, shadowEdgePos*fadeLength),0.0,1.0); vec3 cubicRadius = clamp( min((1.0-shadowEdgePos)*fadeLength, shadowEdgePos*fadeLength),0.0,1.0);
float shadowmapFade = cubicRadius.x*cubicRadius.y*cubicRadius.z; float shadowmapFade = cubicRadius.x*cubicRadius.y*cubicRadius.z;
shadowmapFade = 1.0 - pow(1.0-pow(shadowmapFade,1.5),3.0); // make it nice and soft :) shadowmapFade = 1.0 - pow(1.0-pow(shadowmapFade,1.5),3.0);
float shadowMapFalloff = shadowmapFade; float shadowMapFalloff = shadowmapFade;
float shadowMapFalloff2 = shadowmapFade; float shadowMapFalloff2 = shadowmapFade;
@ -1035,32 +1035,32 @@ void main() {
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// UNDER WATER SHADING //////////////////////////////// //////////////////////////////// UNDER WATER SHADING ////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
if ((isEyeInWater == 0 && isWater) || (isEyeInWater == 1 && !isWater)){
#ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
float Vdiff = distance(viewPos, viewPos0)*mix(5.0,2.0,clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0)); if ((isEyeInWater == 0 && isWater) || (isEyeInWater == 1 && !isWater)){
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane #ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
// make it such that the estimated depth flips to be correct when entering water. float Vdiff = distance(viewPos, viewPos0)*mix(5.0,2.0,clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0));
if (isEyeInWater == 1){ float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane
estimatedDepth = 40.0 * pow(max(1.0-lightmap.y,0.0),2.0);
MinimumLightColor = vec3(10.0);
}
float depthfalloff = 1.0 - clamp(exp(-0.1*estimatedDepth),0.0,1.0); // make it such that the estimated depth flips to be correct when entering water.
if (isEyeInWater == 1){
float estimatedSunDepth = Vdiff; //assuming water plane estimatedDepth = 40.0 * pow(max(1.0-lightmap.y,0.0),2.0);
Absorbtion = mix(exp(-2.0 * totEpsilon * estimatedDepth), exp(-8.0 * totEpsilon), depthfalloff); MinimumLightColor = vec3(10.0);
// 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));
} }
float depthfalloff = 1.0 - clamp(exp(-0.1*estimatedDepth),0.0,1.0);
float estimatedSunDepth = Vdiff; //assuming water plane
Absorbtion = mix(exp(-2.0 * totEpsilon * estimatedDepth), exp(-8.0 * totEpsilon), depthfalloff);
// 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));
}
#ifdef END_SHADER #ifdef END_SHADER
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0); float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
@ -1079,15 +1079,15 @@ void main() {
AmbientLightColor += lightColors * (endPhase*endPhase) * (1.0-exp(vec3(0.6,2.0,2) * -(endPhase*0.1))) ; AmbientLightColor += lightColors * (endPhase*endPhase) * (1.0-exp(vec3(0.6,2.0,2) * -(endPhase*0.1))) ;
#endif #endif
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
///////////////////////////// INDIRECT LIGHTING ///////////////////////////// ///////////////////////////// INDIRECT LIGHTING /////////////////////////////
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#if defined OVERWORLD_SHADER #if defined OVERWORLD_SHADER
Indirect_lighting = AmbientLightColor;
float skylight = 1.0; float skylight = 1.0;
#if indirect_effect != 2
#if indirect_effect == 0 || indirect_effect == 1 || indirect_effect == 2
float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y*1.5; float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y*1.5;
if(isGrass) SkylightDir = 1.5; if(isGrass) SkylightDir = 1.5;
@ -1098,14 +1098,21 @@ void main() {
#endif #endif
#endif #endif
Indirect_lighting = doIndirectLighting(AmbientLightColor * skylight, MinimumLightColor, lightmap.y); #if indirect_effect == 3 || indirect_effect == 4
skylight = 2.5;
#endif
Indirect_lighting += doIndirectLighting(AmbientLightColor * skylight, MinimumLightColor, lightmap.y);
#endif #endif
#ifdef NETHER_SHADER #ifdef NETHER_SHADER
Indirect_lighting = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 30.0; Indirect_lighting = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 30.0;
vec3 up = skyCloudsFromTexLOD2(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 30.0; vec3 up = skyCloudsFromTexLOD2(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 30.0;
Indirect_lighting = mix(up, Indirect_lighting, clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0)); #if indirect_effect == 1
Indirect_lighting = mix(up, Indirect_lighting, clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0));
#endif
AmbientLightColor = Indirect_lighting / 5.0; AmbientLightColor = Indirect_lighting / 5.0;
#endif #endif
@ -1116,70 +1123,6 @@ void main() {
Indirect_lighting = Indirect_lighting + 0.7*mix(-Indirect_lighting, Indirect_lighting * dot(slopednormal, feetPlayerPos_normalized), clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0)); Indirect_lighting = Indirect_lighting + 0.7*mix(-Indirect_lighting, Indirect_lighting * dot(slopednormal, feetPlayerPos_normalized), clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0));
#endif #endif
#ifdef OVERWORLD_SHADER
Indirect_lighting += LightningFlashLighting;
#endif
#ifdef SSS_view
Indirect_lighting = vec3(3.0);
#endif
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// EFFECTS FOR INDIRECT /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
float SkySSS = 1.0;
vec3 AO = vec3(1.0);
#if indirect_effect == 0
AO = pow(1.0 - vanilla_AO*vanilla_AO,5.0) * vec3(1.0);
Indirect_lighting *= AO;
#endif
#if indirect_effect == 1
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);
// use the min of vanilla ao so they dont overdarken eachother
AO = vec3( min(vanillaAO_curve, SSAO_curve) );
Indirect_lighting *= AO;
#endif
// GTAO... this is so dumb but whatevverrr
#if indirect_effect == 2
float vanillaAO_curve = pow(1.0 - vanilla_AO*vanilla_AO,5.0);
vec2 r2 = fract(R2_samples((frameCounter%40000) + frameCounter*2) + bnoise);
float GTAO = !hand ? ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z), viewPos, worldToView(slopednormal), r2) : 1.0;
AO = vec3(min(vanillaAO_curve,GTAO));
vec3 IndirectColor = Indirect_lighting;
float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y*1.5;
if(isGrass) SkylightDir = 1.5;
skylight = max(pow(viewToWorld(FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1-lightmap.y)*0.8);
skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-GTAO, 0.5),2.0) ));
IndirectColor *= skylight;
Indirect_lighting = doIndirectLighting(IndirectColor, lightmap.y) * AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
if(!hand) Indirect_lighting = ApplySSRT(viewPos, normal, vec3(bnoise, noise_2), AmbientLightColor, MinimumLightColor, lightmap.y, isGrass, isDHrange);
#endif
#if defined END_SHADER
Direct_lighting *= AO;
#endif
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING
#ifdef IS_LPV_ENABLED #ifdef IS_LPV_ENABLED
vec3 normalOffset = vec3(0.0); vec3 normalOffset = vec3(0.0);
@ -1196,7 +1139,52 @@ void main() {
const vec3 lpvPos = vec3(0.0); const vec3 lpvPos = vec3(0.0);
#endif #endif
Indirect_lighting += doBlockLightLighting( vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, exposure, feetPlayerPos, lpvPos); vec3 blockLightColor = doBlockLightLighting( vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, exposure, feetPlayerPos, lpvPos);
Indirect_lighting += blockLightColor;
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// EFFECTS FOR INDIRECT /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
float SkySSS = 1.0;
vec3 AO = vec3(1.0);
#if indirect_effect == 0
AO = vec3(pow(1.0 - vanilla_AO*vanilla_AO,5.0));
Indirect_lighting *= AO;
#endif
#if indirect_effect == 1
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);
// use the min of vanilla ao so they dont overdarken eachother
AO = vec3( min(vanillaAO_curve, SSAO_curve) );
Indirect_lighting *= AO;
#endif
// // GTAO... this is so dumb but whatevverrr
#if indirect_effect == 2
float vanillaAO_curve = pow(1.0 - vanilla_AO*vanilla_AO,5.0);
vec2 r2 = fract(R2_samples((frameCounter%40000) + frameCounter*2) + bnoise);
float GTAO = !hand ? ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z), viewPos, worldToView(slopednormal), r2) : 1.0;
AO = vec3(min(vanillaAO_curve,GTAO));
Indirect_lighting *= AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
if(!hand) Indirect_lighting = ApplySSRT(Indirect_lighting, blockLightColor, viewPos, normal, vec3(bnoise, noise_2), lightmap.y, isGrass, isDHrange);
#endif
#if defined END_SHADER
Direct_lighting *= AO;
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///////////////////////// SUB SURFACE SCATTERING //////////////////////////// ///////////////////////// SUB SURFACE SCATTERING ////////////////////////////

View File

@ -18,6 +18,7 @@ option.RESOURCEPACK_SKY = Resource Pack Sky
value.RESOURCEPACK_SKY.0 = Do not use value.RESOURCEPACK_SKY.0 = Do not use
value.RESOURCEPACK_SKY.1 = Sky + Shader sun/moon value.RESOURCEPACK_SKY.1 = Sky + Shader sun/moon
value.RESOURCEPACK_SKY.2 = Full sky value.RESOURCEPACK_SKY.2 = Full sky
value.RESOURCEPACK_SKY.3 = Shader Sky + RP sun/moon
screen.Waving_Stuff = Waving Stuff screen.Waving_Stuff = Waving Stuff
option.WAVY_PLANTS = Waving Plants option.WAVY_PLANTS = Waving Plants

View File

@ -5,12 +5,14 @@ const float k = 1.8;
const float d0 = 0.04 + max(64.0 - shadowDistance, 0.0)/64.0 * 0.26; const float d0 = 0.04 + max(64.0 - shadowDistance, 0.0)/64.0 * 0.26;
const float d1 = 0.61; const float d1 = 0.61;
float a = exp(d0); float a = exp(d0);
float b = (exp(d1)-a)*150./128.0;
// thank you Espen // thank you Espen
#ifdef DISTANT_HORIZONS_SHADOWMAP // #ifdef DISTANT_HORIZONS_SHADOWMAP
float b = (exp(d1)-a)*min(dhRenderDistance, shadowDistance)/shadowDistance; // float b = (exp(d1)-a)*min(dhRenderDistance, shadowDistance)/shadowDistance;
#else // #else
float b = (exp(d1)-a)*min(far+16.0*3.5, shadowDistance)/shadowDistance; // float b = (exp(d1)-a)*min(far+16.0*3.5, shadowDistance)/shadowDistance;
#endif // #endif
vec4 BiasShadowProjection(in vec4 projectedShadowSpacePosition) { vec4 BiasShadowProjection(in vec4 projectedShadowSpacePosition) {

View File

@ -11,7 +11,7 @@ void GriAndEminShadowFix(
float MinimumValue = 0.05; float MinimumValue = 0.05;
// give a tiny boost to the distance mulitplier when shadowmap resolution is below 2048.0 // give a tiny boost to the distance mulitplier when shadowmap resolution is below 2048.0
float ResMultiplier = 1.0 + (shadowDistance/8.0)*(1.0 - min(shadowMapResolution,2048.0)/2048.0)*0.3; float ResMultiplier = 1.0 + (shadowDistance/8.0)*(1.0 - min(shadowMapResolution,2048)/2048.0)*0.3;
float DistanceMultiplier = max(1.0 - max(1.0 - length(WorldPos) / shadowDistance, 0.0), MinimumValue) * ResMultiplier; float DistanceMultiplier = max(1.0 - max(1.0 - length(WorldPos) / shadowDistance, 0.0), MinimumValue) * ResMultiplier;

View File

@ -210,29 +210,36 @@ vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
direction.xy = normalize(direction.xy); direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen //get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; vec3 maxLengths = (step(0.0,direction)-clipPosition) / direction;
float mult = maxLengths.y; float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither; vec3 stepv = (direction * mult) / quality*vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE ;
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases float minZ = spos.z;
float maxZ = spos.z;
for(int i = 0; i < int(quality); i++){ for(int i = 0; i < int(quality); i++){
spos += stepv; if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
#ifdef UseQuarterResDepth
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0); #ifdef UseQuarterResDepth
#else float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0));
float sp = linZ(texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r); #else
#endif float sp = texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r;
float currZ = linZ(spos.z); #endif
float currZ = linZ(spos.z);
float nextZ = linZ(sp);
if(nextZ < currZ && (sp <= max(minZ,maxZ) && sp >= min(minZ,maxZ))) return vec3(spos.xy/RENDER_SCALE,sp);
float biasamount = 0.00005;
minZ = maxZ - biasamount / currZ;
maxZ += stepv.z;
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv; spos += stepv;
} }
return vec3(1.1); return vec3(1.1);
@ -269,18 +276,21 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
//Do one iteration for closest texel (good contact shadows) //Do one iteration for closest texel (good contact shadows)
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
spos += stepv/(stepSize/2);
spos += stepv;
float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for(int i = 0; i < iterations; i++){ for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1); if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
spos += stepv*noise; spos += stepv*noise;
#ifdef UseQuarterResDepth #ifdef UseQuarterResDepth
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0); float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0);
#else #else
float sp = linZ(texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r); float sp = linZ(texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r);
#endif #endif
float currZ = linZ(spos.z); float currZ = linZ(spos.z);
if( sp < currZ) { if( sp < currZ) {
@ -291,13 +301,71 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
return vec3(1.1); return vec3(1.1);
} }
vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
vec3 worldpos = mat3(gbufferModelViewInverse) * position;
float dist = 1.0 + length(worldpos)/far; // step length as distance increases
float stepSize = stepsizes / dist;
int maxSteps = 10;
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ?
(-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far;
vec3 end = toClipSpace3(position+dir*rayLength) ;
vec3 direction = end-clipPosition ; //convert to clip space
float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize;
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0;
vec3 stepv = direction/len;
int iterations = min(int(min(len, mult*len)-2), maxSteps);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0);// + stepv*noise;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
float minZ = spos.z;
float maxZ = spos.z;
for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
#ifdef UseQuarterResDepth
float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0));
#else
float sp = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).r;
#endif
float currZ = linZ(spos.z);
float nextZ = linZ(sp);
if(nextZ < currZ && (sp <= max(minZ,maxZ) && sp >= min(minZ,maxZ))) return vec3(spos.xy/RENDER_SCALE,sp);
float biasamount = 0.00005;
minZ = maxZ-biasamount / currZ;
maxZ += stepv.z;
spos += stepv*(noise*0.25+0.75);
}
return vec3(1.1);
}
vec3 ApplySSRT( vec3 ApplySSRT(
in vec3 unchangedIndirect,
in vec3 blockLightColor,
vec3 viewPos, vec3 viewPos,
vec3 normal, vec3 normal,
vec3 noise, vec3 noise,
vec3 indirectLightColor, // vec3 indirectLightColor,
vec3 minLightColor, // vec3 minLightColor,
float lightmap, float lightmap,
bool isGrass, bool isGrass,
@ -306,88 +374,66 @@ vec3 ApplySSRT(
int nrays = RAY_COUNT; int nrays = RAY_COUNT;
vec3 radiance = vec3(0.0); vec3 radiance = vec3(0.0);
vec3 occlusion = vec3(0.0); vec3 occlusion = vec3(0.0);
vec3 skycontribution = vec3(0.0); vec3 skycontribution = unchangedIndirect;
vec3 radiance2 = vec3(0.0);
vec3 occlusion2 = vec3(0.0); vec3 occlusion2 = vec3(0.0);
vec3 skycontribution2 = vec3(0.0); vec3 skycontribution2 = unchangedIndirect;
vec3 ambientColor = doIndirectLighting(indirectLightColor * 2.5, minLightColor, lightmap);
vec3 bouncedLight = vec3(0.0);
for (int i = 0; i < nrays; i++){ for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i; int seed = (frameCounter%40000)*nrays+i;
vec2 ij = fract(R2_samples(seed) + noise.xy); vec2 ij = fract(R2_samples(seed) + noise.xy);
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij)) ,1.0); vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij)), lightmap);
#ifdef HQ_SSGI #ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, noise.z, 50.); // ssr rt vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, noise.z, 50.); // ssr rt
#else #else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 30., isLOD); // choc sspt vec3 rayHit = RT_alternate(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 10., isLOD); // choc sspt
#endif #endif
#ifdef SKY_CONTRIBUTION_IN_SSRT #ifdef SKY_CONTRIBUTION_IN_SSRT
#ifdef OVERWORLD_SHADER #ifdef OVERWORLD_SHADER
if(isGrass) rayDir.y = clamp(rayDir.y + 0.5,-1,1); skycontribution = doIndirectLighting(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30.0, minLightColor, lightmap) + blockLightColor;
skycontribution = mix(ambientColor, pow(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30, vec3(0.7)), lightmap);
#else #else
skycontribution = pow(skyCloudsFromTexLOD2(rayDir, colortex4, 6).rgb / 30.0,vec3(0.7)); skycontribution = pow(skyCloudsFromTexLOD2(rayDir, colortex4, 6).rgb / 30.0,vec3(0.7)) + blockLightColor;
#endif #endif
skycontribution = max(skycontribution, minLightColor * max(MIN_LIGHT_AMOUNT*0.01, nightVision * 0.1));
#else #else
#ifdef OVERWORLD_SHADER #ifdef OVERWORLD_SHADER
if(isGrass) rayDir.y = clamp(rayDir.y + 0.25,-1,1); skycontribution = unchangedIndirect * (max(rayDir.y,pow(1.0-lightmap,2))*0.95+0.05);
skycontribution = ambientColor * (max(rayDir.y,pow(1.0-lightmap,2))*0.95+0.05);
#else
skycontribution = ambientColor;
#endif #endif
#if indirect_effect == 4
skycontribution2 = ambientColor;
#endif
#endif #endif
if (rayHit.z < 1.){ radiance += skycontribution;
radiance2 += skycontribution2;
if (rayHit.z < 1.0){
#if indirect_effect == 4 #if indirect_effect == 4
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; 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){ if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){
radiance += texture2D(colortex5, previousPosition.xy).rgb * GI_Strength + skycontribution; bouncedLight = texture2D(colortex5, previousPosition.xy).rgb * GI_Strength;
} else{
radiance += skycontribution; radiance += bouncedLight;
radiance2 += bouncedLight;
} }
#else
radiance += skycontribution;
#endif #endif
occlusion += skycontribution * GI_Strength; occlusion += skycontribution;
occlusion2 += skycontribution2;
#if indirect_effect == 4
occlusion2 += skycontribution2 * GI_Strength;
#endif
} else {
radiance += skycontribution;
} }
} }
if(isLOD) return max(radiance/nrays, 0.0); if(isLOD) return max(radiance/nrays, 0.0);
occlusion *= AO_Strength; #ifdef SKY_CONTRIBUTION_IN_SSRT
return max((radiance - occlusion)/nrays,0.0);
#if indirect_effect == 4
return max(radiance/nrays - max(occlusion, occlusion2*0.5)/nrays, 0.0);
#else #else
return max(radiance/nrays - occlusion/nrays, 0.0); float threshold = isGrass ? 0.8 : (pow(1.0-lightmap,2.0) * 0.9 + 0.1);
return max((radiance - occlusion)/nrays, (radiance2 - occlusion2)/nrays * threshold);
#endif #endif
} }

View File

@ -671,7 +671,7 @@ const vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631)
#define LIGHTNING_FLASH // FOR OPTIFINE USERS. some mods change the sky color, which can trigger the lightning flash detection. #define LIGHTNING_FLASH // FOR OPTIFINE USERS. some mods change the sky color, which can trigger the lightning flash detection.
#define RESOURCEPACK_SKY 0 // [0 1 2] #define RESOURCEPACK_SKY 0 // [0 1 2 3]
#ifdef IS_IRIS #ifdef IS_IRIS
#define TRANSLUCENT_ENTITIES #define TRANSLUCENT_ENTITIES

View File

@ -86,22 +86,36 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo
float dist = 1.0 + clamp(position.z*position.z/50.0,0.0,2.0); // shrink sample size as distance increases float dist = 1.0 + clamp(position.z*position.z/50.0,0.0,2.0); // shrink sample size as distance increases
for (int i = 0; i <= int(quality); i++) { for (int i = 0; i <= int(quality); i++) {
// float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0));
// if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/RENDER_SCALE,sp);
// spos += stepv;
// //small bias
// float biasamount = (0.0002 + 0.0015*pow(depthcancleoffset,5) ) / dist;
// if(hand) biasamount = 0.00035;
// minZ = maxZ-biasamount / ld(spos.z);
// maxZ += stepv.z;
float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0)); float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0));
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/RENDER_SCALE,sp); float currZ = linZ(spos.z);
float nextZ = linZ(sp);
// if(nextZ < currZ) {
if(abs(nextZ-currZ)/currZ < 0.15 && sp <= max(minZ,maxZ) && sp >= min(minZ,maxZ)) return vec3(spos.xy/RENDER_SCALE,sp);
// }
float biasamount = 0.005;
minZ = maxZ-biasamount / linZ(spos.z);
maxZ += stepv.z;
spos += stepv; spos += stepv;
//small bias
float biasamount = (0.0002 + 0.0015*pow(depthcancleoffset,5) ) / dist;
if(hand) biasamount = 0.00035;
minZ = maxZ-biasamount / ld(spos.z);
maxZ += stepv.z;
reflectLength += 1.0 / quality; // for shit reflectLength += 1.0 / quality; // for shit
} }
return vec3(1.1); return vec3(1.1);
} }

View File

@ -10,7 +10,7 @@ beacon.beam.depth = true
iris.features.optional = ENTITY_TRANSLUCENT REVERSED_CULLING COMPUTE_SHADERS CUSTOM_IMAGES BLOCK_EMISSION_ATTRIBUTE iris.features.optional = ENTITY_TRANSLUCENT REVERSED_CULLING COMPUTE_SHADERS CUSTOM_IMAGES BLOCK_EMISSION_ATTRIBUTE
#if RESOURCEPACK_SKY == 2 #if RESOURCEPACK_SKY == 2 || RESOURCEPACK_SKY == 3
sun=true sun=true
moon=true moon=true
#else #else

View File

@ -1,7 +1,43 @@
#version 120 #version 120
#include "/lib/settings.glsl"
/* RENDERTARGETS:0 */ #if RESOURCEPACK_SKY != 0
varying vec4 color;
varying vec2 texcoord;
uniform sampler2D texture;
uniform int renderStage;
float interleaved_gradientNoise(){
// vec2 coord = gl_FragCoord.xy + (frameCounter%40000);
vec2 coord = gl_FragCoord.xy ;
// vec2 coord = gl_FragCoord.xy;
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
return noise ;
}
#endif
void main() { void main() {
discard;
#if RESOURCEPACK_SKY != 0
/* RENDERTARGETS:10 */
vec4 COLOR = texture2D(texture, texcoord.xy)*color;
#if RESOURCEPACK_SKY == 3
if(renderStage == 1 || renderStage == 3) { discard; return; }
#endif
#if RESOURCEPACK_SKY == 1
if(renderStage == 4 || renderStage == 5) { discard; return; }
#else
if(renderStage == 4) COLOR.rgb *= 5.0;
#endif
COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0);
gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a);
#else
discard;
#endif
} }

View File

@ -1,5 +1,40 @@
#version 120 #version 120
#include "/lib/settings.glsl"
#if RESOURCEPACK_SKY != 0
#include "/lib/res_params.glsl"
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
varying vec4 color;
varying vec2 texcoord;
uniform vec2 texelSize;
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() { void main() {
gl_Position = ftransform(); gl_Position = ftransform();
#if RESOURCEPACK_SKY != 0
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
color = gl_Color;
#ifdef TAA_UPSCALING
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;
#endif
#endif
} }

View File

@ -24,12 +24,19 @@ void main() {
vec4 COLOR = texture2D(texture, texcoord.xy)*color; vec4 COLOR = texture2D(texture, texcoord.xy)*color;
if(renderStage == 4) COLOR.rgb *= 5.0; #if RESOURCEPACK_SKY == 3
// if(renderStage == 5) COLOR.rgb *= 1.5; if(renderStage == 1 || renderStage == 3) { discard; return; }
#endif
COLOR.rgb = max(COLOR.rgb * (0.9+0.1*interleaved_gradientNoise()), 0.0); #if RESOURCEPACK_SKY == 1
if(renderStage == 4 || renderStage == 5) { discard; return; }
#else
if(renderStage == 4) COLOR.rgb *= 5.0;
#endif
gl_FragData[0] = vec4(COLOR.rgb/255.0, COLOR.a); COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0);
gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a);
#else #else
discard; discard;
#endif #endif

View File

@ -1,7 +1,43 @@
#version 120 #version 120
#include "/lib/settings.glsl"
/* RENDERTARGETS:0 */ #if RESOURCEPACK_SKY != 0
varying vec4 color;
varying vec2 texcoord;
uniform sampler2D texture;
uniform int renderStage;
float interleaved_gradientNoise(){
// vec2 coord = gl_FragCoord.xy + (frameCounter%40000);
vec2 coord = gl_FragCoord.xy ;
// vec2 coord = gl_FragCoord.xy;
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
return noise ;
}
#endif
void main() { void main() {
discard;
#if RESOURCEPACK_SKY != 0
/* RENDERTARGETS:10 */
vec4 COLOR = texture2D(texture, texcoord.xy)*color;
#if RESOURCEPACK_SKY == 3
if(renderStage == 1 || renderStage == 3) { discard; return; }
#endif
#if RESOURCEPACK_SKY == 1
if(renderStage == 4 || renderStage == 5) { discard; return; }
#else
if(renderStage == 4) COLOR.rgb *= 5.0;
#endif
COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0);
gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a);
#else
discard;
#endif
} }

View File

@ -1,5 +1,40 @@
#version 120 #version 120
#include "/lib/settings.glsl"
#if RESOURCEPACK_SKY != 0
#include "/lib/res_params.glsl"
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
varying vec4 color;
varying vec2 texcoord;
uniform vec2 texelSize;
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
#endif
void main() { void main() {
gl_Position = ftransform(); gl_Position = ftransform();
#if RESOURCEPACK_SKY != 0
texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
color = gl_Color;
#ifdef TAA_UPSCALING
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;
#endif
#endif
} }