Set up a proper render layer for shields

This commit is contained in:
Sollace 2024-01-21 15:17:21 +00:00
parent 7fb9543dbe
commit 3827deb235
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 18 additions and 21 deletions

View file

@ -11,12 +11,9 @@ import com.minelittlepony.unicopia.ability.magic.spell.Spell;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect; import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleHandle; import com.minelittlepony.unicopia.particle.ParticleHandle;
import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.projectile.ProjectileDelegate; import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
import com.minelittlepony.unicopia.util.shape.Sphere; import com.minelittlepony.unicopia.util.shape.Sphere;
@ -113,16 +110,11 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega
return EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.test(entity) && getAttractiveForce(source, entity) > 0; return EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.test(entity) && getAttractiveForce(source, entity) > 0;
} }
@Override
protected void onDestroyed(Caster<?> caster) {
particlEffect.destroy();
}
@Override @Override
public void generateParticles(Caster<?> source) { public void generateParticles(Caster<?> source) {
super.generateParticles(source); super.generateParticles(source);
float radius = (float)getEventHorizonRadius(); /*float radius = (float)getEventHorizonRadius();
particlEffect.update(getUuid(), source, spawner -> { particlEffect.update(getUuid(), source, spawner -> {
spawner.addParticle(new SphereParticleEffect(UParticles.SPHERE, 0x000000, 0.99F, radius, SPHERE_OFFSET), source.getOriginVector(), Vec3d.ZERO); spawner.addParticle(new SphereParticleEffect(UParticles.SPHERE, 0x000000, 0.99F, radius, SPHERE_OFFSET), source.getOriginVector(), Vec3d.ZERO);
@ -134,7 +126,7 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega
spawner.addParticle(new SphereParticleEffect(UParticles.DISK, 0xAAAAAA, 0.4F, radius + 1, SPHERE_OFFSET), getOrigin(source), Vec3d.ZERO); spawner.addParticle(new SphereParticleEffect(UParticles.DISK, 0xAAAAAA, 0.4F, radius + 1, SPHERE_OFFSET), getOrigin(source), Vec3d.ZERO);
}).ifPresent(p -> { }).ifPresent(p -> {
p.setAttribute(Attachment.ATTR_RADIUS, radius * 0F); p.setAttribute(Attachment.ATTR_RADIUS, radius * 0F);
}); });*/
source.spawnParticles(ParticleTypes.SMOKE, 3); source.spawnParticles(ParticleTypes.SMOKE, 3);
} }
@ -185,7 +177,7 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega
// 2. max force (at dist 0) is taken from accumulated mass // 2. max force (at dist 0) is taken from accumulated mass
// 3. force reaches 0 at distance of drawDropOffRange // 3. force reaches 0 at distance of drawDropOffRange
private double getEventHorizonRadius() { public double getEventHorizonRadius() {
return Math.sqrt(Math.max(0.001, getMass() - 12)); return Math.sqrt(Math.max(0.001, getMass() - 12));
} }

View file

@ -39,6 +39,15 @@ public final class RenderLayers extends RenderLayer {
.target(TRANSLUCENT_TARGET) .target(TRANSLUCENT_TARGET)
.build(false)); .build(false));
private static final RenderLayer MAGIC_SHIELD = of("magic_shield", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL,
VertexFormat.DrawMode.QUADS, 256, true, true, MultiPhaseParameters.builder()
.program(COLOR_PROGRAM)
.transparency(TRANSLUCENT_TRANSPARENCY)
.target(TRANSLUCENT_TARGET)
.cull(DISABLE_CULLING)
.writeMaskState(COLOR_MASK)
.build(false));
private static final Function<Integer, RenderLayer> MAGIC_COLORIN_FUNC = Util.memoize(color -> { private static final Function<Integer, RenderLayer> MAGIC_COLORIN_FUNC = Util.memoize(color -> {
return of("magic_colored_" + color, return of("magic_colored_" + color,
VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL,
@ -72,15 +81,11 @@ public final class RenderLayers extends RenderLayer {
} }
public static RenderLayer getMagicNoColor() { public static RenderLayer getMagicNoColor() {
//return MAGIC_NO_COLOR; return MAGIC_NO_COLOR;
return of("magic_no_color", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, }
VertexFormat.DrawMode.QUADS, 256, true, true, MultiPhaseParameters.builder()
.program(COLOR_PROGRAM) public static RenderLayer getMagicShield() {
.transparency(TRANSLUCENT_TRANSPARENCY) return MAGIC_SHIELD;
.target(TRANSLUCENT_TARGET)
.cull(DISABLE_CULLING)
.writeMaskState(COLOR_MASK)
.build(false));
} }
public static RenderLayer getMagicColored() { public static RenderLayer getMagicColored() {

View file

@ -28,7 +28,7 @@ public class ShieldSpellRenderer implements SpellRenderer<ShieldSpell> {
float[] colors = ColorHelper.changeSaturation(Color.r(color), Color.g(color), Color.b(color), 4); float[] colors = ColorHelper.changeSaturation(Color.r(color), Color.g(color), Color.b(color), 4);
float radius = 0.35F + spell.getRadius(tickDelta) + MathHelper.sin(animationProgress / 30F) * 0.01F; float radius = 0.35F + spell.getRadius(tickDelta) + MathHelper.sin(animationProgress / 30F) * 0.01F;
VertexConsumer buffer = vertices.getBuffer(RenderLayers.getMagicNoColor()); VertexConsumer buffer = vertices.getBuffer(RenderLayers.getMagicShield());
float thickness = 0.02F * MathHelper.sin(animationProgress / 30F); float thickness = 0.02F * MathHelper.sin(animationProgress / 30F);
float alpha = 1 - Math.abs(MathHelper.sin(animationProgress / 20F)) * 0.2F; float alpha = 1 - Math.abs(MathHelper.sin(animationProgress / 20F)) * 0.2F;