mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-25 14:14:32 +01:00
Fixed magic shield particles not rendering
This commit is contained in:
parent
62dc7ffa1b
commit
e132246516
4 changed files with 54 additions and 76 deletions
|
@ -1,10 +1,12 @@
|
||||||
package com.minelittlepony.unicopia.client.particle;
|
package com.minelittlepony.unicopia.client.particle;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.client.render.RenderLayers;
|
||||||
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
|
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.MinecraftClient;
|
||||||
import net.minecraft.client.render.Camera;
|
import net.minecraft.client.render.Camera;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
|
||||||
import net.minecraft.client.render.VertexConsumer;
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
import net.minecraft.client.render.VertexConsumerProvider;
|
import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
@ -12,7 +14,7 @@ import net.minecraft.client.world.ClientWorld;
|
||||||
|
|
||||||
public class DiskParticle extends SphereParticle {
|
public class DiskParticle extends SphereParticle {
|
||||||
|
|
||||||
private static final DiskModel model = new DiskModel();
|
private static final DiskModel MODEL = new DiskModel();
|
||||||
|
|
||||||
protected float rotX;
|
protected float rotX;
|
||||||
protected float rotY;
|
protected float rotY;
|
||||||
|
@ -32,12 +34,23 @@ public class DiskParticle extends SphereParticle {
|
||||||
return;
|
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();
|
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||||
model.setPosition(x, y, z);
|
VertexConsumer buffer = immediate.getBuffer(RenderLayers.getMagicGlow());
|
||||||
model.setRotation(rotX, rotY, rotZ);
|
|
||||||
model.render(matrices, radius, immediate.getBuffer(RenderLayer.getTranslucent()), 1, 1, colorRed, colorGreen, colorBlue, colorAlpha);
|
int light = getBrightness(tickDelta);
|
||||||
|
|
||||||
|
MatrixStack matrices = new MatrixStack();
|
||||||
|
MODEL.render(matrices, radius, buffer, 1, light, 1, 1, 1, 1);
|
||||||
|
|
||||||
immediate.draw();
|
immediate.draw();
|
||||||
|
|
||||||
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,8 @@ public class SphereModel {
|
||||||
|
|
||||||
double radius = 1;
|
double radius = 1;
|
||||||
|
|
||||||
for(double zenith = -pi; zenith < pi; zenith += zenithIncrement) {
|
for (double zenith = -pi; zenith < pi; zenith += zenithIncrement) {
|
||||||
for(double azimuth = -two_pi; azimuth < two_pi; azimuth += azimuthIncrement) {
|
for (double azimuth = -two_pi; azimuth < two_pi; azimuth += azimuthIncrement) {
|
||||||
drawQuad(model, vertexWriter, radius, zenith, azimuth, zenithIncrement, azimuthIncrement, light, overlay, r, g, b, a);
|
drawQuad(model, vertexWriter, radius, zenith, azimuth, zenithIncrement, azimuthIncrement, light, overlay, r, g, b, a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import com.minelittlepony.unicopia.client.render.RenderLayers;
|
||||||
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
|
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
|
||||||
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
|
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
|
||||||
import com.minelittlepony.unicopia.particle.ParticleHandle.Link;
|
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;
|
import com.minelittlepony.common.util.Color;
|
||||||
|
|
||||||
public class SphereParticle extends Particle implements Attachment {
|
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 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) {
|
public SphereParticle(SphereParticleEffect effect, ClientWorld w, double x, double y, double z, double vX, double vY, double vZ) {
|
||||||
this(effect, w, x, y, z);
|
this(effect, w, x, y, z);
|
||||||
|
@ -42,9 +44,9 @@ public class SphereParticle extends Particle implements Attachment {
|
||||||
super(w, x, y, z);
|
super(w, x, y, z);
|
||||||
|
|
||||||
this.radius = effect.getRadius();
|
this.radius = effect.getRadius();
|
||||||
this.colorRed = effect.getRed()/255F;
|
this.colorRed = effect.getRed() / 255F;
|
||||||
this.colorGreen = effect.getGreen()/255F;
|
this.colorGreen = effect.getGreen() / 255F;
|
||||||
this.colorBlue = effect.getBlue()/255F;
|
this.colorBlue = effect.getBlue() / 255F;
|
||||||
this.colorAlpha = effect.getAlpha();
|
this.colorAlpha = effect.getAlpha();
|
||||||
|
|
||||||
setMaxAge(10);
|
setMaxAge(10);
|
||||||
|
@ -92,10 +94,10 @@ public class SphereParticle extends Particle implements Attachment {
|
||||||
|
|
||||||
if (link.linked()) {
|
if (link.linked()) {
|
||||||
link.ifAbsent(this::markDead).map(Caster::getEntity).ifPresent(e -> {
|
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;
|
prevPosX = e.lastRenderX;
|
||||||
prevPosY = e.lastRenderY;
|
prevPosY = e.lastRenderY + 0.5;
|
||||||
prevPosZ = e.lastRenderZ;
|
prevPosZ = e.lastRenderZ;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -114,27 +116,34 @@ public class SphereParticle extends Particle implements Attachment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixStack matrices = new MatrixStack();
|
MODEL.setPosition(
|
||||||
|
|
||||||
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
|
||||||
model.setPosition(
|
|
||||||
MathHelper.lerp(tickDelta, prevPosX, x) - camera.getPos().x,
|
MathHelper.lerp(tickDelta, prevPosX, x) - camera.getPos().x,
|
||||||
MathHelper.lerp(tickDelta, prevPosY, y) - camera.getPos().y,
|
MathHelper.lerp(tickDelta, prevPosY, y) - camera.getPos().y,
|
||||||
MathHelper.lerp(tickDelta, prevPosZ, z) - camera.getPos().z
|
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);
|
float lerpedRad = MathHelper.lerp(tickDelta, prevRadius, radius);
|
||||||
|
|
||||||
VertexConsumer buffer;
|
float[] color = ColorHelper.changeSaturation(colorRed, colorGreen, colorBlue, 4);
|
||||||
buffer = immediate.getBuffer(RenderLayers.getTintedTexturedLayer(colorRed, colorGreen, colorBlue, colorAlpha));
|
RenderSystem.setShaderColor(color[0], color[1], color[2], colorAlpha / 3F);
|
||||||
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)));
|
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||||
model.render(matrices, lerpedRad - 0.1F, buffer, 1, 1, colorRed * 0.9F, colorGreen * 0.9F, colorBlue * 0.9F, Math.min(1, colorAlpha + 0.2F));
|
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();
|
immediate.draw();
|
||||||
|
|
||||||
prevRadius = radius;
|
prevRadius = radius;
|
||||||
|
|
||||||
|
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
package com.minelittlepony.unicopia.client.render;
|
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.RenderLayer;
|
||||||
import net.minecraft.client.render.RenderPhase;
|
|
||||||
import net.minecraft.client.render.VertexFormat;
|
import net.minecraft.client.render.VertexFormat;
|
||||||
import net.minecraft.client.render.VertexFormat.DrawMode;
|
import net.minecraft.client.render.VertexFormat.DrawMode;
|
||||||
import net.minecraft.client.render.VertexFormats;
|
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);
|
super(name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, translucent, startAction, endAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final RenderPhase.Transparency GLOWING_TRANSPARENCY = new RenderPhase.Transparency("glowing_transparency", () -> {
|
private static final RenderLayer MAGIC_GLOW = RenderLayer.of("uni_shield", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL,
|
||||||
RenderSystem.enableBlend();
|
VertexFormat.DrawMode.QUADS, 256, true, true, RenderLayer.MultiPhaseParameters.builder()
|
||||||
RenderSystem.blendFuncSeparate(
|
.shader(COLOR_SHADER)
|
||||||
SrcFactor.CONSTANT_COLOR, DstFactor.ONE,
|
.transparency(TRANSLUCENT_TRANSPARENCY)
|
||||||
SrcFactor.ONE, DstFactor.ZERO);
|
.target(TRANSLUCENT_TARGET)
|
||||||
}, () -> {
|
.build(false));
|
||||||
RenderSystem.disableBlend();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
});
|
|
||||||
|
|
||||||
public static RenderLayer getTintedTexturedLayer(float red, float green, float blue, float alpha) {
|
public static RenderLayer getMagicGlow() {
|
||||||
return RenderLayer.of("mlp_tint_layer", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, true, true, RenderLayer.MultiPhaseParameters.builder()
|
return MAGIC_GLOW;
|
||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue