CubeParticle hotfix
- Switched to additive cube particle mode - Fixed cube particles not rendering properly with other entities in frame
This commit is contained in:
parent
257dc11f55
commit
a009540190
1 changed files with 52 additions and 47 deletions
|
@ -1,7 +1,11 @@
|
|||
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.vertex.IVertexBuilder;
|
||||
|
||||
import net.minecraft.client.particle.IParticleFactory;
|
||||
import net.minecraft.client.particle.IParticleRenderType;
|
||||
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.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class CubeParticle extends Particle {
|
||||
|
||||
public static final Vec3d[] CUBE = {
|
||||
// TOP
|
||||
new Vec3d(1, 1, -1), new Vec3d(1, 1, 1), new Vec3d(-1, 1, 1), new Vec3d(-1, 1, -1),
|
||||
// TOP
|
||||
new Vec3d(1, 1, -1), new Vec3d(1, 1, 1), new Vec3d(-1, 1, 1), new Vec3d(-1, 1, -1),
|
||||
|
||||
// BOTTOM
|
||||
new Vec3d(-1, -1, -1), new Vec3d(-1, -1, 1), new Vec3d(1, -1, 1), new Vec3d(1, -1, -1),
|
||||
// BOTTOM
|
||||
new Vec3d(-1, -1, -1), new Vec3d(-1, -1, 1), new Vec3d(1, -1, 1), new Vec3d(1, -1, -1),
|
||||
|
||||
// FRONT
|
||||
new Vec3d(-1, -1, 1), new Vec3d(-1, 1, 1), new Vec3d(1, 1, 1), new Vec3d(1, -1, 1),
|
||||
// FRONT
|
||||
new Vec3d(-1, -1, 1), new Vec3d(-1, 1, 1), new Vec3d(1, 1, 1), new Vec3d(1, -1, 1),
|
||||
|
||||
// BACK
|
||||
new Vec3d(1, -1, -1), new Vec3d(1, 1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, -1, -1),
|
||||
// BACK
|
||||
new Vec3d(1, -1, -1), new Vec3d(1, 1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, -1, -1),
|
||||
|
||||
// LEFT
|
||||
new Vec3d(-1, -1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, 1, 1), new Vec3d(-1, -1, 1),
|
||||
// LEFT
|
||||
new Vec3d(-1, -1, -1), new Vec3d(-1, 1, -1), new Vec3d(-1, 1, 1), new Vec3d(-1, -1, 1),
|
||||
|
||||
// RIGHT
|
||||
new Vec3d(1, -1, 1), new Vec3d(1, 1, 1), new Vec3d(1, 1, -1), new Vec3d(1, -1, -1) };
|
||||
// RIGHT
|
||||
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 = {
|
||||
//modified normals for the sides
|
||||
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, 0, 1),
|
||||
// modified normals for the sides
|
||||
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, 0, 1),
|
||||
|
||||
|
||||
/*new Vec3d(0, 1, 0),
|
||||
new Vec3d(0, -1, 0),
|
||||
new Vec3d(0, 0, 1),
|
||||
new Vec3d(0, 0, -1),
|
||||
new Vec3d(-1, 0, 0),
|
||||
new Vec3d(1, 0, 0)*/
|
||||
/*
|
||||
* new Vec3d(0, 1, 0), new Vec3d(0, -1, 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() {
|
||||
|
@ -59,16 +55,17 @@ public class CubeParticle extends Particle {
|
|||
public void beginRender(BufferBuilder builder, TextureManager textureManager) {
|
||||
RenderSystem.disableTexture();
|
||||
|
||||
//transparent, additive blending
|
||||
//RenderSystem.depthMask(false);
|
||||
//RenderSystem.enableBlend();
|
||||
//RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
||||
//RenderSystem.enableLighting();
|
||||
|
||||
//opaque
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.disableBlend();
|
||||
// transparent, additive blending
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
||||
RenderSystem.enableLighting();
|
||||
RenderSystem.enableColorMaterial();
|
||||
|
||||
// opaque
|
||||
// RenderSystem.depthMask(true);
|
||||
// RenderSystem.disableBlend();
|
||||
// RenderSystem.enableLighting();
|
||||
|
||||
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
}
|
||||
|
@ -76,6 +73,8 @@ public class CubeParticle extends Particle {
|
|||
@Override
|
||||
public void finishRender(Tessellator tessellator) {
|
||||
tessellator.draw();
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA,
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
};
|
||||
|
@ -103,25 +102,30 @@ public class CubeParticle extends Particle {
|
|||
@Override
|
||||
public void buildGeometry(IVertexBuilder builder, ActiveRenderInfo renderInfo, float p_225606_3_) {
|
||||
Vec3d projectedView = renderInfo.getProjectedView();
|
||||
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 lerpedZ = (float)(MathHelper.lerp(p_225606_3_, this.prevPosZ, this.posZ) - projectedView.getZ());
|
||||
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 lerpedZ = (float) (MathHelper.lerp(p_225606_3_, this.prevPosZ, this.posZ) - projectedView.getZ());
|
||||
|
||||
//int light = getBrightnessForRender(p_225606_3_);
|
||||
int light = 15728880;//15<<20 && 15<<4
|
||||
// int light = getBrightnessForRender(p_225606_3_);
|
||||
int light = 15728880;// 15<<20 && 15<<4
|
||||
double ageMultiplier = 1 - Math.pow(age, 3) / Math.pow(maxAge, 3);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
//6 faces to a cube
|
||||
// 6 faces to a cube
|
||||
for (int j = 0; j < 4; j++) {
|
||||
Vec3d vec = CUBE[i * 4 + j];
|
||||
vec = vec
|
||||
/*.rotate(?)*/
|
||||
.scale(scale * ageMultiplier)
|
||||
.add(lerpedX, lerpedY, lerpedZ);
|
||||
/* .rotate(?) */
|
||||
.scale(scale * ageMultiplier)
|
||||
.add(lerpedX, lerpedY, lerpedZ);
|
||||
|
||||
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() {}
|
||||
|
||||
@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);
|
||||
particle.setColor(data.r, data.g, data.b);
|
||||
particle.setScale(data.scale);
|
||||
|
|
Loading…
Reference in a new issue