Skip to content

Commit

Permalink
neo support
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 5, 2024
1 parent ccfc645 commit 19ad7ea
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 38 deletions.
7 changes: 4 additions & 3 deletions common/src/main/java/net/irisshaders/iris/NeoLambdas.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.irisshaders.iris;

public class NeoLambdas {
public static final String NEO_RENDER_SKY = "lambda$addSkyPass$12";
public static final String NEO_RENDER_SKY = "lambda$addSkyPass$10";
public static final String NEO_RENDER_MAIN_PASS = "lambda$addMainPass$2";
public static final String NEO_RENDER_WEATHER = "lambda$addWeatherPass$7";
public static final String NEO_RENDER_CLOUDS = "lambda$addCloudsPass$6";
public static final String NEO_RENDER_WEATHER = "lambda$addWeatherPass$5.";
public static final String NEO_RENDER_CLOUDS = "lambda$addCloudsPass$4";
public static final String NEO_PARTICLE = "lambda$static$26";
}
17 changes: 11 additions & 6 deletions common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ public static String getStringi(int glEnum, int index) {
public static void copyImageSubData(int sourceTexture, int target, int mip, int srcX, int srcY, int srcZ, int destTexture, int dstTarget, int dstMip, int dstX, int dstY, int dstZ, int width, int height, int depth) {
GL46C.glCopyImageSubData(sourceTexture, target, mip, srcX, srcY, srcZ, destTexture, dstTarget, dstMip, dstX, dstY, dstZ, width, height, depth);
}


private static boolean cullingState;

public static void backupAndDisableCullingState(boolean b) {
Expand Down Expand Up @@ -531,19 +531,23 @@ public void generateMipmaps(int texture, int target) {

@Override
public void texParameteri(int texture, int target, int pname, int param) {
ARBDirectStateAccess.glTextureParameteri(texture, pname, param);
bindTextureForSetup(target, texture);
GL32C.glTexParameteri(target, pname, param);
}

@Override
public void texParameterf(int texture, int target, int pname, float param) {
ARBDirectStateAccess.glTextureParameterf(texture, pname, param);
bindTextureForSetup(target, texture);
GL32C.glTexParameterf(target, pname, param);
}

@Override
public void texParameteriv(int texture, int target, int pname, int[] params) {
ARBDirectStateAccess.glTextureParameteriv(texture, pname, params);
bindTextureForSetup(target, texture);
GL32C.glTexParameteriv(target, pname, params);
}


@Override
public void readBuffer(int framebuffer, int buffer) {
ARBDirectStateAccess.glNamedFramebufferReadBuffer(framebuffer, buffer);
Expand All @@ -556,7 +560,8 @@ public void drawBuffers(int framebuffer, int[] buffers) {

@Override
public int getTexParameteri(int texture, int target, int pname) {
return ARBDirectStateAccess.glGetTextureParameteri(texture, pname);
bindTextureForSetup(target, texture);
return GL32C.glGetTexParameteri(target, pname);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public List<String> getMixins() {

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

//if (targetClassName.contains("LevelRenderer")) {
// targetClass.methods.forEach(m -> System.out.println(m.name + m.desc));
//}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.irisshaders.iris.mixin;

import net.irisshaders.iris.NeoLambdas;
import net.irisshaders.iris.pipeline.programs.ShaderAccess;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(RenderType.class)
public class MixinRenderType {
@Unique
private static final RenderStateShard.ShaderStateShard TRANSLUCENT_PARTICLE_SHADER = new RenderStateShard.ShaderStateShard(ShaderAccess.TRANSLUCENT_PARTICLE_SHADER);

@Redirect(method = {"method_65225", NeoLambdas.NEO_PARTICLE }, require = 1, at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderType;PARTICLE_SHADER:Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;"))
private static RenderStateShard.ShaderStateShard getTranslucentParticleShader() {
return TRANSLUCENT_PARTICLE_SHADER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class MixinShaderManager_Overrides {
coreShaderMap.put(CoreShaders.POSITION_TEX_COLOR, p -> ShaderOverrides.getSkyTexColorShader((IrisRenderingPipeline) p));
coreShaderMap.put(CoreShaders.POSITION_COLOR, p -> ShaderOverrides.getSkyColorShader((IrisRenderingPipeline) p));
coreShaderMap.put(CoreShaders.PARTICLE, p -> ShaderOverrides.isPhase((IrisRenderingPipeline) p, WorldRenderingPhase.RAIN_SNOW) ? ShaderKey.WEATHER : ShaderKey.PARTICLES);
coreShaderMap.put(ShaderAccess.TRANSLUCENT_PARTICLE_SHADER, p -> ShaderOverrides.isPhase((IrisRenderingPipeline) p, WorldRenderingPhase.RAIN_SNOW) ? ShaderKey.WEATHER : ShaderKey.PARTICLES_TRANS);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_CUTOUT, p -> getCutout(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_SOLID, p -> getSolid(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_ARMOR_CUTOUT_NO_CULL, p -> getCutout(p));
Expand Down Expand Up @@ -100,6 +101,7 @@ public abstract class MixinShaderManager_Overrides {
coreShaderMapShadow.put(CoreShaders.POSITION_TEX_COLOR, p -> ShaderKey.SHADOW_TEX_COLOR);
coreShaderMapShadow.put(CoreShaders.POSITION_COLOR, p -> ShaderKey.SHADOW_BASIC_COLOR);
coreShaderMapShadow.put(CoreShaders.PARTICLE, p -> ShaderKey.SHADOW_PARTICLES);
coreShaderMapShadow.put(ShaderAccess.TRANSLUCENT_PARTICLE_SHADER, p -> ShaderKey.SHADOW_PARTICLES);
coreShaderMapShadow.put(CoreShaders.RENDERTYPE_ENTITY_CUTOUT, p -> ShaderKey.SHADOW_ENTITIES_CUTOUT);
coreShaderMapShadow.put(CoreShaders.RENDERTYPE_ENTITY_SOLID, p -> ShaderKey.SHADOW_ENTITIES_CUTOUT);
coreShaderMapShadow.put(CoreShaders.RENDERTYPE_ARMOR_CUTOUT_NO_CULL, p -> ShaderKey.SHADOW_ENTITIES_CUTOUT);
Expand Down Expand Up @@ -219,6 +221,8 @@ private void redirectIrisProgram(ShaderProgram shaderProgram, CallbackInfoReturn
cir.setReturnValue(getProgram(CoreShaders.RENDERTYPE_ENTITY_CUTOUT));
} else if (shaderProgram == ShaderAccess.IE_COMPAT) {
// TODO when IE updates
} else if (shaderProgram == ShaderAccess.TRANSLUCENT_PARTICLE_SHADER) {
cir.setReturnValue(getProgram(CoreShaders.PARTICLE));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.irisshaders.iris.mixin;

import com.mojang.blaze3d.platform.TextureUtil;
import net.irisshaders.iris.gl.IrisRenderSystem;
import org.lwjgl.opengl.GL46C;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(TextureUtil.class)
public class MixinTextureUtil {
@Inject(method = "generateTextureId", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;assertOnRenderThreadOrInit()V", shift = At.Shift.AFTER), cancellable = true)
private static void generateTextureId(CallbackInfoReturnable<Integer> cir) {
cir.setReturnValue(IrisRenderSystem.createTexture(GL46C.GL_TEXTURE_2D));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@

@Mixin(ItemStackRenderState.LayerRenderState.class)
public class ItemStackStateLayerMixin {
@Shadow(aliases = "field_55345")
@Unique
private ItemStackRenderState parentState;

@Inject(method = "<init>", at = @At("TAIL"))
private void iris$catchParent(ItemStackRenderState itemStackRenderState, CallbackInfo ci) {
this.parentState = itemStackRenderState;
}

@Inject(method = "render", at = @At("HEAD"))
private void onRender(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j, CallbackInfo ci, @Share("lastBState") LocalIntRef ref) {
ref.set(CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MixinTextureManager {
@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = {
"method_65880",
"lambda$reload$4"
"lambda$reload$2"
}, at = @At("TAIL"), require = 1)
private void iris$onTailReloadLambda(List list, Void void_, CallbackInfo ci) {
TextureFormatLoader.reload(this.resourceManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.irisshaders.iris.pbr.texture;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.irisshaders.iris.mixin.texture.SpriteContentsAnimatedTextureAccessor;
import net.irisshaders.iris.mixin.texture.SpriteContentsFrameInfoAccessor;
import net.irisshaders.iris.mixin.texture.SpriteContentsTickerAccessor;
Expand Down Expand Up @@ -43,6 +45,7 @@ public PBRAtlasTexture(TextureAtlas atlasTexture, PBRType type) {
this.atlasTexture = atlasTexture;
this.type = type;
id = ResourceLocation.fromNamespaceAndPath(atlasTexture.location().getNamespace(), atlasTexture.location().getPath().replace(".png", "") + type.getSuffix() + ".png");
setFilter(false, true);
}

public static void syncAnimation(SpriteContents.Ticker source, SpriteContents.Ticker target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ShaderAccess {
.add("Normal", VertexFormatElement.NORMAL)
.padding(1)
.build();
public static final ShaderProgram TRANSLUCENT_PARTICLE_SHADER = new ShaderProgram(ResourceLocation.fromNamespaceAndPath("iris", "translucent_particle"), DefaultVertexFormat.PARTICLE, ShaderDefines.EMPTY);

public static CompiledShaderProgram getParticleTranslucentShader() {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/iris.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ mutable field net/minecraft/client/renderer/LevelRenderer renderBuffers Lnet/min
accessible class net/minecraft/client/gui/components/AbstractSelectionList$Entry
accessible field com/mojang/blaze3d/platform/GlStateManager$BooleanState enabled Z
accessible field com/mojang/blaze3d/vertex/PoseStack$Pose trustedNormals Z
accessible class net/minecraft/client/renderer/RenderStateShard$ShaderStateShard
2 changes: 2 additions & 0 deletions common/src/main/resources/mixins.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
"MixinRenderSection",
"MixinRenderSystem",
"MixinRenderTarget",
"MixinRenderType",
"MixinScreenEffectRenderer",
"MixinCompiledShaderProgram",
"MixinSystemReport",
"MixinTextureUtil",
"MixinSkyRenderer",
"MixinTheEndPortalRenderer",
"MixinTitleScreen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ public class MixinParticleEngine implements PhasedParticleEngine {
@Unique
private static ParticleRenderingPhase phase = ParticleRenderingPhase.EVERYTHING;

@Inject(method = "renderParticleType", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;", shift = At.Shift.AFTER))
private static void iris$changeParticleShader(Camera camera, float f, MultiBufferSource.BufferSource bufferSource, ParticleRenderType particleRenderType, Queue<Particle> queue, CallbackInfo ci) {
if (IrisApi.getInstance().isShaderPackInUse() && phase == ParticleRenderingPhase.TRANSLUCENT) {
RenderSystem.setShader(ShaderAccess.getParticleTranslucentShader());
}
}

@Redirect(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/particle/ParticleEngine;RENDER_ORDER:Ljava/util/List;"))
private List<ParticleRenderType> iris$selectParticlesToRender() {
if (phase == ParticleRenderingPhase.TRANSLUCENT) {
Expand Down
10 changes: 9 additions & 1 deletion neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ sourceSets {

repositories {
mavenLocal()
maven("https://maven.pkg.github.com/ims212/ForgifiedFabricAPI") {
credentials {
username = "IMS212"
// Read only token
password = "ghp_" + "DEuGv0Z56vnSOYKLCXdsS9svK4nb9K39C1Hn"
}
}

maven("https://maven.su5ed.dev/releases")
maven("https://maven.neoforged.net/releases/")
maven("https://prmaven.neoforged.net/NeoForge/pr1590") {
Expand Down Expand Up @@ -122,7 +130,7 @@ dependencies {
compileOnly(project.project(":common").sourceSets.getByName("headers").output)
compileOnly(project.project(":common").sourceSets.getByName("api").output)
runtimeOnly("org.sinytra.forgified-fabric-api:fabric-api-base:0.4.42+d1308ded19")
runtimeOnly("net.fabricmc:fabric_renderer_api_v1:3.3.0+1.21.2-pre1")
runtimeOnly("org.sinytra.forgified-fabric-api:fabric-renderer-api-v1:5.0.0+babc52e504")
runtimeOnly("org.sinytra.forgified-fabric-api:fabric-rendering-data-attachment-v1:0.3.48+73761d2e19")
runtimeOnly("org.sinytra.forgified-fabric-api:fabric-block-view-api-v2:1.0.10+9afaaf8c19")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@
*/
@Mixin(LevelRenderer.class)
public abstract class MixinLevelRenderer {
@Shadow
@Final
private Minecraft minecraft;

@Shadow
private RenderBuffers renderBuffers;

@Shadow
public abstract Frustum getFrustum();

@WrapOperation(method = "lambda$addMainPass$2", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V"))
private void redirectSolidParticles(ParticleEngine instance, Camera camera, float v, MultiBufferSource.BufferSource bufferSource, Frustum frustum, Predicate<ParticleRenderType> predicate, Operation<Void> original) {
ParticleRenderingSettings settings = getRenderingSettings();
Expand All @@ -65,8 +55,8 @@ private void redirectSolidParticles(ParticleEngine instance, Camera camera, floa
original.call(instance, camera, v, bufferSource, frustum, newPredicate);
}

@WrapOperation(method = "lambda$addParticlesPass$3", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V"))
private void redirectTransParticles(ParticleEngine instance, LightTexture lightTexture, Camera camera, float v, Frustum frustum, Predicate<ParticleRenderType> predicate, Operation<Void> original) {
@WrapOperation(method = "lambda$addParticlesPass$5", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V"))
private void redirectTransParticles(ParticleEngine instance, Camera camera, float v, MultiBufferSource.BufferSource bufferSource, Frustum frustum, Predicate<ParticleRenderType> predicate, Operation<Void> original) {
ParticleRenderingSettings settings = getRenderingSettings();

Predicate<ParticleRenderType> newPredicate = predicate;
Expand All @@ -77,7 +67,7 @@ private void redirectTransParticles(ParticleEngine instance, LightTexture lightT
newPredicate = (t) -> true;
}

original.call(instance, lightTexture, camera, v, frustum, newPredicate);
original.call(instance, camera, v, bufferSource, frustum, newPredicate);
}

private ParticleRenderingSettings getRenderingSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.particle.ParticleEngine;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.culling.Frustum;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -57,10 +58,10 @@
*/
@Mixin(ParticleEngine.class)
public class MixinParticleEngine {
@Inject(method = "render(Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;Ljava/util/function/Predicate;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleRenderType;begin(Lcom/mojang/blaze3d/vertex/Tesselator;Lnet/minecraft/client/renderer/texture/TextureManager;)Lcom/mojang/blaze3d/vertex/BufferBuilder;"))
private void iris$changeParticleShader(LightTexture p_107339_, Camera p_107340_, float p_107341_, Frustum frustum, Predicate<ParticleRenderType> renderTypePredicate, CallbackInfo ci) {
if (!renderTypePredicate.test(ParticleRenderType.PARTICLE_SHEET_OPAQUE)) {
RenderSystem.setShader(ShaderAccess.getParticleTranslucentShader());
}
//@Inject(method = "renderParticleType(Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/particle/ParticleRenderType;Ljava/util/Queue;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleRenderType;begin(Lcom/mojang/blaze3d/vertex/Tesselator;Lnet/minecraft/client/renderer/texture/TextureManager;)Lcom/mojang/blaze3d/vertex/BufferBuilder;"))
private static void iris$changeParticleShader(Camera p_382847_, float p_383032_, MultiBufferSource.BufferSource p_383105_, ParticleRenderType p_383179_, Queue<Particle> p_383046_, CallbackInfo ci) {
//if (!renderTypePredicate.test(ParticleRenderType.PARTICLE_SHEET_OPAQUE)) {
// RenderSystem.setShader(ShaderAccess.getParticleTranslucentShader());
//}
}
}
1 change: 1 addition & 0 deletions neoforge/src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public net.minecraft.client.renderer.texture.Stitcher$Holder
public net.minecraft.world.level.biome.Biome$ClimateSettings
public net.minecraft.client.Options$FieldAccess
public net.minecraft.client.renderer.texture.SpriteContents$AnimatedTexture
public net.minecraft.client.renderer.RenderStateShard$ShaderStateShard
public net.minecraft.client.renderer.texture.SpriteContents$FrameInfo
public net.minecraft.client.renderer.texture.SpriteContents$Ticker
public net.minecraft.client.OptionInstance$ValueSet
Expand Down

0 comments on commit 19ad7ea

Please sign in to comment.