From abdeab95986008ef7de6d711360e4d7c051b0aa7 Mon Sep 17 00:00:00 2001 From: Goby56 <60710855+Goby56@users.noreply.github.com> Date: Sat, 10 Aug 2024 13:45:48 +0200 Subject: [PATCH] light kinda works still some visual artifacts need to remove light element of vertex builder i think --- .../com/goby56/wakes/config/WakesConfig.java | 1 + .../goby56/wakes/config/YACLIntegration.java | 4 +++ .../com/goby56/wakes/render/WakeTexture.java | 9 +++--- .../goby56/wakes/render/enums/WakeColor.java | 11 +++++-- .../com/goby56/wakes/simulation/Brick.java | 31 ++++++++++++++----- .../com/goby56/wakes/simulation/WakeNode.java | 10 ------ src/main/resources/wakes.accesswidener | 4 ++- 7 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/goby56/wakes/config/WakesConfig.java b/src/main/java/com/goby56/wakes/config/WakesConfig.java index 915f38d..7cfe7e3 100644 --- a/src/main/java/com/goby56/wakes/config/WakesConfig.java +++ b/src/main/java/com/goby56/wakes/config/WakesConfig.java @@ -44,6 +44,7 @@ public class WakesConfig { public boolean showDebugInfo = false; public RenderType renderType = RenderType.AUTO; public boolean useLODs = true; + public int lightInfluence = 127; // Appearance public Resolution wakeResolution = Resolution.SIXTEEN; diff --git a/src/main/java/com/goby56/wakes/config/YACLIntegration.java b/src/main/java/com/goby56/wakes/config/YACLIntegration.java index c6fbfe9..dfb142e 100644 --- a/src/main/java/com/goby56/wakes/config/YACLIntegration.java +++ b/src/main/java/com/goby56/wakes/config/YACLIntegration.java @@ -131,6 +131,10 @@ public static Screen createScreen(Screen parent) { .option(booleanOption("use_lods", false) .binding(false, () -> config.useLODs, val -> config.useLODs = val) .build()) + .option(optionOf(Integer.class, "light_influence", false) + .binding(127, () -> config.lightInfluence, val -> config.lightInfluence = val) + .controller(opt -> integerSlider(opt, 0, 255)) + .build()) .group(intervalGroup(0, WakeColor.TRANSPARENT, -50, -45)) .group(intervalGroup(1, WakeColor.DARK_GRAY, -45, -35)) .group(intervalGroup(2, WakeColor.GRAY, -35, -30)) diff --git a/src/main/java/com/goby56/wakes/render/WakeTexture.java b/src/main/java/com/goby56/wakes/render/WakeTexture.java index b0c3e49..7ff8d58 100644 --- a/src/main/java/com/goby56/wakes/render/WakeTexture.java +++ b/src/main/java/com/goby56/wakes/render/WakeTexture.java @@ -49,29 +49,30 @@ public void render(Matrix4f matrix, Camera camera, Brick brick) { buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL); Vector3f pos = brick.pos.add(camera.getPos().negate()).toVector3f(); + int light = LightmapTextureManager.MAX_LIGHT_COORDINATE; buffer.vertex(matrix, pos.x, pos.y, pos.z) .color(1f, 1f, 1f, 1f) .texture(0, 0) .overlay(OverlayTexture.DEFAULT_UV) - .light(14680064) + .light(light) .normal(0f, 1f, 0f).next(); buffer.vertex(matrix, pos.x, pos.y, pos.z + brick.dim) .color(1f, 1f, 1f, 1f) .texture(0, 1) .overlay(OverlayTexture.DEFAULT_UV) - .light(14680064) + .light(light) .normal(0f, 1f, 0f).next(); buffer.vertex(matrix, pos.x + brick.dim, pos.y, pos.z + brick.dim) .color(1f, 1f, 1f, 1f) .texture(1, 1) .overlay(OverlayTexture.DEFAULT_UV) - .light(14680064) + .light(light) .normal(0f, 1f, 0f).next(); buffer.vertex(matrix, pos.x + brick.dim, pos.y, pos.z) .color(1f, 1f, 1f, 1f) .texture(1, 0) .overlay(OverlayTexture.DEFAULT_UV) - .light(14680064) + .light(light) .normal(0f, 1f, 0f).next(); Tessellator.getInstance().draw(); diff --git a/src/main/java/com/goby56/wakes/render/enums/WakeColor.java b/src/main/java/com/goby56/wakes/render/enums/WakeColor.java index 74f957d..b60b14e 100644 --- a/src/main/java/com/goby56/wakes/render/enums/WakeColor.java +++ b/src/main/java/com/goby56/wakes/render/enums/WakeColor.java @@ -3,6 +3,7 @@ import com.goby56.wakes.WakesClient; import com.goby56.wakes.config.WakesConfig; import net.minecraft.util.StringIdentifiable; +import net.minecraft.util.math.ColorHelper; public enum WakeColor implements StringIdentifiable { TRANSPARENT(0, 0, 0, 0), @@ -26,7 +27,7 @@ public enum WakeColor implements StringIdentifiable { this.abgr = alpha << 24 | blue << 16 | green << 8 | red; } - private int blend(int waterColor, float opacity, boolean isWhite) { + private int blend(int waterColor, int lightColor, float opacity, boolean isWhite) { float srcA = (this.abgr >>> 24 & 0xFF) / 255f; int a = (int) (opacity * 255 * srcA); int b = 255, g = 255, r = 255; @@ -35,15 +36,19 @@ private int blend(int waterColor, float opacity, boolean isWhite) { g = (int) ((this.abgr >> 8 & 0xFF) * (1 - srcA) + (waterColor >> 8 & 0xFF) * (srcA)); r = (int) ((this.abgr & 0xFF) * (1 - srcA) + (waterColor >> 16 & 0xFF) * (srcA)); } + float lightA = WakesClient.CONFIG_INSTANCE.lightInfluence / 255f; + b = (int) ((b * (1-lightA) + (lightColor >> 16 & 0xFF) * lightA)); + g = (int) ((g * (1-lightA) + (lightColor >> 8 & 0xFF) * lightA)); + r = (int) ((r * (1-lightA) + (lightColor & 0xFF) * lightA)); return a << 24 | b << 16 | g << 8 | r; } - public static int getColor(float waveEqAvg, int waterColor, float opacity) { + public static int getColor(float waveEqAvg, int waterColor, int lightColor, float opacity) { double clampedRange = 100 / (1 + Math.exp(-0.1 * waveEqAvg)) - 50; for (WakesConfig.ColorInterval interval : WakesClient.CONFIG_INSTANCE.colorIntervals) { if (interval.lower <= clampedRange && clampedRange <= interval.upper) { - return interval.color.blend(waterColor, opacity, interval.color == WakeColor.WHITE); + return interval.color.blend(waterColor, lightColor, opacity, interval.color == WakeColor.WHITE); } } return WakeColor.TRANSPARENT.abgr; diff --git a/src/main/java/com/goby56/wakes/simulation/Brick.java b/src/main/java/com/goby56/wakes/simulation/Brick.java index 7e8040d..7cc374e 100644 --- a/src/main/java/com/goby56/wakes/simulation/Brick.java +++ b/src/main/java/com/goby56/wakes/simulation/Brick.java @@ -3,9 +3,17 @@ import com.goby56.wakes.WakesClient; import com.goby56.wakes.render.enums.WakeColor; import com.goby56.wakes.debug.WakesDebugInfo; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.RunArgs; +import net.minecraft.client.color.world.BiomeColors; import net.minecraft.client.render.Frustum; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.WorldRenderer; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; import org.lwjgl.system.MemoryUtil; import java.util.ArrayList; @@ -159,24 +167,33 @@ public void updateAdjacency(Brick brick) { } public void populatePixels() { + World world = MinecraftClient.getInstance().world; for (int z = 0; z < dim; z++) { for (int x = 0; x < dim; x++) { WakeNode node = this.get(x, z); - - int waterCol = node != null ? node.waterColor : 0; - float opacity = node != null ? (float) ((-Math.pow(node.t, 2) + 1) * WakesClient.CONFIG_INSTANCE.wakeOpacity) : 0; + int lightCol = LightmapTextureManager.MAX_LIGHT_COORDINATE; + int waterCol = 0; + float opacity = 0; + if (node != null) { + waterCol = BiomeColors.getWaterColor(world, node.blockPos()); + int lightCoordinate = WorldRenderer.getLightmapCoordinates(world, node.blockPos()); + lightCol = MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().image.getColor( + LightmapTextureManager.getBlockLightCoordinates(lightCoordinate), + LightmapTextureManager.getSkyLightCoordinates(lightCoordinate) + ); + opacity = (float) ((-Math.pow(node.t, 2) + 1) * WakesClient.CONFIG_INSTANCE.wakeOpacity); + } long nodeOffset = texRes * 4L * (((long) z * dim * texRes) + (long) x); for (int r = 0; r < texRes; r++) { for (int c = 0; c < texRes; c++) { - float avg = 0; + int color = 0; if (node != null) { - avg += (node.u[0][r + 1][c + 1] + node.u[1][r + 1][c + 1] + node.u[2][r + 1][c + 1]) / 3; + float avg = (node.u[0][r + 1][c + 1] + node.u[1][r + 1][c + 1] + node.u[2][r + 1][c + 1]) / 3; + color = WakeColor.getColor(avg, waterCol, lightCol, opacity); } - int color = waterCol != 0 ? WakeColor.getColor(avg, waterCol, opacity) : 0; long pixelOffset = 4L * (((long) r * dim * texRes) + c); - MemoryUtil.memPutInt(imgPtr + nodeOffset + pixelOffset, color); } } diff --git a/src/main/java/com/goby56/wakes/simulation/WakeNode.java b/src/main/java/com/goby56/wakes/simulation/WakeNode.java index 580f99b..308adb4 100644 --- a/src/main/java/com/goby56/wakes/simulation/WakeNode.java +++ b/src/main/java/com/goby56/wakes/simulation/WakeNode.java @@ -42,14 +42,6 @@ public class WakeNode implements Position, Age { public float t = 0; public int floodLevel; - public int waterColor = 0; - public int lightCoordinate = 0; - - // public WakeNode(int x, int z) { - // this.x = x; - // this.z = z; - // } - //TODO MORE GENERALIZED CONSTRUCTOR public WakeNode(Vec3d position, int initialStrength) { this.initValues(); @@ -145,8 +137,6 @@ public boolean tick() { this.u[0][z][x] *= beta; } } - waterColor = BiomeColors.getWaterColor(MinecraftClient.getInstance().world, this.blockPos()); - lightCoordinate = WorldRenderer.getLightmapCoordinates(MinecraftClient.getInstance().world, this.blockPos()); floodFill(); return true; } diff --git a/src/main/resources/wakes.accesswidener b/src/main/resources/wakes.accesswidener index 44296de..2b04ecd 100644 --- a/src/main/resources/wakes.accesswidener +++ b/src/main/resources/wakes.accesswidener @@ -4,4 +4,6 @@ accessible field net/minecraft/entity/vehicle/BoatEntity paddlePhases [F accessible field net/minecraft/entity/vehicle/BoatEntity NEXT_PADDLE_PHASE F -accessible field net/minecraft/client/model/ModelPart$Cuboid sides [Lnet/minecraft/client/model/ModelPart$Quad; \ No newline at end of file +accessible field net/minecraft/client/model/ModelPart$Cuboid sides [Lnet/minecraft/client/model/ModelPart$Quad; + +accessible field net/minecraft/client/render/LightmapTextureManager image Lnet/minecraft/client/texture/NativeImage; \ No newline at end of file