Update #50 - Bug fixes and shader improvements

This commit is contained in:
lax1dude
2025-02-22 16:52:35 -08:00
parent b0a2739fe1
commit 7e772e2502
133 changed files with 3064 additions and 2299 deletions

View File

@ -37,6 +37,9 @@ uniform mat4 u_inverseProjectionMatrix4f;
#ifdef COMPILE_SUN_SHADOW
uniform sampler2D u_sunShadowTexture;
#endif
#ifdef COMPILE_SUBSURFACE_SCATTERING
uniform sampler2D u_subsurfaceScatteringTexture;
#endif
uniform vec3 u_sunDirection3f;
uniform vec3 u_sunColor3f;
@ -49,30 +52,64 @@ void main() {
vec3 normalVector3f;
vec2 lightmapCoords2f;
vec3 materialData3f;
vec4 sampleVar4f;
#ifdef COMPILE_SUBSURFACE_SCATTERING
float depth = textureLod(u_gbufferDepthTexture, v_position2f, 0.0).r;
if(depth == 0.0) {
discard;
}
sampleVar4f = textureLod(u_gbufferColorTexture, v_position2f, 0.0);
diffuseColor3f.rgb = sampleVar4f.rgb;
diffuseColor3f *= diffuseColor3f;
lightmapCoords2f.x = sampleVar4f.a;
#endif
#ifdef COMPILE_SUBSURFACE_SCATTERING
float subsurfValue = textureLod(u_subsurfaceScatteringTexture, v_position2f, 0.0).r;
subsurfValue *= subsurfValue;
output4f = vec4(subsurfValue * u_sunColor3f * diffuseColor3f * 0.125, 0.0);
#endif
#ifdef COMPILE_SUN_SHADOW
#ifdef COMPILE_COLORED_SHADOW
vec4 shadow = textureLod(u_sunShadowTexture, v_position2f, 0.0);
if(shadow.a < 0.05) {
#ifndef COMPILE_SUBSURFACE_SCATTERING
discard;
#else
return;
#endif
}
#else
vec3 shadow = vec3(textureLod(u_sunShadowTexture, v_position2f, 0.0).r);
#ifndef COMPILE_SUBSURFACE_SCATTERING
if(shadow.r < 0.05) {
#ifndef COMPILE_SUBSURFACE_SCATTERING
discard;
#else
return;
#endif
}
#endif
#endif
#endif
#ifndef COMPILE_SUBSURFACE_SCATTERING
float depth = textureLod(u_gbufferDepthTexture, v_position2f, 0.0).r;
#endif
#ifndef COMPILE_SUN_SHADOW
if(depth == 0.0) {
#ifndef COMPILE_SUBSURFACE_SCATTERING
discard;
#else
return;
#endif
}
#endif
vec4 sampleVar4f = textureLod(u_gbufferNormalTexture, v_position2f, 0.0);
sampleVar4f = textureLod(u_gbufferNormalTexture, v_position2f, 0.0);
#ifndef COMPILE_SUN_SHADOW
vec3 shadow = vec3(sampleVar4f.a, 0.0, 0.0);
@ -85,9 +122,12 @@ void main() {
normalVector3f.xyz = sampleVar4f.rgb * 2.0 - 1.0;
lightmapCoords2f.y = sampleVar4f.a;
#ifndef COMPILE_SUBSURFACE_SCATTERING
sampleVar4f = textureLod(u_gbufferColorTexture, v_position2f, 0.0);
diffuseColor3f.rgb = sampleVar4f.rgb;
diffuseColor3f *= diffuseColor3f;
lightmapCoords2f.x = sampleVar4f.a;
#endif
materialData3f = textureLod(u_gbufferMaterialTexture, v_position2f, 0.0).rgb;
vec3 worldSpaceNormal = normalize(mat3(u_inverseViewMatrix4f) * normalVector3f);
@ -97,6 +137,15 @@ void main() {
worldSpacePosition = u_inverseProjectionMatrix4f * worldSpacePosition;
worldSpacePosition = u_inverseViewMatrix4f * vec4(worldSpacePosition.xyz / worldSpacePosition.w, 0.0);
diffuseColor3f *= diffuseColor3f;
output4f = vec4(eaglercraftLighting(diffuseColor3f, u_sunColor3f * shadow.rgb, normalize(-worldSpacePosition.xyz), u_sunDirection3f, worldSpaceNormal, materialData3f), 0.0);
}
#ifdef COMPILE_SUBSURFACE_SCATTERING
output4f.rgb +=
#else
output4f = vec4(
#endif
eaglercraftLighting(diffuseColor3f, u_sunColor3f * shadow.rgb, normalize(-worldSpacePosition.xyz), u_sunDirection3f, worldSpaceNormal, materialData3f)
#ifdef COMPILE_SUBSURFACE_SCATTERING
* (1.0 - subsurfValue * 0.0625);
#else
, 0.0);
#endif
}