rainbow debugging and almost correct tints for contraptions

This commit is contained in:
JozsefA 2021-01-12 01:56:30 -08:00
parent c567437ede
commit 0ec312340f
24 changed files with 162 additions and 177 deletions

View file

@ -68,7 +68,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
data.setRotationalSpeed(te.getSpeed())
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
.setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector())
.setPosition(pos);
.setTileEntity(te);
if (ctx.checkWorldLight()) {
data.setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()))

View file

@ -10,10 +10,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
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.WorldRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
@ -58,7 +56,7 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer {
data.setRotationalSpeed(speed)
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setPosition(pos);
.setTileEntity(te);
if (ctx.checkWorldLight()) {
BlockPos inFront = te.getPos().offset(direction);

View file

@ -25,15 +25,6 @@ public abstract class AbstractContraptionEntityRenderer<C extends AbstractContra
protected abstract void transform(C contraptionEntity, float partialTicks, MatrixStack[] matrixStacks);
public Vec3d getPosition(C entity, float partialTicks) {
double x = MathHelper.lerp(partialTicks, entity.lastTickPosX, entity.getX());
double y = MathHelper.lerp(partialTicks, entity.lastTickPosY, entity.getY());
double z = MathHelper.lerp(partialTicks, entity.lastTickPosZ, entity.getZ());
return new Vec3d(x, y, z);
}
public abstract Vec3d getRotation(C contraptionEntity, float partialTicks);
@Override
public boolean shouldRender(C entity, ClippingHelperImpl p_225626_2_, double p_225626_3_, double p_225626_5_,
double p_225626_7_) {
@ -60,7 +51,7 @@ public abstract class AbstractContraptionEntityRenderer<C extends AbstractContra
Contraption contraption = entity.getContraption();
if (contraption != null) {
ContraptionRenderer.renderDynamic(entity.world, contraption, ms, msLocal, buffers);
FastContraptionRenderer.markForRendering(entity.world, contraption, getPosition(entity, partialTicks), getRotation(entity, partialTicks));
FastContraptionRenderer.markForRendering(entity.world, contraption, msLocal);
}
ms.pop();

View file

@ -27,17 +27,4 @@ public class ControlledContraptionEntityRenderer extends AbstractContraptionEnti
.rotate(angle, axis)
.unCentre();
}
public Vec3d getRotation(ControlledContraptionEntity entity, float partialTicks) {
Axis axis = entity.getRotationAxis();
if (axis == null) return Vec3d.ZERO;
float angle = entity.getAngle(partialTicks);
if (axis == Axis.X) return new Vec3d(angle, 0, 0);
if (axis == Axis.Y) return new Vec3d(0, angle, 0);
if (axis == Axis.Z) return new Vec3d(0, 0, angle);
throw new IllegalStateException("impossible axis");
}
}

View file

@ -57,32 +57,6 @@ public class OrientedContraptionEntityRenderer extends AbstractContraptionEntity
.unCentre();
}
@Override
public Vec3d getPosition(OrientedContraptionEntity entity, float partialTicks) {
Vec3d offset = Vec3d.ZERO;
Entity ridingEntity = entity.getRidingEntity();
if (ridingEntity instanceof AbstractMinecartEntity)
offset = getCartOffset(partialTicks, ridingEntity);
else if (ridingEntity instanceof AbstractContraptionEntity) {
if (ridingEntity.getRidingEntity() instanceof AbstractMinecartEntity)
offset = getCartOffset(partialTicks, ridingEntity.getRidingEntity());
else
offset = getContraptionOffset(entity, partialTicks, ridingEntity);
}
Vec3d pos = super.getPosition(entity, partialTicks);
return new Vec3d(pos.x + offset.x - 0.5, pos.y + offset.y, pos.z + offset.z - 0.5);
}
public Vec3d getRotation(OrientedContraptionEntity entity, float partialTicks) {
float angleInitialYaw = entity.getInitialYaw();
float angleYaw = entity.getYaw(partialTicks);
float anglePitch = entity.getPitch(partialTicks);
return new Vec3d(0, angleInitialYaw + angleYaw, anglePitch);
}
private void repositionOnContraption(OrientedContraptionEntity entity, float partialTicks,
MatrixStack[] matrixStacks, Entity ridingEntity) {
Vec3d pos = getContraptionOffset(entity, partialTicks, ridingEntity);

View file

@ -1,21 +1,17 @@
package com.simibubi.create.content.contraptions.relays.belt;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.function.Function;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllSpriteShifts;
import com.simibubi.create.CreateClient;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack;
import com.simibubi.create.foundation.block.render.SpriteShiftEntry;
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.render.FastContraptionRenderer;
import com.simibubi.create.foundation.utility.render.FastKineticRenderer;
import com.simibubi.create.foundation.utility.render.instancing.*;
import com.simibubi.create.foundation.utility.render.ShadowRenderHelper;
@ -113,7 +109,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> 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)

View file

@ -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);
});
}
}

View file

@ -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);
});
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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<D extends BasicData<D>> extends InstanceData {
import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*;
public class BasicData<D extends BasicData<D>> 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<D extends BasicData<D>> 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<D extends BasicData<D>> 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);

View file

@ -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<BeltData> {
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;

View file

@ -162,10 +162,10 @@ public abstract class InstanceBuffer<D extends InstanceData> 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

View file

@ -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<RotatingData> {
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;

View file

@ -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() {

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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);
}
}