Skip to content

Commit

Permalink
Fixed glowing render layers not working with Iris
Browse files Browse the repository at this point in the history
Lucraft committed Sep 16, 2024
1 parent c148ed0 commit 19c404f
Showing 15 changed files with 95 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.threetag.palladium.Palladium;
import net.threetag.palladium.util.RenderUtil;

import java.util.function.Function;

@@ -17,9 +18,29 @@ public PalladiumRenderTypes(String string, VertexFormat vertexFormat, VertexForm
}

private static final Function<ResourceLocation, RenderType> GLOWING = Util.memoize((resourceLocation) -> {
RenderType.CompositeState compositeState = RenderType.CompositeState.builder().setShaderState(RENDERTYPE_ENERGY_SWIRL_SHADER).setTextureState(new TextureStateShard(resourceLocation, false, false)).setTransparencyState(TRANSLUCENT_TRANSPARENCY).setCullState(NO_CULL).setLightmapState(LIGHTMAP).setOverlayState(OVERLAY).setLayeringState(VIEW_OFFSET_Z_LAYERING).createCompositeState(true);
RenderType.CompositeState compositeState = RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_ENERGY_SWIRL_SHADER)
.setTextureState(new TextureStateShard(resourceLocation, false, false))
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setCullState(NO_CULL)
.setLightmapState(NO_LIGHTMAP)
.setOverlayState(OVERLAY)
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.createCompositeState(true);
return create(Palladium.MOD_ID + ":glowing", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, compositeState);
});
private static final Function<ResourceLocation, RenderType> GLOWING_SHADER_USE = Util.memoize((resourceLocation) -> {
RenderType.CompositeState compositeState = RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_EMISSIVE_SHADER)
.setTextureState(new TextureStateShard(resourceLocation, false, false))
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setCullState(NO_CULL)
.setLightmapState(NO_LIGHTMAP)
.setOverlayState(OVERLAY)
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.createCompositeState(true);
return create(Palladium.MOD_ID + ":glowing_shader_use", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, compositeState);
});

public static final RenderType LASER = create(Palladium.MOD_ID + ":laser", DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_LIGHTNING_SHADER)
@@ -57,7 +78,7 @@ public PalladiumRenderTypes(String string, VertexFormat vertexFormat, VertexForm
);

public static RenderType getGlowing(ResourceLocation texture) {
return GLOWING.apply(texture);
return RenderUtil.isIrisShaderActive() ? GLOWING_SHADER_USE.apply(texture) : GLOWING.apply(texture);
}

public static RenderType getArmorTranslucent(ResourceLocation texture) {
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public void render(DataContext context, PoseStack poseStack, MultiBufferSource b

VertexConsumer vertexConsumer = this.renderType.createVertexConsumer(bufferSource, this.texture.get(entity).getTexture(context), context.getItem().hasFoil());

entityModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, 1F);
entityModel.renderToBuffer(poseStack, vertexConsumer, this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, 1F);
}
}

