CubeParticle hotfix

- Switched to additive cube particle mode
- Fixed cube particles not rendering properly with other entities in frame
This commit is contained in:
simibubi 2020-07-19 00:50:03 +02:00
parent 257dc11f55
commit a009540190

View file

@ -1,7 +1,11 @@
package com.simibubi.create.content.contraptions.particle; package com.simibubi.create.content.contraptions.particle;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.particle.IParticleFactory; import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.particle.IParticleRenderType;
import net.minecraft.client.particle.Particle; import net.minecraft.client.particle.Particle;
@ -13,45 +17,37 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
public class CubeParticle extends Particle { public class CubeParticle extends Particle {
public static final Vec3d[] CUBE = { public static final Vec3d[] CUBE = {
// TOP // TOP
new Vec3d(1, 1, -1), new Vec3d(1, 1, 1), new Vec3d(-1, 1, 1), new Vec3d(-1, 1, -1), new Vec3d(1, 1, -1), new Vec3d(1, 1, 1), new Vec3d(-1, 1, 1), new Vec3d(-1, 1, -1),
// BOTTOM // BOTTOM
new Vec3d(-1, -1, -1), new Vec3d(-1, -1, 1), new Vec3d(1, -1, 1), new Vec3d(1, -1, -1), new Vec3d(-1, -1, -1), new Vec3d(-1, -1, 1), new Vec3d(1, -1, 1), new Vec3d(1, -1, -1),
// FRONT // FRONT
new Vec3d(-1, -1, 1), new Vec3d(-1, 1, 1), new Vec3d(1, 1, 1), new Vec3d(1, -1, 1), new Vec3d(-1, -1, 1), new Vec3d(-1, 1, 1), new Vec3d(1, 1, 1), new Vec3d(1, -1, 1),
// BACK // BACK
new Vec3d(1, -1, -1), new Vec3d(1, 1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, -1, -1), new Vec3d(1, -1, -1), new Vec3d(1, 1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, -1, -1),
// LEFT // LEFT
new Vec3d(-1, -1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, 1, 1), new Vec3d(-1, -1, 1), new Vec3d(-1, -1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, 1, 1), new Vec3d(-1, -1, 1),
// RIGHT // RIGHT
new Vec3d(1, -1, 1), new Vec3d(1, 1, 1), new Vec3d(1, 1, -1), new Vec3d(1, -1, -1) }; new Vec3d(1, -1, 1), new Vec3d(1, 1, 1), new Vec3d(1, 1, -1), new Vec3d(1, -1, -1) };
public static final Vec3d[] CUBE_NORMALS = { public static final Vec3d[] CUBE_NORMALS = {
//modified normals for the sides // modified normals for the sides
new Vec3d(0, 1, 0), new Vec3d(0, 1, 0), new Vec3d(0, -1, 0), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1),
new Vec3d(0, -1, 0), new Vec3d(0, 0, 1),
new Vec3d(0, 0, 1),
new Vec3d(0, 0, 1),
new Vec3d(0, 0, 1),
new Vec3d(0, 0, 1),
/*
/*new Vec3d(0, 1, 0), * new Vec3d(0, 1, 0), new Vec3d(0, -1, 0), new Vec3d(0, 0, 1), new Vec3d(0, 0,
new Vec3d(0, -1, 0), * -1), new Vec3d(-1, 0, 0), new Vec3d(1, 0, 0)
new Vec3d(0, 0, 1), */
new Vec3d(0, 0, -1),
new Vec3d(-1, 0, 0),
new Vec3d(1, 0, 0)*/
}; };
private static final IParticleRenderType renderType = new IParticleRenderType() { private static final IParticleRenderType renderType = new IParticleRenderType() {
@ -59,16 +55,17 @@ public class CubeParticle extends Particle {
public void beginRender(BufferBuilder builder, TextureManager textureManager) { public void beginRender(BufferBuilder builder, TextureManager textureManager) {
RenderSystem.disableTexture(); RenderSystem.disableTexture();
//transparent, additive blending // transparent, additive blending
//RenderSystem.depthMask(false); RenderSystem.depthMask(false);
//RenderSystem.enableBlend(); RenderSystem.enableBlend();
//RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE); RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
//RenderSystem.enableLighting();
//opaque
RenderSystem.depthMask(true);
RenderSystem.disableBlend();
RenderSystem.enableLighting(); RenderSystem.enableLighting();
RenderSystem.enableColorMaterial();
// opaque
// RenderSystem.depthMask(true);
// RenderSystem.disableBlend();
// RenderSystem.enableLighting();
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
} }
@ -76,6 +73,8 @@ public class CubeParticle extends Particle {
@Override @Override
public void finishRender(Tessellator tessellator) { public void finishRender(Tessellator tessellator) {
tessellator.draw(); tessellator.draw();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.enableTexture(); RenderSystem.enableTexture();
} }
}; };
@ -103,25 +102,30 @@ public class CubeParticle extends Particle {
@Override @Override
public void buildGeometry(IVertexBuilder builder, ActiveRenderInfo renderInfo, float p_225606_3_) { public void buildGeometry(IVertexBuilder builder, ActiveRenderInfo renderInfo, float p_225606_3_) {
Vec3d projectedView = renderInfo.getProjectedView(); Vec3d projectedView = renderInfo.getProjectedView();
float lerpedX = (float)(MathHelper.lerp(p_225606_3_, this.prevPosX, this.posX) - projectedView.getX()); float lerpedX = (float) (MathHelper.lerp(p_225606_3_, this.prevPosX, this.posX) - projectedView.getX());
float lerpedY = (float)(MathHelper.lerp(p_225606_3_, this.prevPosY, this.posY) - projectedView.getY()); float lerpedY = (float) (MathHelper.lerp(p_225606_3_, this.prevPosY, this.posY) - projectedView.getY());
float lerpedZ = (float)(MathHelper.lerp(p_225606_3_, this.prevPosZ, this.posZ) - projectedView.getZ()); float lerpedZ = (float) (MathHelper.lerp(p_225606_3_, this.prevPosZ, this.posZ) - projectedView.getZ());
//int light = getBrightnessForRender(p_225606_3_); // int light = getBrightnessForRender(p_225606_3_);
int light = 15728880;//15<<20 && 15<<4 int light = 15728880;// 15<<20 && 15<<4
double ageMultiplier = 1 - Math.pow(age, 3) / Math.pow(maxAge, 3); double ageMultiplier = 1 - Math.pow(age, 3) / Math.pow(maxAge, 3);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
//6 faces to a cube // 6 faces to a cube
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
Vec3d vec = CUBE[i * 4 + j]; Vec3d vec = CUBE[i * 4 + j];
vec = vec vec = vec
/*.rotate(?)*/ /* .rotate(?) */
.scale(scale * ageMultiplier) .scale(scale * ageMultiplier)
.add(lerpedX, lerpedY, lerpedZ); .add(lerpedX, lerpedY, lerpedZ);
Vec3d normal = CUBE_NORMALS[i]; Vec3d normal = CUBE_NORMALS[i];
builder.vertex(vec.x, vec.y, vec.z).color(particleRed, particleGreen, particleBlue, particleAlpha).texture(0,0).light(light).normal((float)normal.x,(float) normal.y,(float) normal.z).endVertex(); builder.vertex(vec.x, vec.y, vec.z)
.color(particleRed, particleGreen, particleBlue, particleAlpha)
.texture(0, 0)
.light(light)
.normal((float) normal.x, (float) normal.y, (float) normal.z)
.endVertex();
} }
} }
} }
@ -136,7 +140,8 @@ public class CubeParticle extends Particle {
public Factory() {} public Factory() {}
@Override @Override
public Particle makeParticle(CubeParticleData data, World world, double x, double y, double z, double motionX, double motionY, double motionZ) { public Particle makeParticle(CubeParticleData data, World world, double x, double y, double z, double motionX,
double motionY, double motionZ) {
CubeParticle particle = new CubeParticle(world, x, y, z, motionX, motionY, motionZ); CubeParticle particle = new CubeParticle(world, x, y, z, motionX, motionY, motionZ);
particle.setColor(data.r, data.g, data.b); particle.setColor(data.r, data.g, data.b);
particle.setScale(data.scale); particle.setScale(data.scale);