Fixed magic shield particles not rendering

This commit is contained in:
Sollace 2021-08-06 01:05:41 +02:00
parent 62dc7ffa1b
commit e132246516
4 changed files with 54 additions and 76 deletions

View file

@ -1,10 +1,12 @@
package com.minelittlepony.unicopia.client.particle;
import com.minelittlepony.unicopia.client.render.RenderLayers;
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import com.minelittlepony.unicopia.util.ColorHelper;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
@ -12,7 +14,7 @@ import net.minecraft.client.world.ClientWorld;
public class DiskParticle extends SphereParticle {
private static final DiskModel model = new DiskModel();
private static final DiskModel MODEL = new DiskModel();
protected float rotX;
protected float rotY;
@ -32,12 +34,23 @@ public class DiskParticle extends SphereParticle {
return;
}
MatrixStack matrices = new MatrixStack();
MODEL.setPosition(x, y, z);
MODEL.setRotation(rotX, rotY, rotZ);
float[] color = ColorHelper.changeSaturation(colorRed, colorGreen, colorBlue, 4);
RenderSystem.setShaderColor(color[0], color[1], color[2], colorAlpha / 3F);
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
model.setPosition(x, y, z);
model.setRotation(rotX, rotY, rotZ);
model.render(matrices, radius, immediate.getBuffer(RenderLayer.getTranslucent()), 1, 1, colorRed, colorGreen, colorBlue, colorAlpha);
VertexConsumer buffer = immediate.getBuffer(RenderLayers.getMagicGlow());
int light = getBrightness(tickDelta);
MatrixStack matrices = new MatrixStack();
MODEL.render(matrices, radius, buffer, 1, light, 1, 1, 1, 1);
immediate.draw();
RenderSystem.setShaderColor(1, 1, 1, 1);
}
}

View file