@@ -79,10 +79,10 @@ public void renderArm(DataContext context, HumanoidArm arm, PlayerRenderer playe

if (arm == HumanoidArm.RIGHT) {
humanoidModel.rightArm.xRot = 0.0F;
humanoidModel.rightArm.render(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
humanoidModel.rightArm.render(poseStack, vertexConsumer, this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY);
} else {
humanoidModel.leftArm.xRot = 0.0F;
humanoidModel.leftArm.render(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
humanoidModel.leftArm.render(poseStack, vertexConsumer, this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY);
}
}
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;
@@ -49,7 +51,7 @@ public class PackRenderLayerManager extends SimpleJsonResourceReloadListener {
registerProvider((entity, layers) -> {
if (entity instanceof LivingEntity livingEntity) {
var manager = PackRenderLayerManager.getInstance();
for (AbilityInstance entry : AbilityUtil.getEnabledRenderLayerEntries(livingEntity)) {
for (AbilityInstance entry : AbilityUtil.getEnabledRenderLayerInstances(livingEntity)) {
IPackRenderLayer layer = ((RenderLayerProviderAbility) entry.getConfiguration().getAbility()).getRenderLayer(entry, livingEntity, manager);
if (layer != null) {
layers.accept(DataContext.forAbility(livingEntity, entry), layer);
@@ -96,7 +98,17 @@ public class PackRenderLayerManager extends SimpleJsonResourceReloadListener {
registerParser(new ResourceLocation(Palladium.MOD_ID, "thrusters"), ThrusterPackRenderLayer::parse);

registerRenderType(new ResourceLocation("minecraft", "solid"), (source, texture, glint) -> ItemRenderer.getArmorFoilBuffer(source, RenderType.entityTranslucent(texture), false, glint));
registerRenderType(new ResourceLocation("minecraft", "glow"), (source, texture, glint) -> ItemRenderer.getArmorFoilBuffer(source, PalladiumRenderTypes.getGlowing(texture), false, glint));
registerRenderType(new ResourceLocation("minecraft", "glow"), new RenderTypeFunction() {
@Override
public VertexConsumer createVertexConsumer(MultiBufferSource buffer, ResourceLocation texture, boolean withGlint) {
return ItemRenderer.getArmorFoilBuffer(buffer, PalladiumRenderTypes.getGlowing(texture), false, withGlint);
}

@Override
public int getPackedLight(int packedLight) {
return 15728640;
}
});
}

public PackRenderLayerManager() {
Original file line number Diff line number Diff line change
@@ -8,4 +8,8 @@ public interface RenderTypeFunction {

VertexConsumer createVertexConsumer(MultiBufferSource buffer, ResourceLocation texture, boolean withGlint);

default int getPackedLight(int packedLight) {
return packedLight;
}

}
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public void render(DataContext context, PoseStack poseStack, MultiBufferSource b
var entity = context.getEntity();
if (IPackRenderLayer.conditionsFulfilled(entity, this.conditions, this.thirdPersonConditions)) {
VertexConsumer vertexConsumer = this.renderType.createVertexConsumer(bufferSource, this.texture.get(entity).getTexture(context), context.getItem().hasFoil());
parentModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, 1F);
parentModel.renderToBuffer(poseStack, vertexConsumer, this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, 1F);
}
}

@@ -51,10 +51,10 @@ public void renderArm(DataContext context, HumanoidArm arm, PlayerRenderer playe

if (arm == HumanoidArm.RIGHT) {
entityModel.rightArm.xRot = 0.0F;
entityModel.rightArm.render(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
entityModel.rightArm.render(poseStack, vertexConsumer, this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY);
} else {
entityModel.leftArm.xRot = 0.0F;
entityModel.leftArm.render(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
entityModel.leftArm.render(poseStack, vertexConsumer, this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY);
}
}
}
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ public void render(DataContext context, PoseStack poseStack, MultiBufferSource b
this.model.setAllVisible(true);
this.cachedTexture = this.texture.get(living).getTexture(context);
this.cachedModel = this.modelLocation.get(living).getTexture(context);
this.model.renderToBuffer(poseStack, this.renderType.createVertexConsumer(bufferSource, this.cachedTexture, false), packedLight, OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, 1F);
this.model.renderToBuffer(poseStack, this.renderType.createVertexConsumer(bufferSource, this.cachedTexture, false), this.renderType.getPackedLight(packedLight), OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, 1F);
}
}

@@ -106,7 +106,7 @@ public void renderArm(DataContext context, HumanoidArm arm, PlayerRenderer playe
poseStack.translate(0, 24 / 16F, 0);
poseStack.scale(-1, -1, 1);

Color renderColor = this.model.getRenderColor(state, partialTick, packedLight);
Color renderColor = this.model.getRenderColor(state, partialTick, this.renderType.getPackedLight(packedLight));
float red = renderColor.getRedFloat();
float green = renderColor.getGreenFloat();
float blue = renderColor.getBlueFloat();
@@ -121,7 +121,7 @@ public void renderArm(DataContext context, HumanoidArm arm, PlayerRenderer playe
animationState.setData(DataTickets.EQUIPMENT_SLOT, EquipmentSlot.CHEST);
this.model.getGeoModel().addAdditionalStateData(state, instanceId, animationState::setData);
this.model.getGeoModel().handleAnimations(state, instanceId, animationState);
this.model.renderRecursively(poseStack, state, bone, null, bufferSource, buffer, false, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
this.model.renderRecursively(poseStack, state, bone, null, bufferSource, buffer, false, partialTick, this.renderType.getPackedLight(packedLight), packedOverlay, red, green, blue, alpha);

poseStack.popPose();
}
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packe
this.modelProvider.handleAnimations(this.currentState, instanceId, animationState);

defaultRender(poseStack, this.currentState, bufferSource, null, buffer,
0, partialTick, packedLight);
0, partialTick, this.currentState.layer.renderType.getPackedLight(packedLight));
poseStack.popPose();
}

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@@ -66,4 +67,9 @@ public static void drawGlowingBox(PoseStack poseStack, VertexConsumer consumer,
}
}

@ExpectPlatform
public static boolean isIrisShaderActive() {
throw new AssertionError();
}

}
3 changes: 3 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -96,6 +96,9 @@ dependencies {
// Sodium
modImplementation "maven.modrinth:sodium:${rootProject.sodium_version}"

// Iris
modCompileOnly "maven.modrinth:iris:${rootProject.iris_version}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.threetag.palladium.compat.iris.fabric;

import net.irisshaders.iris.api.v0.IrisApi;

public class IrisCompat {

public static boolean isShaderPackActive() {
return IrisApi.getInstance().isShaderPackInUse();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.threetag.palladium.util.fabric;

import net.threetag.palladium.compat.iris.fabric.IrisCompat;
import net.threetag.palladiumcore.util.Platform;

public class RenderUtilImpl {

public static boolean isIrisShaderActive() {
return Platform.isModLoaded("iris") && IrisCompat.isShaderPackActive();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.threetag.palladium.util.forge;

public class RenderUtilImpl {

public static boolean isIrisShaderActive() {
return false;
}

}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ rei_version=12.0.684
condensed_creative_version=3.1.3+1.20

# Fabric Dependencies
fabric_loader_version=0.15.3
fabric_loader_version=0.15.7
fabric_api_version=0.91.0+1.20.1
qsl_version=6.1.2+1.20.1
forge_config_api_port_version=8.0.0
@@ -34,6 +34,7 @@ pehkui_fabric_version=3.7.12
portinglib_version=2.3.2+1.20.1
cardinal_components_version=5.2.2
sodium_version=mc1.20.1-0.5.8
iris_version=1.7.2+1.20.1

# Forge Dependencies
neoforge_version=1.20.1-47.1.84
2 changes: 1 addition & 1 deletion run/mods/documentation/palladium/abilities.html
Original file line number Diff line number Diff line change
@@ -947,7 +947,7 @@ <h3>
<td>
Attribute</td>
<td>
Determines which attribute should be modified. Possible attributes: minecraft:generic.armor, minecraft:generic.armor_toughness, minecraft:generic.attack_damage, minecraft:generic.attack_knockback, minecraft:generic.attack_speed, minecraft:generic.flying_speed, minecraft:generic.follow_range, minecraft:generic.knockback_resistance, minecraft:generic.luck, minecraft:generic.max_health, minecraft:generic.movement_speed, minecraft:horse.jump_strength, minecraft:zombie.spawn_reinforcements, porting_lib:attack_range, porting_lib:entity_gravity, porting_lib:reach_distance, porting_lib:step_height_addition, porting_lib:swim_speed</td>
Determines which attribute should be modified. Possible attributes: minecraft:generic.armor, minecraft:generic.armor_toughness, minecraft:generic.attack_damage, minecraft:generic.attack_knockback, minecraft:generic.attack_speed, minecraft:generic.flying_speed, minecraft:generic.follow_range, minecraft:generic.knockback_resistance, minecraft:generic.luck, minecraft:generic.max_health, minecraft:generic.movement_speed, minecraft:horse.jump_strength, minecraft:zombie.spawn_reinforcements, porting_lib:entity_gravity, porting_lib:step_height_addition, porting_lib:swim_speed, reach-entity-attributes:attack_range, reach-entity-attributes:reach</td>
<td style="background-color: lightcoral">
false</td>
<td>
2 changes: 1 addition & 1 deletion run/mods/documentation/palladium/items.html
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ <h3>
<td>
AttributeModifier[]</td>
<td>
Attribute modifiers when having the item equipped. You first specify the slot ("all" for every slot, other options: [mainhand, offhand, feet, legs, chest, head]), then an array for different modifiers. Possible attributes: minecraft:generic.armor, minecraft:generic.armor_toughness, minecraft:generic.attack_damage, minecraft:generic.attack_knockback, minecraft:generic.attack_speed, minecraft:generic.flying_speed, minecraft:generic.follow_range, minecraft:generic.knockback_resistance, minecraft:generic.luck, minecraft:generic.max_health, minecraft:generic.movement_speed, minecraft:horse.jump_strength, minecraft:zombie.spawn_reinforcements, palladium:destroy_speed, palladium:fall_resistance, palladium:flight_flexibility, palladium:flight_speed, palladium:heroic_flight_type, palladium:jump_power, palladium:leaping, palladium:levitation_speed, palladium:punch_damage, porting_lib:attack_range, porting_lib:entity_gravity, porting_lib:reach_distance, porting_lib:step_height_addition, porting_lib:swim_speed</td>
Attribute modifiers when having the item equipped. You first specify the slot ("all" for every slot, other options: [mainhand, offhand, feet, legs, chest, head]), then an array for different modifiers. Possible attributes: minecraft:generic.armor, minecraft:generic.armor_toughness, minecraft:generic.attack_damage, minecraft:generic.attack_knockback, minecraft:generic.attack_speed, minecraft:generic.flying_speed, minecraft:generic.follow_range, minecraft:generic.knockback_resistance, minecraft:generic.luck, minecraft:generic.max_health, minecraft:generic.movement_speed, minecraft:horse.jump_strength, minecraft:zombie.spawn_reinforcements, palladium:destroy_speed, palladium:fall_resistance, palladium:flight_flexibility, palladium:flight_speed, palladium:heroic_flight_type, palladium:jump_power, palladium:leaping, palladium:levitation_speed, palladium:punch_damage, porting_lib:entity_gravity, porting_lib:step_height_addition, porting_lib:swim_speed, reach-entity-attributes:attack_range, reach-entity-attributes:reach</td>
<td style="background-color: lightcoral">
false</td>
<td>

0 comments on commit 19c404f

Please sign in to comment.