mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
fast actor rendering but it's not correct yet
This commit is contained in:
parent
f6518d5c5d
commit
cfd60fbc8d
13 changed files with 115 additions and 37 deletions
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.actors;
|
|||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -31,12 +32,12 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour {
|
|||
@OnlyIn(value = Dist.CLIENT)
|
||||
public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
DrillRenderer.renderInContraption(context, ms, msLocal, buffer);
|
||||
//DrillRenderer.renderInContraption(context, ms, msLocal, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstance(MovementContext context) {
|
||||
super.addInstance(context);
|
||||
public void addInstance(RenderedContraption contraption, MovementContext context) {
|
||||
DrillRenderer.addInstanceForContraption(contraption, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,9 @@ import com.simibubi.create.AllBlockPartials;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import com.simibubi.create.foundation.render.instancing.RenderMaterial;
|
||||
import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||
|
@ -19,6 +22,7 @@ import com.simibubi.create.foundation.render.instancing.RotatingData;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
|
@ -37,8 +41,20 @@ public class DrillRenderer extends KineticTileEntityRenderer {
|
|||
return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state);
|
||||
}
|
||||
|
||||
public static void addInstanceForContraption(MovementContext context) {
|
||||
//AllBlockPartials.DRILL_HEAD.
|
||||
public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) {
|
||||
RenderMaterial<InstanceBuffer<StaticRotatingActorData>> renderMaterial = contraption.getActorMaterial();
|
||||
|
||||
BlockState state = context.state;
|
||||
InstanceBuffer<StaticRotatingActorData> model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state);
|
||||
|
||||
model.setupInstance(data -> {
|
||||
Direction facing = state.get(DrillBlock.FACING);
|
||||
Vector3f orientation = facing.getOpposite().getUnitVector();
|
||||
data.setPosition(context.localPos)
|
||||
.setRotationOffset(0)
|
||||
.setRotationAxis(orientation)
|
||||
.setLocalRotation(AngleHelper.verticalAngle(facing), facing.getHorizontalAngle(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.actors;
|
|||
|
||||
import static net.minecraft.block.HorizontalBlock.HORIZONTAL_FACING;
|
||||
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
@ -35,10 +36,15 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
|
|||
.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstance(RenderedContraption contraption, MovementContext context) {
|
||||
HarvesterRenderer.addInstanceForContraption(contraption, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffers) {
|
||||
HarvesterRenderer.renderInContraption(context, ms, msLocal, buffers);
|
||||
//HarvesterRenderer.renderInContraption(context, ms, msLocal, buffers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,10 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC
|
|||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import com.simibubi.create.foundation.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.render.instancing.RenderMaterial;
|
||||
import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData;
|
||||
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
|
@ -14,6 +18,7 @@ import com.simibubi.create.foundation.utility.VecHelper;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -34,6 +39,25 @@ public class HarvesterRenderer extends SafeTileEntityRenderer<HarvesterTileEntit
|
|||
.renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped()));
|
||||
}
|
||||
|
||||
public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) {
|
||||
RenderMaterial<InstanceBuffer<StaticRotatingActorData>> renderMaterial = contraption.getActorMaterial();
|
||||
|
||||
BlockState state = context.state;
|
||||
InstanceBuffer<StaticRotatingActorData> model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state);
|
||||
|
||||
model.setupInstance(data -> {
|
||||
Direction facing = state.get(HORIZONTAL_FACING);
|
||||
Direction rotationAxis = facing.rotateY();
|
||||
float originOffset = 1 / 16f;
|
||||
Vector3f rotOffset = new Vector3f(0.5f, -2 * originOffset + 0.5f, originOffset + 0.5f);
|
||||
data.setPosition(context.localPos)
|
||||
.setRotationOffset(0)
|
||||
.setRotationCenter(rotOffset)
|
||||
.setRotationAxis(rotationAxis.getUnitVector())
|
||||
.setLocalRotation(0, facing.getHorizontalAngle(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffers) {
|
||||
BlockState blockState = context.state;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement;
|
|||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -56,7 +57,7 @@ public abstract class MovementBehaviour {
|
|||
IRenderTypeBuffer buffer) {}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInstance(MovementContext context) {}
|
||||
public void addInstance(RenderedContraption contraption, MovementContext context) {}
|
||||
|
||||
public void onSpeedChanged(MovementContext context, Vec3d oldMotion, Vec3d motion) {
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ public class FastKineticRenderer {
|
|||
|
||||
public void invalidate() {
|
||||
for (RenderMaterial<?> material : materials.values()) {
|
||||
material.runOnAll(InstanceBuffer::delete);
|
||||
material.delete();
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,8 @@ import com.simibubi.create.foundation.render.instancing.BeltBuffer;
|
|||
import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials;
|
||||
import com.simibubi.create.foundation.render.instancing.RenderMaterial;
|
||||
import com.simibubi.create.foundation.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.render.instancing.actors.RotatingActorBuffer;
|
||||
import com.simibubi.create.foundation.render.shader.Shader;
|
||||
import com.simibubi.create.foundation.render.shader.ShaderCallback;
|
||||
import com.simibubi.create.foundation.render.shader.ShaderHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
public class ContraptionKineticRenderer extends FastKineticRenderer {
|
||||
|
||||
|
@ -18,6 +14,7 @@ public class ContraptionKineticRenderer extends FastKineticRenderer {
|
|||
public void registerMaterials() {
|
||||
materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(Shader.CONTRAPTION_BELT, BeltBuffer::new));
|
||||
materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(Shader.CONTRAPTION_ROTATING, RotatingBuffer::new));
|
||||
materials.put(KineticRenderMaterials.ACTORS, new RenderMaterial<>(Shader.CONTRAPTION_ACTOR, RotatingActorBuffer::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,8 +7,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con
|
|||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||
import com.simibubi.create.foundation.render.FastKineticRenderer;
|
||||
import com.simibubi.create.foundation.render.instancing.IInstanceRendered;
|
||||
import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.render.instancing.*;
|
||||
import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData;
|
||||
import com.simibubi.create.foundation.render.light.ContraptionLighter;
|
||||
import com.simibubi.create.foundation.render.shader.ShaderHelper;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
|
@ -43,6 +43,8 @@ public class RenderedContraption {
|
|||
|
||||
buildLayers(contraption);
|
||||
buildInstancedTiles(contraption);
|
||||
buildActors(contraption);
|
||||
kinetics.markAllDirty();
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
|
@ -57,6 +59,10 @@ public class RenderedContraption {
|
|||
return lighter;
|
||||
}
|
||||
|
||||
public RenderMaterial<InstanceBuffer<StaticRotatingActorData>> getActorMaterial() {
|
||||
return kinetics.get(KineticRenderMaterials.ACTORS);
|
||||
}
|
||||
|
||||
public void doRenderLayer(RenderType layer, int shader) {
|
||||
ContraptionBuffer buffer = renderLayers.get(layer);
|
||||
if (buffer != null) {
|
||||
|
@ -93,8 +99,6 @@ public class RenderedContraption {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
kinetics.markAllDirty();
|
||||
}
|
||||
|
||||
private void buildActors(Contraption c) {
|
||||
|
@ -107,7 +111,7 @@ public class RenderedContraption {
|
|||
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
|
||||
|
||||
if (movementBehaviour != null) {
|
||||
movementBehaviour.addInstance(context);
|
||||
movementBehaviour.addInstance(this, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public abstract class InstanceBuffer<D extends InstanceData> extends GPUBuffer {
|
|||
}
|
||||
|
||||
protected int getTotalShaderAttributeCount() {
|
||||
return getInstanceFormat().getShaderAttributeCount() + FORMAT.getShaderAttributeCount();
|
||||
return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,7 +130,7 @@ public abstract class InstanceBuffer<D extends InstanceData> extends GPUBuffer {
|
|||
buffer.rewind();
|
||||
GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER);
|
||||
|
||||
int staticAttributes = FORMAT.getShaderAttributeCount();
|
||||
int staticAttributes = getModelFormat().getShaderAttributeCount();
|
||||
instanceFormat.informAttributes(staticAttributes);
|
||||
|
||||
for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) {
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.simibubi.create.foundation.render.instancing;
|
||||
|
||||
import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData;
|
||||
|
||||
public class KineticRenderMaterials {
|
||||
public static final MaterialType<InstanceBuffer<RotatingData>> ROTATING = new MaterialType<>();
|
||||
public static final MaterialType<InstanceBuffer<BeltData>> BELTS = new MaterialType<>();
|
||||
|
||||
public static final MaterialType<InstanceBuffer<StaticRotatingActorData>> ACTORS = new MaterialType<>();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.foundation.render.instancing.actors;
|
||||
|
||||
import com.simibubi.create.foundation.render.instancing.InstanceData;
|
||||
import com.simibubi.create.foundation.render.instancing.RotatingData;
|
||||
import com.simibubi.create.foundation.render.instancing.VertexFormat;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -11,7 +10,7 @@ import java.nio.ByteBuffer;
|
|||
import static com.simibubi.create.foundation.render.instancing.VertexAttribute.*;
|
||||
|
||||
public class StaticRotatingActorData extends InstanceData {
|
||||
public static VertexFormat FORMAT = new VertexFormat(POSITION, FLOAT, NORMAL, NORMAL);
|
||||
public static VertexFormat FORMAT = new VertexFormat(POSITION, FLOAT, NORMAL, VEC3, NORMAL);
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
|
@ -20,9 +19,12 @@ public class StaticRotatingActorData extends InstanceData {
|
|||
private byte rotationAxisX;
|
||||
private byte rotationAxisY;
|
||||
private byte rotationAxisZ;
|
||||
private byte localOrientationX;
|
||||
private byte localOrientationY;
|
||||
private byte localOrientationZ;
|
||||
private float localRotationX;
|
||||
private float localRotationY;
|
||||
private float localRotationZ;
|
||||
private byte rotationCenterX = 64;
|
||||
private byte rotationCenterY = 64;
|
||||
private byte rotationCenterZ = 64;
|
||||
|
||||
public StaticRotatingActorData setPosition(BlockPos pos) {
|
||||
this.x = pos.getX();
|
||||
|
@ -48,15 +50,27 @@ public class StaticRotatingActorData extends InstanceData {
|
|||
return this;
|
||||
}
|
||||
|
||||
public StaticRotatingActorData setLocalOrientation(Vector3f axis) {
|
||||
setRotationAxis(axis.getX(), axis.getY(), axis.getZ());
|
||||
public StaticRotatingActorData setRotationCenter(Vector3f axis) {
|
||||
setRotationCenter(axis.getX(), axis.getY(), axis.getZ());
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticRotatingActorData setLocalOrientation(float localOrientationX, float localOrientationY, float localOrientationZ) {
|
||||
this.localOrientationX = (byte) (localOrientationX * 127);
|
||||
this.localOrientationY = (byte) (localOrientationY * 127);
|
||||
this.localOrientationZ = (byte) (localOrientationZ * 127);
|
||||
public StaticRotatingActorData setRotationCenter(float rotationCenterX, float rotationCenterY, float rotationCenterZ) {
|
||||
this.rotationCenterX = (byte) (rotationCenterX * 127);
|
||||
this.rotationCenterY = (byte) (rotationCenterY * 127);
|
||||
this.rotationCenterZ = (byte) (rotationCenterZ * 127);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticRotatingActorData setLocalRotation(Vector3f axis) {
|
||||
setLocalRotation(axis.getX(), axis.getY(), axis.getZ());
|
||||
return this;
|
||||
}
|
||||
|
||||
public StaticRotatingActorData setLocalRotation(float localRotationX, float localRotationY, float localRotationZ) {
|
||||
this.localRotationX = localRotationX;
|
||||
this.localRotationY = localRotationY;
|
||||
this.localRotationZ = localRotationZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -65,7 +79,8 @@ public class StaticRotatingActorData extends InstanceData {
|
|||
putVec3(buf, x, y, z);
|
||||
put(buf, rotationOffset);
|
||||
putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ);
|
||||
putVec3(buf, localOrientationX, localOrientationY, localOrientationZ);
|
||||
putVec3(buf, localRotationX, localRotationY, localRotationZ);
|
||||
putVec3(buf, rotationCenterX, rotationCenterY, rotationCenterZ);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ public enum Shader {
|
|||
CONTRAPTION_STRUCTURE("shader/contraption.vert", "shader/contraption.frag"),
|
||||
CONTRAPTION_ROTATING("shader/contraption_rotating.vert", "shader/contraption.frag"),
|
||||
CONTRAPTION_BELT("shader/contraption_belt.vert", "shader/contraption.frag"),
|
||||
//CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"),
|
||||
CONTRAPTION_ACTOR("shader/contraption_actor.vert", "shader/contraption.frag"),
|
||||
;
|
||||
|
||||
public final String vert;
|
||||
|
|
|
@ -9,10 +9,11 @@ layout (location = 2) in vec2 aTexCoords;
|
|||
layout (location = 3) in vec3 instancePos;
|
||||
layout (location = 4) in float rotationOffset;
|
||||
layout (location = 5) in vec3 localRotationAxis;
|
||||
layout (location = 6) in vec3 localOrientation;
|
||||
layout (location = 6) in vec3 localRotation;
|
||||
layout (location = 7) in vec3 rotationCenter;
|
||||
|
||||
// dynamic data
|
||||
layout (location = 7) in vec3 relativeMotion;
|
||||
//layout (location = 7) in vec3 relativeMotion;
|
||||
|
||||
out float Diffuse;
|
||||
out vec2 TexCoords;
|
||||
|
@ -40,7 +41,12 @@ mat4 rotate(vec3 axis, float angle) {
|
|||
0., 0., 0., 1.);
|
||||
}
|
||||
|
||||
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 kineticRotation() {
|
||||
const float speed = 20;
|
||||
float degrees = rotationOffset + time * speed * -3./10.;
|
||||
float angle = fract(degrees / 360.) * PI * 2.;
|
||||
|
||||
|
@ -55,13 +61,17 @@ float diffuse(vec3 normal) {
|
|||
}
|
||||
|
||||
void main() {
|
||||
vec3 rot = fract(localRotation / 360.) * PI * 2.;
|
||||
mat4 localRot = rotation(rot);
|
||||
vec4 localPos = localRot * vec4(aPos - 0.5, 1f) + vec4(0.5, 0.5, 0.5, 0);
|
||||
|
||||
mat4 kineticRotation = kineticRotation();
|
||||
vec4 localPos = kineticRotation * vec4(aPos - 0.5, 1f) + vec4(instancePos + 0.5, 0);
|
||||
localPos = kineticRotation * vec4(localPos.xyz - rotationCenter, 1) + vec4(instancePos + rotationCenter, 0);
|
||||
|
||||
vec4 worldPos = model * localPos;
|
||||
|
||||
BoxCoord = (worldPos.xyz - lightBoxMin) / lightBoxSize;
|
||||
Diffuse = diffuse(normalize(model * kineticRotation * vec4(aNormal, 0.)).xyz);
|
||||
Diffuse = diffuse(normalize(model * localRot * kineticRotation * vec4(aNormal, 0.)).xyz);
|
||||
Color = vec4(1.);
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = projection * view * worldPos;
|
||||
|
|
Loading…
Reference in a new issue