From 160e8232827bcdc1da6f608ec7b3a90905c4c5d6 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 13 Feb 2022 14:04:52 -0800 Subject: [PATCH] JEI and glowing fixes - Fix sequenced assembly scene in newer JEI versions; Fix #2779 - Fix inconsistent JEI fan scenes; Fix #2748 - Fix glowing RenderTypes not respecting lightmap values --- gradle.properties | 2 +- .../jei/category/FanBlastingCategory.java | 12 +- .../jei/category/FanHauntingCategory.java | 79 +--------- .../jei/category/FanSmokingCategory.java | 16 ++- .../jei/category/FanWashingCategory.java | 81 +---------- .../category/ProcessingViaFanCategory.java | 135 +++++++++++++----- .../category/SequencedAssemblyCategory.java | 4 + .../WorldshaperItemRenderer.java | 4 +- .../create/foundation/render/RenderTypes.java | 39 +++-- .../create/shaders/core/glowing_shader.fsh | 25 ++++ .../create/shaders/core/glowing_shader.json | 30 ++++ .../create/shaders/core/glowing_shader.vsh | 35 +++++ 12 files changed, 257 insertions(+), 205 deletions(-) create mode 100644 src/main/resources/assets/create/shaders/core/glowing_shader.fsh create mode 100644 src/main/resources/assets/create/shaders/core/glowing_shader.json create mode 100644 src/main/resources/assets/create/shaders/core/glowing_shader.vsh diff --git a/gradle.properties b/gradle.properties index 9ff056bdd..e1393d7d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ parchment_version = 2022.01.23 registrate_version = MC1.18-1.0.21 flywheel_version = 1.18-0.6.1.60 jei_minecraft_version = 1.18.1 -jei_version = 9.2.1.69 +jei_version = 9.3.2.92 # curseforge information projectId = 328085 diff --git a/src/main/java/com/simibubi/create/compat/jei/category/FanBlastingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/FanBlastingCategory.java index 205d7c13c..df77d0746 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/FanBlastingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/FanBlastingCategory.java @@ -3,6 +3,7 @@ package com.simibubi.create.compat.jei.category; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics; +import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.element.GuiGameElement; import net.minecraft.world.item.Items; @@ -21,16 +22,17 @@ public class FanBlastingCategory extends ProcessingViaFanCategory { +public class FanHauntingCategory extends ProcessingViaFanCategory.MultiOutput { public FanHauntingCategory() { - super(185, doubleItemIcon(AllItems.PROPELLER.get(), Items.SOUL_CAMPFIRE)); + super(doubleItemIcon(AllItems.PROPELLER.get(), Items.SOUL_CAMPFIRE)); } @Override @@ -30,76 +22,17 @@ public class FanHauntingCategory extends ProcessingViaFanCategory results = recipe.getRollableResults(); - int xOffsetGlobal = 8 * (3 - Math.min(3, results.size())); - - itemStacks.init(0, true, xOffsetGlobal + 12, 47); - itemStacks.set(0, Arrays.asList(recipe.getIngredients() - .get(0) - .getItems())); - - boolean single = results.size() == 1; - boolean excessive = results.size() > 9; - for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { - int xOffset = (outputIndex % 3) * 19; - int yOffset = (outputIndex / 3) * -19; - - itemStacks.init(outputIndex + 1, false, xOffsetGlobal + (single ? 126 : 126 + xOffset), - 47 + yOffset + (excessive ? 8 : 0)); - itemStacks.set(outputIndex + 1, results.get(outputIndex) - .getStack()); - } - - addStochasticTooltip(itemStacks, results); - } - - @Override - protected void renderWidgets(PoseStack matrixStack, HauntingRecipe recipe, double mouseX, double mouseY) { - int size = recipe.getRollableResultsAsItemStacks() - .size(); - int xOffsetGlobal = 8 * (3 - Math.min(3, size)); - - AllGuiTextures.JEI_SLOT.render(matrixStack, xOffsetGlobal + 12, 47); - AllGuiTextures.JEI_SHADOW.render(matrixStack, 47 + 4, 29); - AllGuiTextures.JEI_SHADOW.render(matrixStack, 66 + 4, 39); - AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, xOffsetGlobal + 42, 51); - - if (size == 1) { - getRenderedSlot(recipe, 0).render(matrixStack, xOffsetGlobal + 126, 47); - return; - } - - for (int i = 0; i < size; i++) { - int xOffset = (i % 3) * 19; - int yOffset = (i / 3) * -19 + (size > 9 ? 8 : 0); - getRenderedSlot(recipe, i).render(matrixStack, xOffsetGlobal + 126 + xOffset, 47 + yOffset); - } - } - - @Override - protected void translateFan(PoseStack ms) { - ms.translate(56 + 4, 33, 0); - } - - @Override - public void renderAttachedBlock(PoseStack matrixStack) { - matrixStack.pushPose(); - + protected void renderAttachedBlock(PoseStack matrixStack) { GuiGameElement.of(Blocks.SOUL_FIRE.defaultBlockState()) - .scale(24) + .scale(SCALE) .atLocal(0, 0, 2) .lighting(AnimatedKinetics.DEFAULT_LIGHTING) .render(matrixStack); - - matrixStack.popPose(); } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java index 7160a8b1c..d2bce200e 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/FanSmokingCategory.java @@ -2,6 +2,8 @@ package com.simibubi.create.compat.jei.category; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; +import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics; +import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.element.GuiGameElement; import net.minecraft.world.item.Items; @@ -20,11 +22,17 @@ public class FanSmokingCategory extends ProcessingViaFanCategory } @Override - public void renderAttachedBlock(PoseStack matrixStack) { + protected AllGuiTextures getBlockShadow() { + return AllGuiTextures.JEI_LIGHT; + } + + @Override + protected void renderAttachedBlock(PoseStack matrixStack) { GuiGameElement.of(Blocks.FIRE.defaultBlockState()) - .scale(24) - .atLocal(0, 0, 2) - .render(matrixStack); + .scale(SCALE) + .atLocal(0, 0, 2) + .lighting(AnimatedKinetics.DEFAULT_LIGHTING) + .render(matrixStack); } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java index 9aeae2c83..74f2c01f7 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/FanWashingCategory.java @@ -1,27 +1,18 @@ package com.simibubi.create.compat.jei.category; -import java.util.Arrays; -import java.util.List; - import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics; import com.simibubi.create.content.contraptions.components.fan.SplashingRecipe; -import com.simibubi.create.content.contraptions.processing.ProcessingOutput; -import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.element.GuiGameElement; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; -import mezz.jei.api.ingredients.IIngredients; import net.minecraft.world.item.Items; import net.minecraft.world.level.material.Fluids; -public class FanWashingCategory extends ProcessingViaFanCategory { +public class FanWashingCategory extends ProcessingViaFanCategory.MultiOutput { public FanWashingCategory() { - super(185, doubleItemIcon(AllItems.PROPELLER.get(), Items.WATER_BUCKET)); + super(doubleItemIcon(AllItems.PROPELLER.get(), Items.WATER_BUCKET)); } @Override @@ -30,76 +21,12 @@ public class FanWashingCategory extends ProcessingViaFanCategory results = recipe.getRollableResults(); - int xOffsetGlobal = 8 * (3 - Math.min(3, results.size())); - - itemStacks.init(0, true, xOffsetGlobal + 12, 47); - itemStacks.set(0, Arrays.asList(recipe.getIngredients() - .get(0) - .getItems())); - - boolean single = results.size() == 1; - boolean excessive = results.size() > 9; - for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { - int xOffset = (outputIndex % 3) * 19; - int yOffset = (outputIndex / 3) * -19; - - itemStacks.init(outputIndex + 1, false, xOffsetGlobal + (single ? 126 : 126 + xOffset), - 47 + yOffset + (excessive ? 8 : 0)); - itemStacks.set(outputIndex + 1, results.get(outputIndex) - .getStack()); - } - - addStochasticTooltip(itemStacks, results); - } - - @Override - protected void renderWidgets(PoseStack matrixStack, SplashingRecipe recipe, double mouseX, double mouseY) { - int size = recipe.getRollableResultsAsItemStacks() - .size(); - int xOffsetGlobal = 8 * (3 - Math.min(3, size)); - - AllGuiTextures.JEI_SLOT.render(matrixStack, xOffsetGlobal + 12, 47); - AllGuiTextures.JEI_SHADOW.render(matrixStack, 47 + 4, 29); - AllGuiTextures.JEI_SHADOW.render(matrixStack, 66 + 4, 39); - AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, xOffsetGlobal + 42, 51); - - if (size == 1) { - getRenderedSlot(recipe, 0).render(matrixStack, xOffsetGlobal + 126, 47); - return; - } - - for (int i = 0; i < size; i++) { - int xOffset = (i % 3) * 19; - int yOffset = (i / 3) * -19 + (size > 9 ? 8 : 0); - getRenderedSlot(recipe, i).render(matrixStack, xOffsetGlobal + 126 + xOffset, 47 + yOffset); - } - } - - @Override - protected void translateFan(PoseStack ms) { - ms.translate(56 + 4, 33, 0); - } - - @Override - public void renderAttachedBlock(PoseStack matrixStack) { - matrixStack.pushPose(); - + protected void renderAttachedBlock(PoseStack matrixStack) { GuiGameElement.of(Fluids.WATER) - .scale(24) + .scale(SCALE) .atLocal(0, 0, 2) .lighting(AnimatedKinetics.DEFAULT_LIGHTING) .render(matrixStack); - - matrixStack.popPose(); } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java index 59e2d42cb..26bf97596 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java @@ -1,15 +1,15 @@ package com.simibubi.create.compat.jei.category; -import java.util.Arrays; +import java.util.List; import java.util.function.Supplier; -import javax.annotation.Nullable; - import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector3f; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics; +import com.simibubi.create.content.contraptions.processing.ProcessingOutput; +import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.utility.Lang; @@ -23,18 +23,14 @@ import net.minecraft.world.item.crafting.Recipe; public abstract class ProcessingViaFanCategory> extends CreateRecipeCategory { + protected static final int SCALE = 24; + public ProcessingViaFanCategory(IDrawable icon) { - this(177, icon); + this(178, icon); } - protected ProcessingViaFanCategory(int width, IDrawable icon) { - super(icon, emptyBackground(width, 71)); - } - - @Override - public void setIngredients(T recipe, IIngredients ingredients) { - ingredients.setInputIngredients(recipe.getIngredients()); - ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem()); + public ProcessingViaFanCategory(int width, IDrawable icon) { + super(icon, emptyBackground(width, 72)); } public static Supplier getFan(String name) { @@ -43,56 +39,123 @@ public abstract class ProcessingViaFanCategory> extends Crea } @Override - public void setRecipe(IRecipeLayout recipeLayout, T recipe, @Nullable IIngredients ingredients) { - IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); - itemStacks.init(0, true, 20, 47); - itemStacks.set(0, Arrays.asList(recipe.getIngredients() - .get(0) - .getItems())); - - itemStacks.init(1, false, 139, 47); - itemStacks.set(1, recipe.getResultItem()); - } - - protected void renderWidgets(PoseStack matrixStack, T recipe, double mouseX, double mouseY) { - AllGuiTextures.JEI_SLOT.render(matrixStack, 20, 47); - AllGuiTextures.JEI_SLOT.render(matrixStack, 139, 47); - AllGuiTextures.JEI_SHADOW.render(matrixStack, 47, 29); - AllGuiTextures.JEI_LIGHT.render(matrixStack, 66, 39); - AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, 53, 51); + public void setIngredients(T recipe, IIngredients ingredients) { + ingredients.setInputIngredients(recipe.getIngredients()); + ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem()); } @Override - public void draw(@Nullable T recipe, @Nullable PoseStack matrixStack, double mouseX, double mouseY) { - if (matrixStack == null) - return; + public void setRecipe(IRecipeLayout recipeLayout, T recipe, IIngredients ingredients) { + IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); + + itemStacks.init(0, true, 20, 47); + itemStacks.set(0, ingredients.getInputs(VanillaTypes.ITEM).get(0)); + + itemStacks.init(1, false, 140, 47); + itemStacks.set(1, ingredients.getOutputs(VanillaTypes.ITEM).get(0)); + } + + @Override + public void draw(T recipe, PoseStack matrixStack, double mouseX, double mouseY) { renderWidgets(matrixStack, recipe, mouseX, mouseY); matrixStack.pushPose(); translateFan(matrixStack); matrixStack.mulPose(Vector3f.XP.rotationDegrees(-12.5f)); matrixStack.mulPose(Vector3f.YP.rotationDegrees(22.5f)); - int scale = 24; AnimatedKinetics.defaultBlockElement(AllBlockPartials.ENCASED_FAN_INNER) .rotateBlock(180, 0, AnimatedKinetics.getCurrentAngle() * 16) - .scale(scale) + .scale(SCALE) .render(matrixStack); AnimatedKinetics.defaultBlockElement(AllBlocks.ENCASED_FAN.getDefaultState()) .rotateBlock(0, 180, 0) .atLocal(0, 0, 0) - .scale(scale) + .scale(SCALE) .render(matrixStack); renderAttachedBlock(matrixStack); matrixStack.popPose(); } + protected void renderWidgets(PoseStack matrixStack, T recipe, double mouseX, double mouseY) { + AllGuiTextures.JEI_SHADOW.render(matrixStack, 46, 29); + getBlockShadow().render(matrixStack, 65, 39); + AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, 54, 51); + AllGuiTextures.JEI_SLOT.render(matrixStack, 20, 47); + AllGuiTextures.JEI_SLOT.render(matrixStack, 140, 47); + } + + protected AllGuiTextures getBlockShadow() { + return AllGuiTextures.JEI_SHADOW; + } + protected void translateFan(PoseStack matrixStack) { matrixStack.translate(56, 33, 0); } - public abstract void renderAttachedBlock(PoseStack matrixStack); + protected abstract void renderAttachedBlock(PoseStack matrixStack); + + public static abstract class MultiOutput> extends ProcessingViaFanCategory { + + public MultiOutput(IDrawable icon) { + super(icon); + } + + public MultiOutput(int width, IDrawable icon) { + super(width, icon); + } + + @Override + public void setIngredients(T recipe, IIngredients ingredients) { + ingredients.setInputIngredients(recipe.getIngredients()); + ingredients.setOutputs(VanillaTypes.ITEM, recipe.getRollableResultsAsItemStacks()); + } + + @Override + public void setRecipe(IRecipeLayout recipeLayout, T recipe, IIngredients ingredients) { + IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); + + List results = recipe.getRollableResults(); + int xOffsetAmount = 1 - Math.min(3, results.size()); + + itemStacks.init(0, true, 5 * xOffsetAmount + 20, 47); + itemStacks.set(0, ingredients.getInputs(VanillaTypes.ITEM).get(0)); + + int xOffsetOutput = 9 * xOffsetAmount; + boolean excessive = results.size() > 9; + for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) { + int xOffset = (outputIndex % 3) * 19 + xOffsetOutput; + int yOffset = (outputIndex / 3) * -19 + (excessive ? 8 : 0); + + itemStacks.init(outputIndex + 1, false, 140 + xOffset, 47 + yOffset); + itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); + } + + addStochasticTooltip(itemStacks, results); + } + + @Override + protected void renderWidgets(PoseStack matrixStack, T recipe, double mouseX, double mouseY) { + int size = recipe.getRollableResultsAsItemStacks() + .size(); + int xOffsetAmount = 1 - Math.min(3, size); + + AllGuiTextures.JEI_SHADOW.render(matrixStack, 46, 29); + getBlockShadow().render(matrixStack, 65, 39); + AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, 7 * xOffsetAmount + 54, 51); + AllGuiTextures.JEI_SLOT.render(matrixStack, 5 * xOffsetAmount + 20, 47); + + int xOffsetOutput = 9 * xOffsetAmount; + boolean excessive = size > 9; + for (int i = 0; i < size; i++) { + int xOffset = (i % 3) * 19 + xOffsetOutput; + int yOffset = (i / 3) * -19 + (excessive ? 8 : 0); + getRenderedSlot(recipe, i).render(matrixStack, 140 + xOffset, 47 + yOffset); + } + } + + } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java index b83355017..6ab4db15d 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java @@ -127,6 +127,8 @@ public class SequencedAssemblyCategory extends CreateRecipeCategory Shaders.glowingShader); + private static final RenderType OUTLINE_SOLID = - RenderType.create(createLayerName("outline_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, + RenderType.create(createLayerName("outline_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, false, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(AllSpecialTextures.BLANK.getLocation(), false, false)) + .setCullState(CULL) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) - .createCompositeState(true)); + .createCompositeState(false)); public static RenderType getOutlineSolid() { return OUTLINE_SOLID; @@ -28,7 +39,7 @@ public class RenderTypes extends RenderStateShard { public static RenderType getOutlineTranslucent(ResourceLocation texture, boolean cull) { return RenderType.create(createLayerName("outline_translucent" + (cull ? "_cull" : "")), - DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder() .setShaderState(cull ? RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER : RENDERTYPE_ENTITY_TRANSLUCENT_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) @@ -36,14 +47,15 @@ public class RenderTypes extends RenderStateShard { .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) .setWriteMaskState(COLOR_WRITE) - .createCompositeState(true)); + .createCompositeState(false)); } public static RenderType getGlowingSolid(ResourceLocation texture) { return RenderType.create(createLayerName("glowing_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, false, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_BEACON_BEAM_SHADER) + .setShaderState(GLOWING_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) + .setCullState(CULL) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) .createCompositeState(true)); @@ -58,10 +70,9 @@ public class RenderTypes extends RenderStateShard { public static RenderType getGlowingTranslucent(ResourceLocation texture) { return RenderType.create(createLayerName("glowing_translucent"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_BEACON_BEAM_SHADER) + .setShaderState(GLOWING_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) - .setCullState(NO_CULL) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) .createCompositeState(true)); @@ -78,6 +89,7 @@ public class RenderTypes extends RenderStateShard { false, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER) .setTextureState(BLOCK_SHEET) + .setCullState(CULL) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) .createCompositeState(true)); @@ -100,7 +112,7 @@ public class RenderTypes extends RenderStateShard { } private static final RenderType FLUID = RenderType.create(createLayerName("fluid"), - DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) .setTextureState(BLOCK_SHEET_MIPPED) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) @@ -121,4 +133,15 @@ public class RenderTypes extends RenderStateShard { super(null, null, null); } + @EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) + private static class Shaders { + private static ShaderInstance glowingShader; + + @SubscribeEvent + public static void onRegisterShaders(RegisterShadersEvent event) throws IOException { + ResourceManager resourceManager = event.getResourceManager(); + event.registerShader(new ShaderInstance(resourceManager, Create.asResource("glowing_shader"), DefaultVertexFormat.NEW_ENTITY), shader -> glowingShader = shader); + } + } + } diff --git a/src/main/resources/assets/create/shaders/core/glowing_shader.fsh b/src/main/resources/assets/create/shaders/core/glowing_shader.fsh new file mode 100644 index 000000000..e8d3a0929 --- /dev/null +++ b/src/main/resources/assets/create/shaders/core/glowing_shader.fsh @@ -0,0 +1,25 @@ +#version 150 + +#moj_import + +uniform sampler2D Sampler0; + +uniform vec4 ColorModulator; +uniform float FogStart; +uniform float FogEnd; +uniform vec4 FogColor; +uniform float GameTime; + +in float vertexDistance; +in vec4 vertexColor; +in vec4 lightMapColor; +in vec2 texCoord0; +in vec4 normal; + +out vec4 fragColor; + +void main() { + vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator; + color *= lightMapColor; + fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); +} diff --git a/src/main/resources/assets/create/shaders/core/glowing_shader.json b/src/main/resources/assets/create/shaders/core/glowing_shader.json new file mode 100644 index 000000000..6180e3b04 --- /dev/null +++ b/src/main/resources/assets/create/shaders/core/glowing_shader.json @@ -0,0 +1,30 @@ +{ + "blend": { + "func": "add", + "srcrgb": "srcalpha", + "dstrgb": "1-srcalpha" + }, + "vertex": "create:glowing_shader", + "fragment": "create:glowing_shader", + "attributes": [ + "Position", + "Color", + "UV0", + "UV1", + "UV2", + "Normal" + ], + "samplers": [ + { "name": "Sampler0" }, + { "name": "Sampler2" } + ], + "uniforms": [ + { "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, + { "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, + { "name": "IViewRotMat", "type": "matrix3x3", "count": 9, "values": [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ] }, + { "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }, + { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, + { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] }, + { "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] } + ] +} diff --git a/src/main/resources/assets/create/shaders/core/glowing_shader.vsh b/src/main/resources/assets/create/shaders/core/glowing_shader.vsh new file mode 100644 index 000000000..9bff895bf --- /dev/null +++ b/src/main/resources/assets/create/shaders/core/glowing_shader.vsh @@ -0,0 +1,35 @@ +#version 150 + +#moj_import + +in vec3 Position; +in vec4 Color; +in vec2 UV0; +in vec2 UV1; +in ivec2 UV2; +in vec3 Normal; + +uniform sampler2D Sampler1; +uniform sampler2D Sampler2; + +uniform mat4 ModelViewMat; +uniform mat4 ProjMat; +uniform mat3 IViewRotMat; + +out float vertexDistance; +out vec4 vertexColor; +out vec4 lightMapColor; +out vec2 texCoord0; +out vec2 texCoord1; +out vec4 normal; + +void main() { + gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0); + + vertexDistance = cylindrical_distance(ModelViewMat, IViewRotMat * Position); + vertexColor = Color; + lightMapColor = texelFetch(Sampler2, UV2 / 16, 0); + texCoord0 = UV0; + texCoord1 = UV1; + normal = ProjMat * ModelViewMat * vec4(Normal, 0.0); +}