Skip to content

Commit

Permalink
what the hell is up
Browse files Browse the repository at this point in the history
fixed some rendering issues but something is seriously broken
  • Loading branch information
Goby56 committed Jul 29, 2024
1 parent ec54e9b commit 25294dd
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 159 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/goby56/wakes/mixin/LilyPadFallMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class LilyPadFallMixin {
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance, CallbackInfo ci) {
if (!world.getBlockState(pos.up()).isOf(Blocks.LILY_PAD)) return;
if (WakesClient.CONFIG_INSTANCE.disableMod) return;

EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(entity);
ProducesWake wakeProducer = (ProducesWake) entity;
if (rule.simulateWakes) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ private void onSwimmingStart(CallbackInfo ci) {
if (WakesClient.CONFIG_INSTANCE.disableMod) {
return;
}

Entity thisEntity = ((Entity) (Object) this);

EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(thisEntity);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/goby56/wakes/render/WakeQuad.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.render.enums.WakeColor;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeNode;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.util.math.Box;
import net.minecraft.world.World;
import org.lwjgl.system.MemoryUtil;

import java.util.List;
import java.util.Objects;

public class WakeQuad {
public final int x;
public final float y;
public final int z;
public final int w;
public final int h;
public final WakeNode[][] nodes;

public WakeQuad(int x, int z, int w, int h, WakeNode[][] affectedNodes) {
public WakeQuad(int x, float y, int z, int w, int h, WakeNode[][] affectedNodes) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
this.h = h;
this.nodes = affectedNodes;
}

public Box toBox() {
return new Box(x, y, z, x + w, y + 1, z + h);
}

public void populatePixels(WakeTexture texture, World world) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
Expand Down
27 changes: 11 additions & 16 deletions src/main/java/com/goby56/wakes/render/WakeRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.goby56.wakes.config.enums.Resolution;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.simulation.WakeNode;
import com.goby56.wakes.utils.WakesDebugInfo;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
Expand All @@ -13,7 +14,6 @@
import java.util.*;

public class WakeRenderer implements WorldRenderEvents.AfterTranslucent {
public static int quadsRendered = 0;
public static Map<Resolution, WakeTexture> wakeTextures = null;

private void initTextures() {
Expand All @@ -37,27 +37,22 @@ public void afterTranslucent(WorldRenderContext context) {

double tRendering = System.nanoTime();

ArrayList<Brick> bricks = wakeHandler.getVisible(context.frustum());
ArrayList<WakeQuad> quads = wakeHandler.getVisible(context.frustum());
Matrix4f matrix = context.matrixStack().peek().getPositionMatrix();
RenderSystem.enableBlend();
RenderSystem.disableCull();
context.lightmapTextureManager().enable();

// int n = 0;
// for (var brick : bricks) {
// Resolution resolution = WakesClient.CONFIG_INSTANCE.wakeResolution;
// if (resolution.res != WakeNode.res) continue;

// for (var quad : brick.quads) {
// wakeTextures.get(resolution).render(matrix, context.camera(), brick, quad, wakeHandler.world);
// n++;
// }

// }
// RenderSystem.enableCull();

// quadsRendered = n;
Resolution resolution = WakesClient.CONFIG_INSTANCE.wakeResolution;
if (resolution.res != WakeNode.res) return;
int n = 0;
for (var quad : quads) {
wakeTextures.get(resolution).render(matrix, context.camera(), quad, wakeHandler.world);
n++;
}
RenderSystem.enableCull();

WakesDebugInfo.quadsRendered = n;
WakesDebugInfo.wakeRenderingTime.add(System.nanoTime() - tRendering);
}
}
36 changes: 17 additions & 19 deletions src/main/java/com/goby56/wakes/render/WakeTexture.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.goby56.wakes.render;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.render.enums.RenderType;
import com.goby56.wakes.render.enums.WakeColor;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeNode;
import com.mojang.blaze3d.platform.GlConst;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.render.*;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL14;
import org.lwjgl.system.MemoryUtil;
Expand All @@ -40,20 +37,16 @@ public WakeTexture(int res) {
GlStateManager._texImage2D(GlConst.GL_TEXTURE_2D, 0, GlConst.GL_RGBA, 32 * res, 32 * res, 0, GlConst.GL_RGBA, GlConst.GL_UNSIGNED_BYTE, null);
}

public void render(Matrix4f matrix, Camera camera, Brick brick, WakeQuad quad, World world) {
int x = quad.x, z = quad.z, w = quad.w, h = quad.h;
public void render(Matrix4f matrix, Camera camera, WakeQuad quad, World world) {
WakeNode[][] nodes = quad.nodes;

Vec3d screenSpace = brick.getPos().add(camera.getPos().negate());
float xPos = (float) screenSpace.x + x;
float zPos = (float) screenSpace.z + z;
Vector3f pos = new Vec3d(quad.x, quad.y, quad.z).add(camera.getPos().negate()).toVector3f();
GlStateManager._bindTexture(glTexId);
GlStateManager._pixelStore(GlConst.GL_UNPACK_ROW_LENGTH, 0);
GlStateManager._pixelStore(GlConst.GL_UNPACK_SKIP_PIXELS, 0);
GlStateManager._pixelStore(GlConst.GL_UNPACK_SKIP_ROWS, 0);
GlStateManager._pixelStore(GlConst.GL_UNPACK_ALIGNMENT, 4);
GlStateManager._texSubImage2D(GlConst.GL_TEXTURE_2D, 0, x * res, z * res, w * res, h * res, GlConst.GL_RGBA, GlConst.GL_UNSIGNED_BYTE, imgPtr);

GlStateManager._texSubImage2D(GlConst.GL_TEXTURE_2D, 0, 0, 0, 32 * res, 32 * res, GlConst.GL_RGBA, GlConst.GL_UNSIGNED_BYTE, imgPtr);
RenderSystem.setShaderTexture(0, glTexId);
RenderSystem.setShader(RenderType.getProgram());
RenderSystem.enableDepthTest(); // Is it THIS simple? https://github.com/Goby56/wakes/issues/46
Expand All @@ -63,27 +56,32 @@ public void render(Matrix4f matrix, Camera camera, Brick brick, WakeQuad quad, W

int X = nodes.length - 1;
int Z = nodes[0].length - 1;
buffer.vertex(matrix, xPos, nodes[0][0].height, zPos)
float u = quad.x / 32f;
float v = quad.z / 32f;
float uOffset = quad.w / 32f;
float vOffset = quad.h / 32f;

buffer.vertex(matrix, pos.x, pos.y, pos.z)
.color(1f, 1f, 1f, 1f)
.texture(0, 0)
.texture(u, v)
.overlay(OverlayTexture.DEFAULT_UV)
.light(light(nodes[0][0], world))
.normal(0f, 1f, 0f).next();
buffer.vertex(matrix, xPos, nodes[0][Z].height, zPos + 1)
buffer.vertex(matrix, pos.x, pos.y, pos.z + quad.h)
.color(1f, 1f, 1f, 1f)
.texture(0, 1)
.texture(u, v + vOffset)
.overlay(OverlayTexture.DEFAULT_UV)
.light(light(nodes[0][Z], world))
.normal(0f, 1f, 0f).next();
buffer.vertex(matrix, xPos + 1, nodes[X][Z].height, zPos + 1)
buffer.vertex(matrix, pos.x + quad.w, pos.y, pos.z + quad.h)
.color(1f, 1f, 1f, 1f)
.texture(1, 1)
.texture(u + uOffset, v + vOffset)
.overlay(OverlayTexture.DEFAULT_UV)
.light(light(nodes[X][Z], world))
.normal(0f, 1f, 0f).next();
buffer.vertex(matrix, xPos + 1, nodes[X][0].height, zPos)
buffer.vertex(matrix, pos.x + quad.w, pos.y, pos.z)
.color(1f, 1f, 1f, 1f)
.texture(1, 0)
.texture(u + uOffset, v)
.overlay(OverlayTexture.DEFAULT_UV)
.light(light(nodes[X][0], world))
.normal(0f, 1f, 0f).next();
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/com/goby56/wakes/render/debug/WakeDebugRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ public class WakeDebugRenderer implements WorldRenderEvents.DebugRender {
@Override
public void beforeDebugRender(WorldRenderContext context) {
WakeHandler wakeHandler = WakeHandler.getInstance();
int n = 0;
if (WakesClient.CONFIG_INSTANCE.drawDebugBoxes) {
for (var brick : wakeHandler.getVisible(context.frustum())) {
for (var quad : brick.quads) {
Vec3d brickPos = brick.getPos();
float y = quad.nodes[0][0].height;
System.out.printf();
Box box = new Box(brickPos.x + quad.x, y, brickPos.z + quad.z, brickPos.x + quad.x + quad.w, y + 0.1f, brickPos.z + quad.z + quad.h);
var col = Color.getHSBColor(new Random(quad.hashCode()).nextFloat(), 1f, 1f).getRGBColorComponents(null);
DebugRenderer.drawBox(context.matrixStack(), context.consumers(),
box.offset(context.camera().getPos().negate()),
col[0], col[1], col[2], 0.5f);
n++;
}
for (var quad : wakeHandler.getVisible(context.frustum())) {
Box box = new Box(quad.x, quad.y - 0.1f, quad.z, quad.x + quad.w, quad.y - 0.2f, quad.z + quad.h);
var col = Color.getHSBColor(new Random(quad.hashCode()).nextFloat(), 1f, 1f).getRGBColorComponents(null);
DebugRenderer.drawBox(context.matrixStack(), context.consumers(),
box.offset(context.camera().getPos().negate()),
col[0], col[1], col[2], 0.5f);
}
}
WakesDebugInfo.quadsRendered = n;
}
}
Loading

0 comments on commit 25294dd

Please sign in to comment.