@ -58,8 +58,8 @@ public class SphereModel {
double radius = 1;
for(double zenith = -pi; zenith < pi; zenith += zenithIncrement) {
for(double azimuth = -two_pi; azimuth < two_pi; azimuth += azimuthIncrement) {
for (double zenith = -pi; zenith < pi; zenith += zenithIncrement) {
for (double azimuth = -two_pi; azimuth < two_pi; azimuth += azimuthIncrement) {
drawQuad(model, vertexWriter, radius, zenith, azimuth, zenithIncrement, azimuthIncrement, light, overlay, r, g, b, a);
}
}

View file

@ -15,6 +15,8 @@ import com.minelittlepony.unicopia.client.render.RenderLayers;
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
import com.minelittlepony.unicopia.particle.ParticleHandle.Link;
import com.minelittlepony.unicopia.util.ColorHelper;
import com.mojang.blaze3d.systems.RenderSystem;
import com.minelittlepony.common.util.Color;
public class SphereParticle extends Particle implements Attachment {
@ -28,7 +30,7 @@ public class SphereParticle extends Particle implements Attachment {
private final Link link = new Link();
private static final SphereModel model = new SphereModel();
private static final SphereModel MODEL = new SphereModel();
public SphereParticle(SphereParticleEffect effect, ClientWorld w, double x, double y, double z, double vX, double vY, double vZ) {
this(effect, w, x, y, z);
@ -42,9 +44,9 @@ public class SphereParticle extends Particle implements Attachment {
super(w, x, y, z);
this.radius = effect.getRadius();
this.colorRed = effect.getRed()/255F;
this.colorGreen = effect.getGreen()/255F;
this.colorBlue = effect.getBlue()/255F;
this.colorRed = effect.getRed() / 255F;
this.colorGreen = effect.getGreen() / 255F;
this.colorBlue = effect.getBlue() / 255F;
this.colorAlpha = effect.getAlpha();
setMaxAge(10);
@ -92,10 +94,10 @@ public class SphereParticle extends Particle implements Attachment {
if (link.linked()) {
link.ifAbsent(this::markDead).map(Caster::getEntity).ifPresent(e -> {
setPos(e.getX(), e.getY(), e.getZ());
setPos(e.getX(), e.getY() + 0.5, e.getZ());
prevPosX = e.lastRenderX;
prevPosY = e.lastRenderY;
prevPosY = e.lastRenderY + 0.5;
prevPosZ = e.lastRenderZ;
});
@ -114,27 +116,34 @@ public class SphereParticle extends Particle implements Attachment {
return;
}
MatrixStack matrices = new MatrixStack();
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
model.setPosition(
MODEL.setPosition(
MathHelper.lerp(tickDelta, prevPosX, x) - camera.getPos().x,
MathHelper.lerp(tickDelta, prevPosY, y) - camera.getPos().y,
MathHelper.lerp(tickDelta, prevPosZ, z) - camera.getPos().z
);
model.setRotation(0, 0, 0);
MODEL.setRotation(0, 0, 0);
float lerpedRad = MathHelper.lerp(tickDelta, prevRadius, radius);
VertexConsumer buffer;
buffer = immediate.getBuffer(RenderLayers.getTintedTexturedLayer(colorRed, colorGreen, colorBlue, colorAlpha));
model.render(matrices, lerpedRad + 0.1F, buffer, 1, 1, colorRed, colorGreen, colorBlue, colorAlpha);
buffer = immediate.getBuffer(RenderLayers.getTintedTexturedLayer(colorRed * 0.9F, colorGreen * 0.9F, colorBlue * 0.9F, Math.min(1, colorAlpha + 0.2F)));
model.render(matrices, lerpedRad - 0.1F, buffer, 1, 1, colorRed * 0.9F, colorGreen * 0.9F, colorBlue * 0.9F, Math.min(1, colorAlpha + 0.2F));
float[] color = ColorHelper.changeSaturation(colorRed, colorGreen, colorBlue, 4);
RenderSystem.setShaderColor(color[0], color[1], color[2], colorAlpha / 3F);
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
VertexConsumer buffer = immediate.getBuffer(RenderLayers.getMagicGlow());
float thickness = 0.05F;
int light = getBrightness(tickDelta);
MatrixStack matrices = new MatrixStack();
MODEL.render(matrices, lerpedRad + thickness, buffer, light, 1, 1, 1, 1, 0.8F);
MODEL.render(matrices, lerpedRad - thickness, buffer, light, 1, 1, 1, 1, 1);
immediate.draw();
prevRadius = radius;
RenderSystem.setShaderColor(1, 1, 1, 1);
}
}

View file

@ -1,11 +1,6 @@
package com.minelittlepony.unicopia.client.render;
import com.mojang.blaze3d.platform.GlStateManager.DstFactor;
import com.mojang.blaze3d.platform.GlStateManager.SrcFactor;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.client.render.VertexFormats;
@ -17,53 +12,14 @@ public final class RenderLayers extends RenderLayer {
super(name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, translucent, startAction, endAction);
}
protected static final RenderPhase.Transparency GLOWING_TRANSPARENCY = new RenderPhase.Transparency("glowing_transparency", () -> {
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(
SrcFactor.CONSTANT_COLOR, DstFactor.ONE,
SrcFactor.ONE, DstFactor.ZERO);
}, () -> {
RenderSystem.disableBlend();
RenderSystem.defaultBlendFunc();
});
private static final RenderLayer MAGIC_GLOW = RenderLayer.of("uni_shield", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL,
VertexFormat.DrawMode.QUADS, 256, true, true, RenderLayer.MultiPhaseParameters.builder()
.shader(COLOR_SHADER)
.transparency(TRANSLUCENT_TRANSPARENCY)
.target(TRANSLUCENT_TARGET)
.build(false));
public static RenderLayer getTintedTexturedLayer(float red, float green, float blue, float alpha) {
return RenderLayer.of("mlp_tint_layer", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, true, true, RenderLayer.MultiPhaseParameters.builder()
.texture(new Color(red, green, blue, alpha))
.shader(EYES_SHADER)
.writeMaskState(COLOR_MASK)
.depthTest(LEQUAL_DEPTH_TEST)
.transparency(GLOWING_TRANSPARENCY)
.lightmap(DISABLE_LIGHTMAP)
.overlay(DISABLE_OVERLAY_COLOR)
.cull(DISABLE_CULLING)
.build(true));
}
private static class Color extends TextureBase {
private final float red;
private final float green;
private final float blue;
private final float alpha;
public Color(float red, float green, float blue, float alpha) {
super(
() -> RenderSystem.setShaderColor(red, green, blue, alpha),
() -> RenderSystem.setShaderColor(1, 1, 1, 1)
);
this.red = red;
this.green = green;
this.blue = blue;
this.alpha = alpha;
}
@Override
public boolean equals(Object other) {
return super.equals(other)
&& ((Color)other).red == red
&& ((Color)other).green == green
&& ((Color)other).blue == blue
&& ((Color)other).alpha == alpha;
}
public static RenderLayer getMagicGlow() {
return MAGIC_GLOW;
}
}