diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 21d520f33..0171090ee 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -68,7 +68,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer impleme float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 270 : 0); float rotZ = sideways ? 90 : (vertical ? 180 : 0); - data.setPosition(te.getPos()) + data.setTileEntity(te) .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) .setRotation(rotX, rotY, rotZ) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 6785f5660..94f93aeb5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -9,7 +9,6 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -72,7 +71,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + .setTileEntity(te); }); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 00b74854d..1bb3f48bc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -8,7 +8,6 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.InstanceContext; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -71,7 +70,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + .setTileEntity(te); }); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java index 5c2a8f2c5..4cebf58d0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/ContraptionBuffer.java @@ -1,20 +1,15 @@ package com.simibubi.create.foundation.utility.render; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.lwjgl.opengl.*; -import org.lwjgl.system.MemoryUtil; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; -import java.nio.Buffer; -import java.nio.ByteBuffer; - public class ContraptionBuffer extends TemplateBuffer { - public static final VertexFormat FORMAT = new VertexFormat(POSITION, NORMAL, UV, COLOR); + public static final VertexFormat FORMAT = new VertexFormat(InstanceBuffer.FORMAT, RGBA); protected int vao, ebo, vbo; @@ -55,10 +50,9 @@ public class ContraptionBuffer extends TemplateBuffer { int stride = FORMAT.getStride(); int invariantSize = vertexCount * stride; - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); - GlStateManager.bindBuffers(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - // Deselect (bind to 0) the VAO - GL30.glBindVertexArray(0); + vao = GL30.glGenVertexArrays(); + ebo = GlStateManager.genBuffers(); + vbo = GlStateManager.genBuffers(); try (SafeDirectBuffer constant = new SafeDirectBuffer(invariantSize)) { constant.order(template.order()); @@ -83,19 +77,15 @@ public class ContraptionBuffer extends TemplateBuffer { } constant.rewind(); - vao = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vao); - ebo = GlStateManager.genBuffers(); - vbo = GlStateManager.genBuffers(); - GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, vbo); GlStateManager.bufferData(GL15.GL_ARRAY_BUFFER, constant.getBacking(), GL15.GL_STATIC_DRAW); buildEBO(ebo); FORMAT.informAttributes(0); } catch (Exception e) { - + e.printStackTrace(); } GlStateManager.bindBuffers(GL15.GL_ARRAY_BUFFER, 0); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index dcb8a4268..4a49583f2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -1,6 +1,8 @@ package com.simibubi.create.foundation.utility.render; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerRenderer; @@ -38,8 +40,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { private Contraption c; - private Vec3d renderPos; - private Vec3d renderRot; + private Matrix4f model; public FastContraptionRenderer(World world, Contraption c) { this.c = c; @@ -89,9 +90,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { } } - private void setRenderSettings(Vec3d position, Vec3d rotation) { - renderPos = position; - renderRot = rotation; + private void setRenderSettings(Matrix4f model) { + this.model = model; } private void setup(int shader) { @@ -120,19 +120,10 @@ public class FastContraptionRenderer extends ContraptionRenderer { buf.rewind(); GlStateManager.uniform3(lightBoxMin, buf); - int cPos = GlStateManager.getUniformLocation(shader, "cPos"); - buf.put(0, (float) renderPos.x); - buf.put(1, (float) renderPos.y); - buf.put(2, (float) renderPos.z); - buf.rewind(); - GlStateManager.uniform3(cPos, buf); - - int cRot = GlStateManager.getUniformLocation(shader, "cRot"); - buf.put(0, (float) renderRot.x); - buf.put(1, (float) renderRot.y); - buf.put(2, (float) renderRot.z); - buf.rewind(); - GlStateManager.uniform3(cRot, buf); + int model = GlStateManager.getUniformLocation(shader, "model"); + this.model.write(ShaderHelper.MATRIX_BUFFER); + ShaderHelper.MATRIX_BUFFER.rewind(); + GlStateManager.uniformMatrix4(model, false, ShaderHelper.MATRIX_BUFFER); } private void invalidate() { @@ -147,8 +138,8 @@ public class FastContraptionRenderer extends ContraptionRenderer { renderLayers.clear(); } - public static void markForRendering(World world, Contraption c, Vec3d position, Vec3d rotation) { - getRenderer(world, c).setRenderSettings(position, rotation); + public static void markForRendering(World world, Contraption c, MatrixStack model) { + getRenderer(world, c).setRenderSettings(model.peek().getModel()); } private static FastContraptionRenderer getRenderer(World world, Contraption c) { @@ -176,6 +167,16 @@ public class FastContraptionRenderer extends ContraptionRenderer { ShaderCallback callback = ShaderHelper.getViewProjectionCallback(projectionMat, viewMat); + + int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); + for (FastContraptionRenderer renderer : renderers.values()) { + renderer.setup(structureShader); + for (ContraptionBuffer layer : renderer.renderLayers) { + layer.render(); + } + renderer.teardown(); + } + int rotatingShader = ShaderHelper.useShader(Shader.CONTRAPTION_ROTATING, callback); for (FastContraptionRenderer renderer : renderers.values()) { renderer.setup(rotatingShader); @@ -190,15 +191,6 @@ public class FastContraptionRenderer extends ContraptionRenderer { renderer.teardown(); } - int structureShader = ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, callback); - for (FastContraptionRenderer renderer : renderers.values()) { - renderer.setup(structureShader); - for (ContraptionBuffer layer : renderer.renderLayers) { - layer.render(); - } - renderer.teardown(); - } - ShaderHelper.releaseShader(); GL11.glDisable(GL13.GL_TEXTURE_3D); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java index b7df264ef..5698537c5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java @@ -1,11 +1,19 @@ package com.simibubi.create.foundation.utility.render.instancing; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.render.SafeDirectBuffer; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; -public class BasicData> extends InstanceData { +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; +public class BasicData> extends InstanceData { + public static final VertexFormat FORMAT = new VertexFormat(RGB, POSITION, LIGHT); + + private byte r; + private byte g; + private byte b; private float x; private float y; private float z; @@ -29,6 +37,22 @@ public class BasicData> extends InstanceData { return (D) this; } + public D setTileEntity(KineticTileEntity te) { + setPosition(te.getPos()); + if (te.hasSource()) { + int color = ColorHelper.colorFromLong(te.network); + r = (byte) ((color >> 16) & 0xFF); + g = (byte) ((color >> 8) & 0xFF); + b = (byte) (color & 0xFF); + } + else { + r = (byte) 0xFF; + g = (byte) 0xFF; + b = (byte) 0x00; + } + return (D) this; + } + public D setPosition(BlockPos pos) { this.x = pos.getX(); this.y = pos.getY(); @@ -38,6 +62,10 @@ public class BasicData> extends InstanceData { @Override public void write(SafeDirectBuffer buf) { + buf.put(r); + buf.put(g); + buf.put(b); + putVec3(buf, x, y, z); putVec2(buf, blockLight, skyLight); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java index f1e359f9c..12c933d05 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java @@ -7,7 +7,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; public class BeltData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, VEC3, FLOAT, VEC2, VEC4, FLOAT); + public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, VEC3, FLOAT, VEC2, VEC4, FLOAT); private float rotX; private float rotY; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java index 0839b37b9..130ae5f8a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstanceBuffer.java @@ -162,10 +162,10 @@ public abstract class InstanceBuffer extends TemplateBuf instanceFormat.informAttributes(staticAttributes); for (int i = 0; i < instanceFormat.getNumAttributes(); i++) { - GL40.glVertexAttribDivisor(i + staticAttributes, 1); + GL33.glVertexAttribDivisor(i + staticAttributes, 1); } } catch (Exception e) { - + e.printStackTrace(); } // Deselect (bind to 0) the VBO diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java index 164bc7610..f0b33392a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java @@ -6,7 +6,7 @@ import net.minecraft.client.renderer.Vector3f; import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; public class RotatingData extends BasicData { - public static VertexFormat FORMAT = new VertexFormat(POSITION, LIGHT, FLOAT, FLOAT, VEC3); + public static VertexFormat FORMAT = new VertexFormat(BasicData.FORMAT, FLOAT, FLOAT, VEC3); private float rotationalSpeed; private float rotationOffset; diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java index 885c1c9d0..522047cc1 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexAttribute.java @@ -11,25 +11,32 @@ public class VertexAttribute { public static final VertexAttribute FLOAT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 1); public static final VertexAttribute POSITION = VEC3; - public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3); - public static final VertexAttribute COLOR = new VertexAttribute(VertexFormatElement.Type.BYTE, 4); + public static final VertexAttribute NORMAL = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); + public static final VertexAttribute RGBA = new VertexAttribute(VertexFormatElement.Type.BYTE, 4, true); + public static final VertexAttribute RGB = new VertexAttribute(VertexFormatElement.Type.BYTE, 3, true); public static final VertexAttribute UV = VEC2; - public static final VertexAttribute LIGHT= VEC2; + public static final VertexAttribute LIGHT = new VertexAttribute(VertexFormatElement.Type.FLOAT, 2); private final VertexFormatElement.Type type; private final int count; private final int size; private final int attributeCount; + private final boolean normalized; public VertexAttribute(VertexFormatElement.Type type, int count) { + this(type, count, false); + } + + public VertexAttribute(VertexFormatElement.Type type, int count, boolean normalized) { this.type = type; this.count = count; this.size = type.getSize() * count; this.attributeCount = (this.size + 15) / 16; // ceiling division. GLSL vertex attributes can only be 16 bytes wide + this.normalized = normalized; } public void registerForBuffer(int stride, int indexAcc, int offsetAcc) { - GL20.glVertexAttribPointer(indexAcc, count, type.getGlConstant(), false, stride, offsetAcc); + GL20.glVertexAttribPointer(indexAcc, count, type.getGlConstant(), normalized, stride, offsetAcc); } public int getSize() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java index 392691e3e..220e69190 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/VertexFormat.java @@ -18,6 +18,22 @@ public class VertexFormat { this.stride = stride; } + public VertexFormat(VertexFormat start, VertexAttribute... elements) { + int baseLength = start.elements.length; + int addedLength = elements.length; + this.elements = new VertexAttribute[baseLength + addedLength]; + System.arraycopy(start.elements, 0, this.elements, 0, baseLength); + System.arraycopy(elements, 0, this.elements, baseLength, addedLength); + + int numAttributes = 0, stride = 0; + for (VertexAttribute element : this.elements) { + numAttributes += element.getAttributeCount(); + stride += element.getSize(); + } + this.numAttributes = numAttributes; + this.stride = stride; + } + public int getNumAttributes() { return numAttributes; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java index 8f13561c8..aeadc3de2 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/shader/ShaderHelper.java @@ -2,6 +2,9 @@ package com.simibubi.create.foundation.utility.render.shader; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.Create; +import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.KineticDebugger; +import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Matrix4f; @@ -93,6 +96,9 @@ public class ShaderHelper { int ticks = GlStateManager.getUniformLocation(program, "ticks"); GlStateManager.uniform1(ticks, AnimationTickHolder.ticks); + int debug = GlStateManager.getUniformLocation(program, "debug"); + GlStateManager.uniform1(debug, KineticDebugger.isActive() ? 1 : 0); + if (cb != null) { cb.call(program); } diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index c40dfd83f..125835300 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -5,22 +5,25 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 rotationDegrees; -layout (location = 6) in float speed; -layout (location = 7) in vec2 sourceUV; -layout (location = 8) in vec4 scrollTexture; -layout (location = 9) in float scrollMult; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in vec3 rotationDegrees; +layout (location = 7) in float speed; +layout (location = 8) in vec2 sourceUV; +layout (location = 9) in vec4 scrollTexture; +layout (location = 10) in float scrollMult; out vec2 TexCoords; out vec2 Light; out float Diffuse; +out vec4 Color; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -56,4 +59,10 @@ void main() { Light = light; TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * renderPos; + + if (debug == 1) { + Color = vec4(networkTint, 1); + } else { + Color = vec4(1); + } } diff --git a/src/main/resources/assets/create/shader/contraption.frag b/src/main/resources/assets/create/shader/contraption.frag index 80a7dec3b..9ec3cc530 100644 --- a/src/main/resources/assets/create/shader/contraption.frag +++ b/src/main/resources/assets/create/shader/contraption.frag @@ -19,5 +19,5 @@ vec4 light() { void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a); + fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/contraption.vert b/src/main/resources/assets/create/shader/contraption.vert index 8364cdc67..05ee9a891 100644 --- a/src/main/resources/assets/create/shader/contraption.vert +++ b/src/main/resources/assets/create/shader/contraption.vert @@ -13,13 +13,13 @@ out vec3 BoxCoord; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; -uniform vec3 cPos; -uniform vec3 cRot; +uniform mat4 model; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -32,11 +32,6 @@ mat4 rotate(vec3 axis, float angle) { 0., 0., 0., 1.); } -mat4 contraptionRotation() { - vec3 rot = -fract(cRot / 360) * PI * 2; - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; @@ -45,12 +40,11 @@ float diffuse(vec3 normal) { } void main() { - mat4 rotation = contraptionRotation(); - vec4 worldPos = (rotation * vec4(aPos - vec3(0.5), 1)) + vec4(cPos + vec3(0.5), 0); + vec4 worldPos = model * vec4(aPos, 1); BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(rotation * vec4(aNormal, 0.)).xyz); - Color = aColor; + Diffuse = diffuse(normalize(model * vec4(aNormal, 0.)).xyz); + Color = vec4(1);//aColor; TexCoords = aTexCoords; gl_Position = projection * view * worldPos; } diff --git a/src/main/resources/assets/create/shader/contraption_belt.vert b/src/main/resources/assets/create/shader/contraption_belt.vert index 320cd8638..1548200d7 100644 --- a/src/main/resources/assets/create/shader/contraption_belt.vert +++ b/src/main/resources/assets/create/shader/contraption_belt.vert @@ -5,13 +5,14 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in vec3 rotationDegrees; -layout (location = 6) in float speed; -layout (location = 7) in vec2 sourceUV; -layout (location = 8) in vec4 scrollTexture; -layout (location = 9) in float scrollMult; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in vec3 rotationDegrees; +layout (location = 7) in float speed; +layout (location = 8) in vec2 sourceUV; +layout (location = 9) in vec4 scrollTexture; +layout (location = 10) in float scrollMult; out float Diffuse; out vec2 TexCoords; @@ -20,16 +21,15 @@ out vec3 BoxCoord; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; -uniform vec3 cPos; -uniform vec3 cRot; +uniform mat4 model; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; -mat4 rotate(vec3 axis, float angle) -{ +mat4 rotate(vec3 axis, float angle) { float s = sin(angle); float c = cos(angle); float oc = 1.0 - c; @@ -44,11 +44,6 @@ mat4 rotation(vec3 rot) { return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); } -mat4 contraptionRotation() { - vec3 rot = -fract(cRot / 360) * PI * 2; - return rotation(rot); -} - mat4 localRotation() { vec3 rot = fract(rotationDegrees / 360) * PI * 2; return rotation(rot); @@ -63,16 +58,15 @@ float diffuse(vec3 normal) { void main() { mat4 localRotation = localRotation(); - vec4 localPos = localRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos, 0); + vec4 localPos = localRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); - mat4 contraptionRotation = contraptionRotation(); - vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); + vec4 worldPos = model * localPos; float scrollSize = scrollTexture.w - scrollTexture.y; float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(contraptionRotation * localRotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize(model * localRotation * vec4(aNormal, 0.)).xyz); Color = vec4(1.); TexCoords = aTexCoords - sourceUV + scrollTexture.xy + vec2(0., scroll); gl_Position = projection * view * worldPos; diff --git a/src/main/resources/assets/create/shader/contraption_rotating.vert b/src/main/resources/assets/create/shader/contraption_rotating.vert index 7315d4a67..7c4ff23db 100644 --- a/src/main/resources/assets/create/shader/contraption_rotating.vert +++ b/src/main/resources/assets/create/shader/contraption_rotating.vert @@ -4,11 +4,12 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in float speed; -layout (location = 6) in float rotationOffset; -layout (location = 7) in vec3 rotationAxis; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in float speed; +layout (location = 7) in float rotationOffset; +layout (location = 8) in vec3 rotationAxis; out float Diffuse; out vec2 TexCoords; @@ -17,13 +18,13 @@ out vec3 BoxCoord; uniform vec3 lightBoxSize; uniform vec3 lightBoxMin; -uniform vec3 cPos; -uniform vec3 cRot; +uniform mat4 model; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 rotate(vec3 axis, float angle) { float s = sin(angle); @@ -43,11 +44,6 @@ mat4 kineticRotation() { return rotate(normalize(rotationAxis), angle); } -mat4 contraptionRotation() { - vec3 rot = -fract(cRot / 360) * PI * 2; - return rotate(vec3(0, 1, 0), rot.y) * rotate(vec3(0, 0, 1), rot.z) * rotate(vec3(1, 0, 0), rot.x); -} - float diffuse(vec3 normal) { float x = normal.x; float y = normal.y; @@ -57,13 +53,12 @@ float diffuse(vec3 normal) { void main() { mat4 kineticRotation = kineticRotation(); - vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos, 0); + vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0); - mat4 contraptionRotation = contraptionRotation(); - vec4 worldPos = contraptionRotation * localPos + vec4(cPos + 0.5, 0); + vec4 worldPos = model * localPos; BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize; - Diffuse = diffuse(normalize(contraptionRotation * kineticRotation * vec4(aNormal, 0.)).xyz); + Diffuse = diffuse(normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz); Color = vec4(1.); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; diff --git a/src/main/resources/assets/create/shader/instanced.frag b/src/main/resources/assets/create/shader/instanced.frag index 8172975c0..fae8b8494 100644 --- a/src/main/resources/assets/create/shader/instanced.frag +++ b/src/main/resources/assets/create/shader/instanced.frag @@ -3,6 +3,7 @@ in vec2 TexCoords; in vec2 Light; in float Diffuse; +in vec4 Color; out vec4 fragColor; @@ -17,5 +18,5 @@ vec4 light() { void main() { vec4 tex = texture2D(BlockAtlas, TexCoords); - fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a); + fragColor = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color; } \ No newline at end of file diff --git a/src/main/resources/assets/create/shader/rotating.vert b/src/main/resources/assets/create/shader/rotating.vert index b1e2a4ab1..9e7eb6573 100644 --- a/src/main/resources/assets/create/shader/rotating.vert +++ b/src/main/resources/assets/create/shader/rotating.vert @@ -4,20 +4,23 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; -layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec2 light; -layout (location = 5) in float speed; -layout (location = 6) in float rotationOffset; -layout (location = 7) in vec3 rotationAxis; +layout (location = 3) in vec3 networkTint; +layout (location = 4) in vec3 instancePos; +layout (location = 5) in vec2 light; +layout (location = 6) in float speed; +layout (location = 7) in float rotationOffset; +layout (location = 8) in vec3 rotationAxis; out vec2 TexCoords; out vec2 Light; out float Diffuse; +out vec4 Color; uniform float time; uniform int ticks; uniform mat4 projection; uniform mat4 view; +uniform int debug; mat4 kineticRotation() { float degrees = rotationOffset + time * speed * -3./10.; @@ -50,4 +53,10 @@ void main() { TexCoords = aTexCoords; gl_Position = projection * view * renderPos; Light = light; + + if (debug == 1) { + Color = vec4(networkTint, 1); + } else { + Color = vec4(1); + } } \ No newline at end of file