mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-28 02:48:14 -05:00
Update #47 - Singleplayer lag fixes
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#line 2
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023 lax1dude. All Rights Reserved.
|
||||
* Copyright (c) 2023-2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
@ -41,72 +41,96 @@ uniform float u_sampleStep1f;
|
||||
|
||||
uniform vec4 u_pixelAlignment4f;
|
||||
|
||||
uniform int u_sampleDelta1i;
|
||||
|
||||
#define maxAge 55.0
|
||||
#define maxSamples 50.0
|
||||
|
||||
void main() {
|
||||
vec2 v_position2f2 = (floor(v_position2f * u_pixelAlignment4f.xy) + 0.25) * (2.0 / u_pixelAlignment4f.zw);
|
||||
reflectionOutput4f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
hitVectorOutput4f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float fragDepth = textureLod(u_gbufferDepthTexture, v_position2f2, 0.0).r;
|
||||
|
||||
if(fragDepth < 0.000001) {
|
||||
reflectionOutput4f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
hitVectorOutput4f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 reflectionInput4f = textureLod(u_reprojectionReflectionInput4f, v_position2f, 0.0);
|
||||
vec4 hitVectorInput4f = textureLod(u_reprojectionHitVectorInput4f, v_position2f, 0.0);
|
||||
hitVectorInput4f.a += 1.0;
|
||||
float f = reflectionInput4f.a < 1.0 ? 1.0 : reflectionInput4f.a;
|
||||
reflectionInput4f.a = hitVectorInput4f.a > maxAge ? f : reflectionInput4f.a;
|
||||
if(reflectionInput4f.a < 1.0) {
|
||||
reflectionOutput4f = reflectionInput4f;
|
||||
hitVectorOutput4f = hitVectorInput4f;
|
||||
return;
|
||||
vec4 reflectionBuffer4f = textureLod(u_reprojectionReflectionInput4f, v_position2f, 0.0);
|
||||
vec4 hitVectorBuffer4f = textureLod(u_reprojectionHitVectorInput4f, v_position2f, 0.0);
|
||||
vec4 surfaceNormal4f = textureLod(u_gbufferNormalTexture, v_position2f2, 0.0);
|
||||
surfaceNormal4f.xyz *= 2.0;
|
||||
surfaceNormal4f.xyz -= 1.0;
|
||||
|
||||
vec4 reflectionInput4f;
|
||||
vec4 hitVectorInput4f;
|
||||
float f;
|
||||
vec4 fragPos4f;
|
||||
vec4 reflectionNormal4f;
|
||||
float sampleStepMod;
|
||||
vec3 sampleOffset3f;
|
||||
vec3 reflectionSamplePos3f;
|
||||
float reflectDepthSample;
|
||||
vec2 sampleFragDepth;
|
||||
vec4 colorSample;
|
||||
|
||||
for(int itr = 0; itr < u_sampleDelta1i; ++itr) {
|
||||
reflectionInput4f = reflectionBuffer4f;
|
||||
hitVectorInput4f = hitVectorBuffer4f;
|
||||
reflectionBuffer4f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
hitVectorBuffer4f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
hitVectorInput4f.a += 1.0;
|
||||
f = reflectionInput4f.a < 1.0 ? 1.0 : reflectionInput4f.a;
|
||||
reflectionInput4f.a = hitVectorInput4f.a > maxAge ? f : reflectionInput4f.a;
|
||||
if(reflectionInput4f.a < 1.0) {
|
||||
reflectionBuffer4f = reflectionInput4f;
|
||||
hitVectorBuffer4f = hitVectorInput4f;
|
||||
continue;
|
||||
}
|
||||
|
||||
fragPos4f = u_inverseProjectionMatrix4f * (vec4(v_position2f2, fragDepth, 1.0) * 2.0 - 1.0);
|
||||
fragPos4f.xyz /= fragPos4f.w;
|
||||
fragPos4f.w = 1.0;
|
||||
reflectionNormal4f.xyz = reflect(normalize(fragPos4f.xyz), surfaceNormal4f.xyz);
|
||||
reflectionNormal4f.w = 1.0;
|
||||
sampleStepMod = (reflectionInput4f.a * 0.03 + 0.15 + length(fragPos4f.xyz) * 0.03) * u_sampleStep1f;
|
||||
sampleOffset3f = reflectionNormal4f.xyz * reflectionInput4f.a * sampleStepMod;
|
||||
fragPos4f.xyz += sampleOffset3f;
|
||||
reflectionNormal4f = u_lastProjectionMatrix4f * fragPos4f;
|
||||
reflectionNormal4f.xyz /= reflectionNormal4f.w;
|
||||
reflectionNormal4f.w = 1.0;
|
||||
reflectionSamplePos3f = reflectionNormal4f.xyz;
|
||||
reflectionSamplePos3f *= 0.5;
|
||||
reflectionSamplePos3f += 0.5;
|
||||
reflectionSamplePos3f.xy = (floor(reflectionSamplePos3f.xy * u_pixelAlignment4f.zw) + 0.5) * (0.5 / u_pixelAlignment4f.xy);
|
||||
|
||||
if(clamp(reflectionSamplePos3f.xy, vec2(0.001), vec2(0.999)) != reflectionSamplePos3f.xy) {
|
||||
continue;
|
||||
}
|
||||
|
||||
reflectDepthSample = textureLod(u_lastFrameDepthInput, reflectionSamplePos3f.xy, 0.0).r;
|
||||
sampleFragDepth = u_lastInverseProjMatrix4x2f * vec4(reflectionNormal4f.xy, reflectDepthSample * 2.0 - 1.0, 1.0);
|
||||
sampleFragDepth.x /= sampleFragDepth.y;
|
||||
|
||||
reflectDepthSample = sampleFragDepth.x - fragPos4f.z;
|
||||
if(reflectDepthSample < sampleStepMod * 3.0) {
|
||||
reflectionInput4f.a += 1.0;
|
||||
reflectionBuffer4f = reflectionInput4f.a >= maxSamples ? vec4(0.0, 0.0, 0.0, 0.0) : reflectionInput4f;
|
||||
hitVectorBuffer4f = vec4(0.0, 0.0, 0.0, hitVectorInput4f.a);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(abs(reflectDepthSample) > sampleStepMod * 6.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
colorSample = textureLod(u_lastFrameColorInput4f, reflectionSamplePos3f.xy, 0.0);
|
||||
reflectionBuffer4f = vec4(colorSample.rgb, 0.0);
|
||||
reflectionBuffer4f.g += 0.0005;
|
||||
hitVectorBuffer4f = vec4(colorSample.a > 0.0 ? sampleOffset3f : vec3(0.0), 0.0);
|
||||
hitVectorBuffer4f.g += colorSample.a > 0.0 ? 0.0004 : 0.0;
|
||||
}
|
||||
|
||||
vec4 fragPos4f = u_inverseProjectionMatrix4f * (vec4(v_position2f2, fragDepth, 1.0) * 2.0 - 1.0);
|
||||
fragPos4f.xyz /= fragPos4f.w;
|
||||
fragPos4f.w = 1.0;
|
||||
vec4 reflectionNormal4f = textureLod(u_gbufferNormalTexture, v_position2f2, 0.0);
|
||||
reflectionNormal4f.xyz *= 2.0;
|
||||
reflectionNormal4f.xyz -= 1.0;
|
||||
reflectionNormal4f.xyz = reflect(normalize(fragPos4f.xyz), reflectionNormal4f.xyz);
|
||||
reflectionNormal4f.w = 1.0;
|
||||
float sampleStepMod = (reflectionInput4f.a * 0.03 + 0.15 + length(fragPos4f.xyz) * 0.03) * u_sampleStep1f;
|
||||
vec3 sampleOffset3f = reflectionNormal4f.xyz * reflectionInput4f.a * sampleStepMod;
|
||||
fragPos4f.xyz += sampleOffset3f;
|
||||
reflectionNormal4f = u_lastProjectionMatrix4f * fragPos4f;
|
||||
reflectionNormal4f.xyz /= reflectionNormal4f.w;
|
||||
reflectionNormal4f.w = 1.0;
|
||||
vec3 reflectionSamplePos3f = reflectionNormal4f.xyz;
|
||||
reflectionSamplePos3f *= 0.5;
|
||||
reflectionSamplePos3f += 0.5;
|
||||
reflectionSamplePos3f.xy = (floor(reflectionSamplePos3f.xy * u_pixelAlignment4f.zw) + 0.5) * (0.5 / u_pixelAlignment4f.xy);
|
||||
|
||||
if(clamp(reflectionSamplePos3f.xy, vec2(0.001), vec2(0.999)) != reflectionSamplePos3f.xy) {
|
||||
return;
|
||||
}
|
||||
|
||||
float reflectDepthSample = textureLod(u_lastFrameDepthInput, reflectionSamplePos3f.xy, 0.0).r;
|
||||
vec2 sampleFragDepth = u_lastInverseProjMatrix4x2f * vec4(reflectionNormal4f.xy, reflectDepthSample * 2.0 - 1.0, 1.0);
|
||||
sampleFragDepth.x /= sampleFragDepth.y;
|
||||
|
||||
reflectDepthSample = sampleFragDepth.x - fragPos4f.z;
|
||||
if(reflectDepthSample < sampleStepMod * 3.0) {
|
||||
reflectionInput4f.a += 1.0;
|
||||
reflectionOutput4f = reflectionInput4f.a >= maxSamples ? vec4(0.0, 0.0, 0.0, 0.0) : reflectionInput4f;
|
||||
hitVectorOutput4f = vec4(0.0, 0.0, 0.0, hitVectorInput4f.a);
|
||||
return;
|
||||
}
|
||||
|
||||
if(abs(reflectDepthSample) > sampleStepMod * 6.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 colorSample = textureLod(u_lastFrameColorInput4f, reflectionSamplePos3f.xy, 0.0);
|
||||
reflectionOutput4f = vec4(colorSample.rgb, 0.0);
|
||||
reflectionOutput4f.g += 0.0005;
|
||||
hitVectorOutput4f = vec4(colorSample.a > 0.0 ? sampleOffset3f : vec3(0.0), 0.0);
|
||||
hitVectorOutput4f.g += colorSample.a > 0.0 ? 0.0004 : 0.0;
|
||||
reflectionOutput4f = reflectionBuffer4f;
|
||||
hitVectorOutput4f = hitVectorBuffer4f;
|
||||
}
|
||||
|
Reference in New Issue
Block a user