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);
vec2 lightmap = lmtexcoord.zw;
vec2 lightmap = clamp(lmtexcoord.zw,0.0,1.0);
#ifndef OVERWORLD_SHADER
lightmap.y = 1.0;

View File

@ -902,32 +902,18 @@ void main() {
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 ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
if (swappedDepth >= 1.0) {
#ifdef OVERWORLD_SHADER
vec3 Background = vec3(0.0);
#if RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 0
// vec3 orbitstar = vec3(feetPlayerPos_normalized.x,abs(feetPlayerPos_normalized.y),feetPlayerPos_normalized.z); orbitstar.x -= WsunVec.x*0.2;
vec3 Background = vec3(0.0);
#ifdef OVERWORLD_SHADER
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 = normalize(mat3(gbufferModelViewInverse) * toScreenSpace(vec3(texcoord/RENDER_SCALE,1.0)));
float radiance = 2.39996 - (worldTime + worldDay*24000.0) / 24000.0;
// float radiance = 2.39996 + frameTimeCounter;
@ -936,42 +922,56 @@ void main() {
orbitstar.xy *= rotationMatrix;
Background += stars(orbitstar) * 10.0 * clamp(-unsigned_WsunVec.y*2.0,0.0,1.0);
#endif
#if RESOURCEPACK_SKY == 2
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
#if !defined ambientLight_only && (RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 0)
Background += drawSun(dot(lightCol.a * WsunVec, feetPlayerPos_normalized),0, DirectLightColor,vec3(0.0));
Background += drawMoon(feetPlayerPos_normalized, lightCol.a * WsunVec, DirectLightColor*20, Background);
#endif
Background *= atmosphereGround;
#endif
#ifdef SKY_GROUND
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
vec3 Sky = skyFromTex(feetPlayerPos_normalized, colortex4)/30.0 * Sky_Brightness;
Background += Sky;
#endif
#if defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN
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
gl_FragData[0].rgb = clamp(fp10Dither(Background, triangularize(noise_2)), 0.0, 65000.);
Background += resourcePackskyBox;
#endif
#if defined NETHER_SHADER || defined END_SHADER
gl_FragData[0].rgb = vec3(0);
#if defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN
vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise, RENDER_SCALE.x);
Background = Background * Clouds.a + Clouds.rgb;
#endif
gl_FragData[0].rgb = clamp(fp10Dither(Background, triangularize(noise_2)), 0.0, 65000.);
} else {
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 ////////////////////////
@ -1006,7 +1006,7 @@ void main() {
vec3 cubicRadius = clamp( min((1.0-shadowEdgePos)*fadeLength, shadowEdgePos*fadeLength),0.0,1.0);
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 shadowMapFalloff2 = shadowmapFade;
@ -1035,32 +1035,32 @@ void main() {
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// 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));
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane
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
// make it such that the estimated depth flips to be correct when entering water.
if (isEyeInWater == 1){
estimatedDepth = 40.0 * pow(max(1.0-lightmap.y,0.0),2.0);
MinimumLightColor = vec3(10.0);
}
float Vdiff = distance(viewPos, viewPos0)*mix(5.0,2.0,clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0));
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane
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));
// make it such that the estimated depth flips to be correct when entering water.
if (isEyeInWater == 1){
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);
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
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))) ;
#endif
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////// INDIRECT LIGHTING /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#if defined OVERWORLD_SHADER
Indirect_lighting = AmbientLightColor;
#if defined OVERWORLD_SHADER
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;
if(isGrass) SkylightDir = 1.5;
@ -1097,16 +1097,23 @@ void main() {
skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) ));
#endif
#endif
#if indirect_effect == 3 || indirect_effect == 4
skylight = 2.5;
#endif
Indirect_lighting = doIndirectLighting(AmbientLightColor * skylight, MinimumLightColor, lightmap.y);
Indirect_lighting += doIndirectLighting(AmbientLightColor * skylight, MinimumLightColor, lightmap.y);
#endif
#ifdef NETHER_SHADER
Indirect_lighting = skyCloudsFromTexLOD2(normal, 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;
#endif
@ -1115,71 +1122,7 @@ 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));
#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
vec3 normalOffset = vec3(0.0);
@ -1194,9 +1137,54 @@ void main() {
vec3 lpvPos = GetLpvPosition(feetPlayerPos) + normalOffset;
#else
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 ////////////////////////////

View File

@ -18,6 +18,7 @@ option.RESOURCEPACK_SKY = Resource Pack Sky
value.RESOURCEPACK_SKY.0 = Do not use
value.RESOURCEPACK_SKY.1 = Sky + Shader sun/moon
value.RESOURCEPACK_SKY.2 = Full sky
value.RESOURCEPACK_SKY.3 = Shader Sky + RP sun/moon
screen.Waving_Stuff = Waving Stuff
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 d1 = 0.61;
float a = exp(d0);
float b = (exp(d1)-a)*150./128.0;
// thank you Espen
#ifdef DISTANT_HORIZONS_SHADOWMAP
float b = (exp(d1)-a)*min(dhRenderDistance, shadowDistance)/shadowDistance;
#else
float b = (exp(d1)-a)*min(far+16.0*3.5, shadowDistance)/shadowDistance;
#endif
// #ifdef DISTANT_HORIZONS_SHADOWMAP
// float b = (exp(d1)-a)*min(dhRenderDistance, shadowDistance)/shadowDistance;
// #else
// float b = (exp(d1)-a)*min(far+16.0*3.5, shadowDistance)/shadowDistance;
// #endif
vec4 BiasShadowProjection(in vec4 projectedShadowSpacePosition) {

View File

@ -11,7 +11,7 @@ void GriAndEminShadowFix(
float MinimumValue = 0.05;
// 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;

View File

@ -210,29 +210,36 @@ vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = maxLengths.y;
vec3 maxLengths = (step(0.0,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
vec3 stepv = (direction * mult) / quality*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++){
spos += stepv;
#ifdef UseQuarterResDepth
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
#else
float sp = linZ(texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r);
#endif
float currZ = linZ(spos.z);
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;
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;
}
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)
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
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
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);
spos += stepv*noise;
#ifdef UseQuarterResDepth
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0);
#else
float sp = linZ(texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r);
#endif
float currZ = linZ(spos.z);
if( sp < currZ) {
@ -291,13 +301,71 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
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(
in vec3 unchangedIndirect,
in vec3 blockLightColor,
vec3 viewPos,
vec3 normal,
vec3 noise,
vec3 indirectLightColor,
vec3 minLightColor,
// vec3 indirectLightColor,
// vec3 minLightColor,
float lightmap,
bool isGrass,
@ -306,88 +374,66 @@ vec3 ApplySSRT(
int nrays = RAY_COUNT;
vec3 radiance = 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 skycontribution2 = vec3(0.0);
vec3 ambientColor = doIndirectLighting(indirectLightColor * 2.5, minLightColor, lightmap);
vec3 skycontribution2 = unchangedIndirect;
vec3 bouncedLight = vec3(0.0);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
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
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, noise.z, 50.); // ssr rt
#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
#ifdef SKY_CONTRIBUTION_IN_SSRT
#ifdef OVERWORLD_SHADER
if(isGrass) rayDir.y = clamp(rayDir.y + 0.5,-1,1);
skycontribution = mix(ambientColor, pow(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30, vec3(0.7)), lightmap);
skycontribution = doIndirectLighting(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30.0, minLightColor, lightmap) + blockLightColor;
#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
skycontribution = max(skycontribution, minLightColor * max(MIN_LIGHT_AMOUNT*0.01, nightVision * 0.1));
#else
#ifdef OVERWORLD_SHADER
if(isGrass) rayDir.y = clamp(rayDir.y + 0.25,-1,1);
skycontribution = ambientColor * (max(rayDir.y,pow(1.0-lightmap,2))*0.95+0.05);
#else
skycontribution = ambientColor;
skycontribution = unchangedIndirect * (max(rayDir.y,pow(1.0-lightmap,2))*0.95+0.05);
#endif
#if indirect_effect == 4
skycontribution2 = ambientColor;
#endif
#endif
if (rayHit.z < 1.){
radiance += skycontribution;
radiance2 += skycontribution2;
if (rayHit.z < 1.0){
#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 += texture2D(colortex5, previousPosition.xy).rgb * GI_Strength + skycontribution;
} else{
radiance += skycontribution;
bouncedLight = texture2D(colortex5, previousPosition.xy).rgb * GI_Strength;
radiance += bouncedLight;
radiance2 += bouncedLight;
}
#else
radiance += skycontribution;
#endif
occlusion += skycontribution * GI_Strength;
#if indirect_effect == 4
occlusion2 += skycontribution2 * GI_Strength;
#endif
} else {
radiance += skycontribution;
occlusion += skycontribution;
occlusion2 += skycontribution2;
}
}
if(isLOD) return max(radiance/nrays, 0.0);
occlusion *= AO_Strength;
#if indirect_effect == 4
return max(radiance/nrays - max(occlusion, occlusion2*0.5)/nrays, 0.0);
#ifdef SKY_CONTRIBUTION_IN_SSRT
return max((radiance - occlusion)/nrays,0.0);
#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
}

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 RESOURCEPACK_SKY 0 // [0 1 2]
#define RESOURCEPACK_SKY 0 // [0 1 2 3]
#ifdef IS_IRIS
#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
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));
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;
float currZ = linZ(spos.z);
float nextZ = linZ(sp);
if(hand) biasamount = 0.00035;
minZ = maxZ-biasamount / ld(spos.z);
// 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;
reflectLength += 1.0 / quality; // for shit
spos += stepv;
reflectLength += 1.0 / quality; // for shit
}
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
#if RESOURCEPACK_SKY == 2
#if RESOURCEPACK_SKY == 2 || RESOURCEPACK_SKY == 3
sun=true
moon=true
#else

View File

@ -1,7 +1,43 @@
#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() {
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
#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() {
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;
if(renderStage == 4) COLOR.rgb *= 5.0;
// if(renderStage == 5) COLOR.rgb *= 1.5;
#if RESOURCEPACK_SKY == 3
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
COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0);
gl_FragData[0] = vec4(COLOR.rgb/255.0, COLOR.a);
gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a);
#else
discard;
#endif

View File

@ -1,7 +1,43 @@
#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() {
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
#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() {
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
}