diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java index d5f650313d..49f2275082 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java @@ -147,4 +147,9 @@ public TextureAtlasSprite getSprite() { public Direction getLightFace() { return this.direction; } + + @Override + public int getMaxLightQuad(int idx) { + return getLight(idx); + } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java index 08369fb0af..373eadc27b 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java @@ -127,4 +127,11 @@ default int getAccurateNormal(int i) { return normal == 0 ? getFaceNormal() : normal; } + + /** + * Gets the maximum light value for this vertex. + * @param idx The vertex index. + * @return Lightmap value. + */ + int getMaxLightQuad(int idx); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java index 2312f3ddc5..516255ecac 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java @@ -723,13 +723,13 @@ public boolean isSectionBuilt(int x, int y, int z) { } public void onChunkAdded(int x, int z) { - for (int y = this.level.getMinSectionY(); y < this.level.getMaxSectionY(); y++) { + for (int y = this.level.getMinSectionY(); y <= this.level.getMaxSectionY(); y++) { this.onSectionAdded(x, y, z); } } public void onChunkRemoved(int x, int z) { - for (int y = this.level.getMinSectionY(); y < this.level.getMaxSectionY(); y++) { + for (int y = this.level.getMinSectionY(); y <= this.level.getMaxSectionY(); y++) { this.onSectionRemoved(x, y, z); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/occlusion/OcclusionCuller.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/occlusion/OcclusionCuller.java index fde97543c1..9b81ed8cbd 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/occlusion/OcclusionCuller.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/occlusion/OcclusionCuller.java @@ -199,10 +199,10 @@ private void init(Visitor visitor, // below the level this.initOutsideWorldHeight(queue, viewport, searchDistance, frame, this.level.getMinSectionY(), GraphDirection.DOWN); - } else if (origin.getY() >= this.level.getMaxSectionY()) { + } else if (origin.getY() > this.level.getMaxSectionY()) { // above the level this.initOutsideWorldHeight(queue, viewport, searchDistance, frame, - this.level.getMaxSectionY() - 1, GraphDirection.UP); + this.level.getMaxSectionY(), GraphDirection.UP); } else { this.initWithinWorld(visitor, queue, viewport, useOcclusionCulling, frame); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java index fce995a97b..5e87722527 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java @@ -342,6 +342,11 @@ public Direction getLightFace() { return lightFace(); } + @Override + public int getMaxLightQuad(int idx) { + return lightmap(idx); + } + @Override public int getFlags() { return geometryFlags(); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java index 688a5febd4..63cc32fdc8 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java @@ -35,9 +35,9 @@ public class CloudRenderer { private static final ResourceLocation CLOUDS_TEXTURE_ID = ResourceLocation.withDefaultNamespace("textures/environment/clouds.png"); + public static final ShaderProgram CLOUDS = new ShaderProgram(ResourceLocation.fromNamespaceAndPath("sodium", "clouds"), DefaultVertexFormat.POSITION_COLOR, ShaderDefines.builder().build()); private CloudTextureData textureData; - private CompiledShaderProgram shaderProgram; private @Nullable CloudRenderer.CloudGeometry cachedGeometry; @@ -110,24 +110,18 @@ public void render(Camera camera, RenderSystem.disableCull(); } - if (fabulous) { - Minecraft.getInstance().levelRenderer.getCloudsTarget().bindWrite(false); - } - RenderSystem.setShaderColor(ARGB.from8BitChannel(ARGB.red(color)), ARGB.from8BitChannel(ARGB.green(color)), ARGB.from8BitChannel(ARGB.blue(color)), 1.0F); vertexBuffer.bind(); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, - GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + RenderType.clouds().setupRenderState(); RenderSystem.depthFunc(GL32C.GL_LESS); - vertexBuffer.drawWithShader(modelViewMatrix, projectionMatrix, this.shaderProgram); + RenderSystem.setShader(CLOUDS); + + vertexBuffer.drawWithShader(modelViewMatrix, projectionMatrix, RenderSystem.getShader()); RenderSystem.depthFunc(GL32C.GL_LEQUAL); - RenderSystem.disableBlend(); VertexBuffer.unbind(); @@ -135,9 +129,8 @@ public void render(Camera camera, RenderSystem.enableCull(); } - if (fabulous) { - Minecraft.getInstance().getMainRenderTarget().bindWrite(false); - } + RenderType.clouds().clearRenderState(); + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); @@ -408,16 +401,9 @@ public void reloadTextures(ResourceProvider resourceProvider) { this.destroy(); this.textureData = loadTextureData(); - - this.shaderProgram = Minecraft.getInstance().getShaderManager().getProgram(new ShaderProgram(ResourceLocation.fromNamespaceAndPath("sodium", "clouds"), DefaultVertexFormat.POSITION_COLOR, ShaderDefines.builder().build())); } public void destroy() { - if (this.shaderProgram != null) { - this.shaderProgram.close(); - this.shaderProgram = null; - } - if (this.cachedGeometry != null) { var vertexBuffer = this.cachedGeometry.vertexBuffer(); vertexBuffer.close(); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/model/BakedModelEncoder.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/model/BakedModelEncoder.java index 539e8ad3a6..b81c60b573 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/model/BakedModelEncoder.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/model/BakedModelEncoder.java @@ -35,7 +35,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m float y = quad.getY(i); float z = quad.getZ(i); - int newLight = mergeLighting(quad.getLight(i), light); + int newLight = mergeLighting(quad.getMaxLightQuad(i), light); // The packed transformed normal vector int normal = MatrixHelper.transformNormal(matNormal, matrices.trustedNormals, quad.getAccurateNormal(i)); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java index 75f565fa51..591ddcba07 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java @@ -48,7 +48,7 @@ public void renderClouds(ResourceHandle resourceHandle, int color, CloudStatus c ClientLevel level = Objects.requireNonNull(this.level); Camera camera = this.minecraft.gameRenderer.getMainCamera(); - this.cloudRenderer.render(camera, level, projectionMatrix, modelView, this.ticks, tickDelta, color); + this.cloudRenderer.render(camera, level, projectionMatrix, modelView, this.ticks, this.minecraft.getDeltaTracker().getGameTimeDeltaPartialTick(false), color); } @Inject(method = "onResourceManagerReload(Lnet/minecraft/server/packs/resources/ResourceManager;)V", at = @At("RETURN")) diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/core/model/quad/BakedQuadMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/core/model/quad/BakedQuadMixin.java index 0cdbb44a07..a0d1ad9717 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/core/model/quad/BakedQuadMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/core/model/quad/BakedQuadMixin.java @@ -4,6 +4,7 @@ import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFacing; import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFlags; import net.caffeinemc.mods.sodium.client.util.ModelQuadUtil; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Direction; @@ -16,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BakedQuad.class) -public class BakedQuadMixin implements BakedQuadView { +public abstract class BakedQuadMixin implements BakedQuadView { @Shadow @Final protected int[] vertices; @@ -37,6 +38,9 @@ public class BakedQuadMixin implements BakedQuadView { @Final private boolean shade; + @Shadow + public abstract int getLightEmission(); + @Unique private int flags; @@ -124,6 +128,11 @@ public Direction getLightFace() { return this.direction; } + @Override + public int getMaxLightQuad(int idx) { + return LightTexture.lightCoordsWithEmission(getLight(idx), getLightEmission()); + } + @Override @Unique(silent = true) // The target class has a function with the same name in a remapped environment public boolean hasShade() {