Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
package foundry.veil.api.client.necromancer.animation.keyframe;

import net.minecraft.util.Mth;
import org.jetbrains.annotations.ApiStatus;
import org.joml.Quaternionf;
import org.joml.Quaternionfc;

// todo: support cubic interpolation w/ derivatives
public enum Interpolation {
NEAREST_NEIGHBOR(
(a, b, t) -> t < 0.5 ? a : b,
(a, b, t, result) -> result.set(t < 0.5 ? a : b)
/**
* @since 4.5.0
*/
STEP(
(a, b, t) -> t < 1F ? a : b,
(a, b, t, result) -> result.set(t < 1 ? a : b)
),
LINEAR(
(a, b, t) -> Mth.lerp(t, a, b),
Quaternionfc::slerp
),
/**
* @since 4.5.0
*/
EASE_IN(
(a, b, t) -> Mth.lerp(t * t, a, b),
(a, b, t, result) -> result.set(a).slerp(b, t * t)
),
/**
* @since 4.5.0
*/
EASE_OUT(
(a, b, t) -> Mth.lerp(1F - (1F - t) * (1F - t), a, b),
(a, b, t, result) -> result.set(a).slerp(b, 1F - (1F - t) * (1F - t))
),
/**
* @since 4.5.0
*/
EASE_IN_OUT(
(a, b, t) -> Mth.lerp(easeInOut(t), a, b),
(a, b, t, result) -> result.set(a).slerp(b, easeInOut(t))
);

/**
* @deprecated Use {@link #STEP} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
@Deprecated
public static final Interpolation NEAREST_NEIGHBOR = STEP;

private static float easeInOut(float t) {
return t < 0.5F ? 2F * t * t : 1F - (float) Math.pow(-2F * t + 2F, 2) / 2F;
}

private final FloatInterpolator fInterpolator;
private final QuaternionInterpolator qInterpolator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ protected float getAdjacentKeyframes(float time, boolean looped, Keyframe[] list
listToPopulate[0] = keyframes[previousIndex];

int nextIndex = currentIndex + 1;
nextIndex = looped ? nextIndex % keyframes.length : Math.max(nextIndex, keyframes.length - 1);
nextIndex = looped ? nextIndex % keyframes.length : Math.min(nextIndex, keyframes.length - 1);
listToPopulate[2] = keyframes[nextIndex];

int nextNextIndex = currentIndex + 2;
nextNextIndex = looped ? nextNextIndex % keyframes.length : Math.max(nextNextIndex, keyframes.length - 1);
nextNextIndex = looped ? nextNextIndex % keyframes.length : Math.min(nextNextIndex, keyframes.length - 1);
listToPopulate[3] = keyframes[nextNextIndex];

// interpolation factor between the two keyframes
Expand All @@ -43,12 +43,11 @@ private int findKeyframeIndex(float time, boolean looped) {
float t1 = keyframes[mid].time();
float t2 = keyframes[mid + 1].time();

// current time is between these two keyframes!
if (time > t1 && time < t2) {
if (time >= t1 && time < t2) {
return mid;
} else if (time > t1) {
low = mid + 1;
} else if (time < t1) {
} else {
high = mid - 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void apply(P parent, S skeleton, float mixFactor, float time) {
Mth.lerp(mixFactor, 1, interpolation.interpolate(a.transform().sz(), b.transform().sz(), t))
);
} else {
bone.size.set(
bone.position.set(
Mth.lerp(mixFactor, bone.position.x, interpolation.interpolate(a.transform().px(), b.transform().px(), t)),
Mth.lerp(mixFactor, bone.position.y, interpolation.interpolate(a.transform().py(), b.transform().py(), t)),
Mth.lerp(mixFactor, bone.position.z, interpolation.interpolate(a.transform().pz(), b.transform().pz(), t))
Expand All @@ -79,16 +79,16 @@ public void apply(P parent, S skeleton, float mixFactor, float time) {
}
}

public static class Builder {
public static class Builder<P extends SkeletonParent<?, ?>, S extends Skeleton> {
boolean looped = false, additive = false;
Map<String, List<Keyframe>> timelines = new HashMap<>();

Builder looped(boolean isLooped) {
public Builder<P, S> looped(boolean isLooped) {
this.looped = isLooped;
return this;
}

Builder additive(boolean isAdditive) {
public Builder<P, S> additive(boolean isAdditive) {
this.additive = isAdditive;
return this;
}
Expand All @@ -104,7 +104,7 @@ public void addKeyframe(String boneId, float time, Interpolation interpolation,
timelines.get(boneId).add(new Keyframe(time, interpolation, new Keyframe.KeyframeTransform(position, size, orientation)));
}

public KeyframedAnimation<?, ?> build() {
public KeyframedAnimation<P, S> build() {
Map<String, KeyframeTimeline> builtTimelines = new HashMap<>();
for (Map.Entry<String, List<Keyframe>> timeline : timelines.entrySet()) {
List<Keyframe> keyframeList = timeline.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import foundry.veil.api.client.render.shader.block.DynamicShaderBlock;
import foundry.veil.api.client.render.vertex.VertexArray;
import foundry.veil.api.client.render.vertex.VertexArrayBuilder;
import foundry.veil.api.compat.ImmersivePortalsCompat;
import it.unimi.dsi.fastutil.floats.FloatList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
Expand All @@ -32,8 +33,7 @@
import java.util.List;

import static org.lwjgl.opengl.ARBDirectStateAccess.glNamedBufferSubData;
import static org.lwjgl.opengl.GL15C.glBindBuffer;
import static org.lwjgl.opengl.GL15C.glBufferSubData;
import static org.lwjgl.opengl.GL15C.*;
import static org.lwjgl.opengl.GL30C.glUniform1ui;
import static org.lwjgl.opengl.GL31C.GL_UNIFORM_BUFFER;

Expand Down Expand Up @@ -120,7 +120,7 @@ public void render(RenderType renderType, List<Matrix4x3f> transforms, List<Skel
}

// Upload data
if (VeilRenderSystem.directStateAccessSupported()) {
if (VeilRenderSystem.directStateAccessSupported() && !ImmersivePortalsCompat.isLoaded()) {
glNamedBufferSubData(boneBuffer, 0, buffer);
} else {
glBindBuffer(GL_UNIFORM_BUFFER, boneBuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import foundry.veil.api.client.render.shader.ShaderPreDefinitions;
import foundry.veil.api.flare.FlareEffectManager;
import foundry.veil.api.quasar.particle.ParticleSystemManager;
import foundry.veil.api.screenshake.ScreenShakeManager;
import foundry.veil.impl.client.render.dynamicbuffer.DynamicBufferManager;
import foundry.veil.impl.client.render.dynamicbuffer.VanillaShaderCompiler;
import foundry.veil.impl.client.render.pipeline.VeilBloomRenderer;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class VeilRenderer implements ResourceManagerReloadListener {
private final EditorManager editorManager;
private final CameraMatrices cameraMatrices;
private final LightRenderer lightRenderer;
private final ScreenShakeManager screenShakeManager;
private final GuiInfo guiInfo;

@ApiStatus.Internal
Expand All @@ -82,6 +84,7 @@ public VeilRenderer(ReloadableResourceManager resourceManager, Window window) {
this.editorManager = new EditorManager(resourceManager);
this.cameraMatrices = new CameraMatrices();
this.lightRenderer = new LightRenderer();
this.screenShakeManager = new ScreenShakeManager();
this.guiInfo = new GuiInfo();

List<PreparableReloadListener> listeners = ((PipelineReloadableResourceManagerAccessor) resourceManager).getListeners();
Expand Down Expand Up @@ -269,6 +272,14 @@ public LightRenderer getLightRenderer() {
return this.lightRenderer;
}

/**
* @return The manager for screen shaking
* @since 4.5.0
*/
public ScreenShakeManager getScreenShakeManager() {
return this.screenShakeManager;
}

/**
* @return The gui info instance
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package foundry.veil.api.client.render.ext;

import foundry.veil.Veil;
import foundry.veil.api.compat.ImmersivePortalsCompat;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.opengl.KHRDebug;
import org.lwjgl.opengl.*;

import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -44,7 +42,9 @@ public void debugMessageInsert(int type, int id, int severity, CharSequence mess
@Override
public void objectLabel(int identifier, int name, @Nullable CharSequence label) {
if (label != null) {
glObjectLabel(identifier, name, label);
if (!ImmersivePortalsCompat.isLoaded()) {
glObjectLabel(identifier, name, label);
}
} else {
nglObjectLabel(identifier, name, 0, 0L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,33 @@ static Builder copy(RenderTarget parent) {
return AdvancedFboImpl.copy(parent);
}

/**
* Gets the attachment type of the main depth buffer.
* @return Either {@code GL_DEPTH_ATTACHMENT} or {@code GL_DEPTH_STENCIL_ATTACHMENT}
* @apiNote If no match is found for whatever reason, {@code GL_DEPTH_ATTACHMENT} is returned.
*/
static int getDepthAttachmentType(int textureId) {
int boundTexture = glGetInteger(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, textureId);

int depthFormat = glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT);

glBindTexture(GL_TEXTURE_2D, boundTexture);

for (FramebufferAttachmentDefinition.Format format : FramebufferAttachmentDefinition.Format.VALUES) {
if (format.getInternalFormat() == depthFormat) {
if (format.getFormat() == GL_DEPTH_COMPONENT) {
return GL_DEPTH_ATTACHMENT;
} else if (format.getFormat() == GL_DEPTH_STENCIL) {
return GL_DEPTH_STENCIL_ATTACHMENT;
}
}
}

return GL_DEPTH_ATTACHMENT;
}

/**
* A builder used to attach buffers to an {@link AdvancedFbo}.
*
Expand Down Expand Up @@ -992,7 +1019,7 @@ public Builder setDepthTextureWrapper(int textureId) {
*/
public Builder setDepthTextureWrapper(int textureId, int layer) {
return this.setDepthBuffer(new AdvancedFboMutableTextureAttachment(
GL_DEPTH_ATTACHMENT,
getDepthAttachmentType(textureId),
textureId,
layer,
this.name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import foundry.veil.api.client.render.framebuffer.AdvancedFbo;
import foundry.veil.api.client.render.light.data.LightData;
import foundry.veil.api.client.render.vertex.VertexArray;
import foundry.veil.api.compat.ImmersivePortalsCompat;
import foundry.veil.impl.client.render.light.VoxelShadowGrid;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -101,7 +102,7 @@ public boolean render(CullFrustum frustum, AdvancedFbo lightFbo, AdvancedFbo lig
lightInscatteringFbo.clear(GL_COLOR_BUFFER_BIT);
}

if (!hasRendered) {
if (!hasRendered && !ImmersivePortalsCompat.isLoaded()) {
renderer.disableBuffers(BUFFER_ID, DynamicBufferType.ALBEDO, DynamicBufferType.NORMAL);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import foundry.veil.api.client.render.VeilRenderSystem;
import foundry.veil.api.client.render.rendertype.VeilRenderType;
import foundry.veil.api.client.render.shader.program.ShaderProgram;
import foundry.veil.api.compat.ImmersivePortalsCompat;
import foundry.veil.impl.client.render.vertex.ARBVertexArray;
import foundry.veil.impl.client.render.vertex.DSAVertexArray;
import foundry.veil.impl.client.render.vertex.LegacyVertexArray;
Expand Down Expand Up @@ -79,7 +80,7 @@ protected VertexArray(int id, Function<VertexArray, VertexArrayBuilder> builder)

private static void loadType() {
if (vertexArrayType == null) {
if (VeilRenderSystem.directStateAccessSupported()) {
if (VeilRenderSystem.directStateAccessSupported() && !ImmersivePortalsCompat.isLoaded()) {
vertexArrayType = VertexArrayType.DSA;
} else {
GLCapabilities caps = GL.getCapabilities();
Expand Down Expand Up @@ -219,7 +220,7 @@ public VertexFormat.Mode getDrawMode() {
* @param usage The draw usage
*/
public static void upload(int buffer, ByteBuffer data, DrawUsage usage) {
if (VeilRenderSystem.directStateAccessSupported()) {
if (VeilRenderSystem.directStateAccessSupported() && !ImmersivePortalsCompat.isLoaded()) {
glNamedBufferData(buffer, data, usage.getGlType());
} else {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package foundry.veil.api.compat;

import com.mojang.blaze3d.shaders.Program;
import foundry.veil.Veil;
import org.jetbrains.annotations.Nullable;

import java.util.ServiceLoader;

public interface ImmersivePortalsCompat {

/**
* Retrieves the compat instance. This will be <code>null</code> if Immersive Portals is not installed.
*/
@Nullable
ImmersivePortalsCompat INSTANCE = (Veil.platform().isModLoaded("immersive_portals") || Veil.platform().isModLoaded("imm_ptl")) ? ServiceLoader.load(ImmersivePortalsCompat.class).findFirst().orElse(null) : null;

/**
* @return Whether Immersive Portals is loaded
*/
static boolean isLoaded() {
return INSTANCE != null;
}

void init();

String transform(Program.Type type, String shaderId, String inputCode);

boolean shouldAddUniform(String shaderName);

boolean renderingThroughPortal();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import net.minecraft.core.Holder;
import net.minecraft.resources.RegistryFileCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.Vector3fc;
import org.joml.*;

public record EmitterShapeSettings(EmitterShape shape,
Vector3fc dimensions,
Expand All @@ -30,6 +29,13 @@ public Vector3d getPos(RandomSource randomSource, Vector3dc pos) {
return this.shape.getPoint(randomSource, this.dimensions, this.rotation, pos, this.fromSurface);
}

/**
* @since 4.5.0
*/
public Vector3d getPos(RandomSource randomSource, Vector3dc pos, Quaternionfc rot) {
return this.shape.getPoint(randomSource, this.dimensions, this.rotation.add(rot.getEulerAnglesXYZ(new Vector3f()).mul(Mth.RAD_TO_DEG), new Vector3f()), pos, this.fromSurface);
}

public @Nullable ResourceLocation getRegistryId() {
return QuasarParticles.registryAccess().registry(QuasarParticles.EMITTER_SHAPE_SETTINGS).map(registry -> registry.getKey(this)).orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import foundry.veil.api.quasar.data.module.init.*;
import foundry.veil.api.quasar.data.module.render.ColorParticleModuleData;
import foundry.veil.api.quasar.data.module.render.TrailParticleModuleData;
import foundry.veil.api.quasar.data.module.update.TickRotationParticleModuleData;
import foundry.veil.api.quasar.data.module.update.TickSizeParticleModuleData;
import foundry.veil.api.quasar.data.module.update.TickSubEmitterModuleData;
import foundry.veil.api.quasar.emitters.module.init.InitRandomRotationModuleData;
Expand Down Expand Up @@ -137,6 +138,10 @@ public class ParticleModuleTypeRegistry {

// UPDATE
public static final ModuleType<TickSizeParticleModuleData> TICK_SIZE = registerModule("size", TickSizeParticleModuleData.CODEC, () -> new TickSizeParticleModuleData(MolangExpression.of(1)));
/**
* @since 4.5.0
*/
public static final ModuleType<TickRotationParticleModuleData> TICK_ROTATION = registerModule("rotation", TickRotationParticleModuleData.CODEC, () -> new TickRotationParticleModuleData(MolangExpression.ZERO, MolangExpression.ZERO, MolangExpression.ZERO));
public static final ModuleType<TickSubEmitterModuleData> TICK_SUB_EMITTER = registerModule("tick_sub_emitter", TickSubEmitterModuleData.CODEC, () -> new TickSubEmitterModuleData(ResourceLocation.withDefaultNamespace(""), 5));
// UPDATE - COLLISION
public static final ModuleType<DieOnCollisionModuleData> DIE_ON_COLLISION = registerModule("die_on_collision", DieOnCollisionModuleData.CODEC, DieOnCollisionModuleData::new);
Expand Down
Loading