diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index ade41072b..d22f9e634 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -1,9 +1,10 @@ package com.jozufozu.flywheel.backend; -import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D; -import static org.lwjgl.opengl.GL11.glBindTexture; -import static org.lwjgl.opengl.GL13.GL_TEXTURE0; -import static org.lwjgl.opengl.GL13.glActiveTexture; +import static org.lwjgl.opengl.GL20.GL_TEXTURE0; +import static org.lwjgl.opengl.GL20.GL_TEXTURE4; +import static org.lwjgl.opengl.GL20.GL_TEXTURE_2D; +import static org.lwjgl.opengl.GL20.glActiveTexture; +import static org.lwjgl.opengl.GL20.glBindTexture; import java.util.BitSet; import java.util.Collection; @@ -44,6 +45,7 @@ import net.minecraft.client.renderer.texture.Texture; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.tileentity.TileEntity; @@ -246,6 +248,9 @@ public class Backend { ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE).getGlTextureId()); + + glActiveTexture(GL_TEXTURE4); CRUMBLING.startDrawing(); bitSet.stream().forEach(i -> { @@ -261,6 +266,11 @@ public class Backend { renderer.invalidate(); }); CRUMBLING.endDrawing(); + + glActiveTexture(GL_TEXTURE0); + Texture breaking = textureManager.getTexture(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(0)); + if (breaking != null) + glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); } public static void enqueueUpdate(TileEntity te) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java b/src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java index c08f37516..de84fd268 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/core/ContraptionContext.java @@ -12,7 +12,7 @@ public class ContraptionContext extends WorldContext { public static final ContraptionContext INSTANCE = new ContraptionContext(); public ContraptionContext() { - super(new ResourceLocation("create", "contraption"), new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new)); + super(new ResourceLocation("create", "context/contraption"), new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new)); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java b/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java index e254a54d2..e25feeee4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java +++ b/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java @@ -8,6 +8,7 @@ import net.minecraft.util.ResourceLocation; public class CrumblingProgram extends BasicProgram { protected final int uTextureScale; + protected int uCrumbling; public CrumblingProgram(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory) { super(name, handle, fogFactory); @@ -15,6 +16,12 @@ public class CrumblingProgram extends BasicProgram { uTextureScale = getUniformLocation("uTextureScale"); } + @Override + protected void registerSamplers() { + super.registerSamplers(); + uCrumbling = setSamplerBinding("uCrumbling", 4); + } + public void setTextureScale(float x, float y) { glUniform2f(uTextureScale, x, y); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java index 54797de14..693150665 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java @@ -22,8 +22,8 @@ public class WorldContext

extends ShaderContext

{ private static final String declaration = "#flwbuiltins"; private static final Pattern builtinPattern = Pattern.compile(declaration); - public static final WorldContext INSTANCE = new WorldContext<>(new ResourceLocation("create", "std"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new)); - public static final WorldContext CRUMBLING = new WorldContext<>(new ResourceLocation("create", "crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new)); + public static final WorldContext INSTANCE = new WorldContext<>(new ResourceLocation("create", "context/std"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new)); + public static final WorldContext CRUMBLING = new WorldContext<>(new ResourceLocation("create", "context/crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new)); private final ShaderSpecLoader

loader; diff --git a/src/main/resources/assets/create/flywheel/shaders/block.frag b/src/main/resources/assets/create/flywheel/shaders/block.frag index 625fc9ea5..2f26044ac 100644 --- a/src/main/resources/assets/create/flywheel/shaders/block.frag +++ b/src/main/resources/assets/create/flywheel/shaders/block.frag @@ -13,6 +13,4 @@ void main() { vec4 color = vec4(tex.rgb * FLWLight(Light).rgb * Diffuse, tex.a) * Color; FLWFinalizeColor(color); - - gl_FragColor = color; } diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.frag b/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag similarity index 83% rename from src/main/resources/assets/create/flywheel/shaders/contraption/builtin.frag rename to src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag index 5091e0ae3..c7463793f 100644 --- a/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.frag +++ b/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag @@ -1,4 +1,4 @@ -#flwinclude <"create:std/fog.glsl"> +#flwinclude <"create:context/std/fog.glsl"> varying vec3 BoxCoord; uniform sampler3D uLightVolume; @@ -10,7 +10,7 @@ vec4 FLWBlockTexture(vec2 texCoords) { return texture2D(uBlockAtlas, texCoords); } -void FLWFinalizeColor(inout vec4 color) { +void FLWFinalizeColor(vec4 color) { #if defined(USE_FOG) float a = color.a; float fog = clamp(FLWFogFactor(), 0., 1.); @@ -18,6 +18,8 @@ void FLWFinalizeColor(inout vec4 color) { color = mix(uFogColor, color, fog); color.a = a; #endif + + gl_FragColor = color; } vec4 FLWLight(vec2 lightCoords) { diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.vert similarity index 100% rename from src/main/resources/assets/create/flywheel/shaders/contraption/builtin.vert rename to src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.vert diff --git a/src/main/resources/assets/create/flywheel/shaders/crumbling/builtin.frag b/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.frag similarity index 53% rename from src/main/resources/assets/create/flywheel/shaders/crumbling/builtin.frag rename to src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.frag index d5dda65a2..40bcfbdc4 100644 --- a/src/main/resources/assets/create/flywheel/shaders/crumbling/builtin.frag +++ b/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.frag @@ -1,14 +1,18 @@ -#flwinclude <"create:std/fog.glsl"> +#flwinclude <"create:context/std/fog.glsl"> uniform vec2 uTextureScale; uniform sampler2D uBlockAtlas; uniform sampler2D uLightMap; +uniform sampler2D uCrumbling; vec4 FLWBlockTexture(vec2 texCoords) { - return texture2D(uBlockAtlas, texCoords * uTextureScale); + vec4 cr = texture2D(uCrumbling, texCoords * uTextureScale); + float diffuseAlpha = texture2D(uBlockAtlas, texCoords).a; + cr.a = cr.a * diffuseAlpha; + return cr; } -void FLWFinalizeColor(inout vec4 color) { +void FLWFinalizeColor(vec4 color) { #if defined(USE_FOG) float a = color.a; float fog = clamp(FLWFogFactor(), 0., 1.); @@ -16,6 +20,8 @@ void FLWFinalizeColor(inout vec4 color) { color = mix(uFogColor, color, fog); color.a = a; #endif + + gl_FragColor = color; } vec4 FLWLight(vec2 lightCoords) { diff --git a/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.vert new file mode 100644 index 000000000..3ca685f97 --- /dev/null +++ b/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.vert @@ -0,0 +1 @@ +#flwinclude <"create:context/std/builtin.vert"> diff --git a/src/main/resources/assets/create/flywheel/shaders/std/builtin.frag b/src/main/resources/assets/create/flywheel/shaders/context/std/builtin.frag similarity index 80% rename from src/main/resources/assets/create/flywheel/shaders/std/builtin.frag rename to src/main/resources/assets/create/flywheel/shaders/context/std/builtin.frag index 42be74ede..d8f079be6 100644 --- a/src/main/resources/assets/create/flywheel/shaders/std/builtin.frag +++ b/src/main/resources/assets/create/flywheel/shaders/context/std/builtin.frag @@ -1,4 +1,4 @@ -#flwinclude <"create:std/fog.glsl"> +#flwinclude <"create:context/std/fog.glsl"> uniform sampler2D uBlockAtlas; uniform sampler2D uLightMap; @@ -7,7 +7,7 @@ vec4 FLWBlockTexture(vec2 texCoords) { return texture2D(uBlockAtlas, texCoords); } -void FLWFinalizeColor(inout vec4 color) { +void FLWFinalizeColor(vec4 color) { #if defined(USE_FOG) float a = color.a; float fog = clamp(FLWFogFactor(), 0., 1.); @@ -15,6 +15,8 @@ void FLWFinalizeColor(inout vec4 color) { color = mix(uFogColor, color, fog); color.a = a; #endif + + gl_FragColor = color; } vec4 FLWLight(vec2 lightCoords) { diff --git a/src/main/resources/assets/create/flywheel/shaders/std/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/context/std/builtin.vert similarity index 100% rename from src/main/resources/assets/create/flywheel/shaders/std/builtin.vert rename to src/main/resources/assets/create/flywheel/shaders/context/std/builtin.vert diff --git a/src/main/resources/assets/create/flywheel/shaders/std/fog.glsl b/src/main/resources/assets/create/flywheel/shaders/context/std/fog.glsl similarity index 100% rename from src/main/resources/assets/create/flywheel/shaders/std/fog.glsl rename to src/main/resources/assets/create/flywheel/shaders/context/std/fog.glsl diff --git a/src/main/resources/assets/create/flywheel/shaders/crumbling/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/crumbling/builtin.vert deleted file mode 100644 index 694f2920e..000000000 --- a/src/main/resources/assets/create/flywheel/shaders/crumbling/builtin.vert +++ /dev/null @@ -1 +0,0 @@ -#flwinclude <"create:std/builtin.vert">