Skip to content

Commit

Permalink
fix shader frustum uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogo committed Apr 24, 2024
1 parent 747f671 commit ad13539
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 0 additions & 3 deletions src/main/java/rogo/renderingculling/api/CullingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
Expand All @@ -35,7 +34,6 @@
import rogo.renderingculling.api.impl.IEntitiesForRender;
import rogo.renderingculling.api.impl.IRenderChunkInfo;
import rogo.renderingculling.api.impl.IRenderSectionVisibility;
import rogo.renderingculling.gui.ConfigScreen;
import rogo.renderingculling.mixin.AccessorLevelRender;
import rogo.renderingculling.mixin.AccessorMinecraft;
import rogo.renderingculling.util.DepthContext;
Expand All @@ -52,7 +50,6 @@
import static org.lwjgl.opengl.GL30.*;

public class CullingHandler {
public static boolean SHADER_ENABLED = false;
public static final String MOD_ID = "brute_force_rendering_culling";
public static final Logger LOGGER = LogUtils.getLogger();
public static EntityCullingMap ENTITY_CULLING_MAP = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static void setUniform(ShaderInstance shader) {
shaderInstance.getCullingProjMat().set(CullingHandler.PROJECTION_MATRIX);
}
if(shaderInstance.getCullingFrustum() != null) {
Vector4f[] frustumData = ((AccessorFrustum.AccessorFrustumIntersection)((AccessorFrustum)CullingHandler.FRUSTUM).frustumIntersection()).planes();
Vector4f[] frustumData = ModLoader.getFrustumPlanes(((AccessorFrustum) CullingHandler.FRUSTUM).frustumIntersection());
List<Float> data = new ArrayList<>();
for (Vector4f frustumDatum : frustumData) {
data.add(frustumDatum.x());
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/rogo/renderingculling/api/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import org.joml.FrustumIntersection;
import org.joml.Vector4f;
import rogo.renderingculling.event.WorldUnloadEvent;
import rogo.renderingculling.gui.ConfigScreen;
import rogo.renderingculling.mixin.AccessorFrustum;
import rogo.renderingculling.util.OcclusionCullerThread;
import rogo.renderingculling.util.ShaderLoader;

import java.io.IOException;
import java.util.function.Supplier;

import static java.lang.Thread.MAX_PRIORITY;
import static rogo.renderingculling.api.CullingHandler.*;
import static rogo.renderingculling.api.CullingHandler.fromID;

public class ModLoader implements ModInitializer {

Expand All @@ -35,6 +35,8 @@ public class ModLoader implements ModInitializer {
((0xFF) << 8) |
((0xFF));

public static boolean SHADER_ENABLED = false;

@Override
public void onInitialize() {
callWhenOn(EnvType.CLIENT, () -> () -> {
Expand Down Expand Up @@ -118,4 +120,8 @@ public static int getBG() {
public static int getB() {
return B;
}

public static Vector4f[] getFrustumPlanes(FrustumIntersection frustum) {
return ((AccessorFrustum.AccessorFrustumIntersection) ((AccessorFrustum) frustum).frustumIntersection()).planes();
}
}
25 changes: 13 additions & 12 deletions src/main/java/rogo/renderingculling/mixin/MixinShaderInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import rogo.renderingculling.api.CullingHandler;
import rogo.renderingculling.api.CullingRenderEvent;
import rogo.renderingculling.api.ModLoader;
import rogo.renderingculling.api.impl.ICullingShader;


Expand Down Expand Up @@ -79,20 +80,9 @@ public void construct(CallbackInfo ci) {
this.CULLING_PROJ_MAT = this.getUniform("CullingProjMat");
}

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourceLocation;<init>(Ljava/lang/String;)V"))
public String onInit(String string) {
if (CullingHandler.SHADER_ENABLED) {
string = string.replace(SHADER_CORE_PATH, "");
string = string.replace(".json", "");
ResourceLocation rl = ResourceLocation.tryParse(string);
string = rl.getNamespace() + ":" + SHADER_CORE_PATH + rl.getPath() + ".json";
}
return string;
}

@ModifyArg(method = "getOrCreate", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourceLocation;<init>(Ljava/lang/String;)V"))
private static String onGetOrCreate(String string) {
if (CullingHandler.SHADER_ENABLED) {
if (ModLoader.SHADER_ENABLED) {
string = string.replace(SHADER_CORE_PATH, "");
Program.Type type = Program.Type.FRAGMENT;
if (string.contains(".fsh"))
Expand All @@ -107,6 +97,17 @@ else if (string.contains(".vsh")) {
return string;
}

@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourceLocation;<init>(Ljava/lang/String;)V"))
public String onInit(String string) {
if (ModLoader.SHADER_ENABLED) {
string = string.replace(SHADER_CORE_PATH, "");
string = string.replace(".json", "");
ResourceLocation rl = ResourceLocation.tryParse(string);
string = rl.getNamespace() + ":" + SHADER_CORE_PATH + rl.getPath() + ".json";
}
return string;
}

@Override
public Uniform getCullingFrustum() {
return CULLING_FRUSTUM;
Expand Down

0 comments on commit ad13539

Please sign in to comment.