solve lighting

This commit is contained in:
JozsefA 2021-01-07 18:31:46 -08:00
parent 0b3615b50e
commit fa1e3ea543
2 changed files with 13 additions and 16 deletions

View File

@ -4,10 +4,10 @@ import net.minecraft.client.renderer.LightTexture;
public class LightUtil { public class LightUtil {
public static float getProperBlockLight(int packedLight) { public static float getProperBlockLight(int packedLight) {
return ((LightTexture.getBlockLightCoordinates(packedLight) + 1) / (float) 0xF); return LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF;
} }
public static float getProperSkyLight(int packedLight) { public static float getProperSkyLight(int packedLight) {
return ((LightTexture.getSkyLightCoordinates(packedLight) + 1) / (float) 0xF); return LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF;
} }
} }

View File

@ -9,18 +9,6 @@ out vec4 fragColor;
layout(binding=0) uniform sampler2D BlockAtlas; layout(binding=0) uniform sampler2D BlockAtlas;
layout(binding=1) uniform sampler2D LightMap; layout(binding=1) uniform sampler2D LightMap;
float blendDarken(float base, float blend) {
return min(blend,base);
}
vec3 blendDarken(vec3 base, vec3 blend) {
return vec3(blendDarken(base.r,blend.r),blendDarken(base.g,blend.g),blendDarken(base.b,blend.b));
}
vec3 blendDarken(vec3 base, vec3 blend, float opacity) {
return (blendDarken(base, blend) * opacity + base * (1.0 - opacity));
}
float diffuse() { float diffuse() {
float x = Normal.x; float x = Normal.x;
float y = Normal.y; float y = Normal.y;
@ -28,10 +16,19 @@ float diffuse() {
return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f);
} }
vec4 light() {
vec2 lm = Light * 0.9375 + 0.03125;
return texture2D(LightMap, lm);
}
void main() { void main() {
vec4 tex = texture2D(BlockAtlas, TexCoords); vec4 tex = texture2D(BlockAtlas, TexCoords);
vec4 light = texture2D(LightMap, Light); tex *= vec4(light().rgb, 1);
fragColor = vec4(blendDarken(tex.rgb, light.rgb, light.a) * diffuse(), tex.a); float df = diffuse();
tex *= vec4(df, df, df, 1);
fragColor = tex;
} }