Compare commits
6 Commits
a4c8dafa07
...
0fae99c535
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fae99c535 | |||
| 9f51c59508 | |||
| 6024227716 | |||
| 69013c2124 | |||
| 3b070a7efc | |||
| 646577e97f |
@@ -12,6 +12,7 @@ import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
@@ -114,6 +115,7 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
|
||||
if (wasAsyncMode) {
|
||||
replayHandler.getReplaySender().setAsyncMode(true);
|
||||
}
|
||||
FovProperty.currentOverride = null;
|
||||
unregister();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.replaymod.pathing.properties;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.replaystudio.pathing.property.AbstractProperty;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyPart;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyParts;
|
||||
import de.johni0702.minecraft.gui.utils.NonNull;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class FovProperty extends AbstractProperty<Triple<Float, Float, Float>> {
|
||||
public static final float DEFAULT_FOV = 70.0f;
|
||||
|
||||
public static volatile Float currentOverride = null;
|
||||
|
||||
public static final FovProperty FOV = new FovProperty("fov", DEFAULT_FOV);
|
||||
|
||||
public final PropertyPart<Triple<Float, Float, Float>> VALUE =
|
||||
new PropertyParts.ForFloatTriple(this, true, PropertyParts.TripleElement.LEFT);
|
||||
|
||||
private FovProperty(String id, float defaultValue) {
|
||||
super(id, "replaymod.gui.editkeyframe." + id, null, Triple.of(defaultValue, 0f, 0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Triple<Float, Float, Float>>> getParts() {
|
||||
return Collections.singletonList(VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Triple<Float, Float, Float> value, @NonNull Object replayHandler) {
|
||||
currentOverride = value.getLeft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Triple<Float, Float, Float> value) throws IOException {
|
||||
writer.value(value.getLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Float, Float, Float> fromJson(JsonReader reader) throws IOException {
|
||||
return Triple.of((float) reader.nextDouble(), 0f, 0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.replaymod.pathing.properties;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.replaystudio.pathing.property.AbstractProperty;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyPart;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyParts;
|
||||
import de.johni0702.minecraft.gui.utils.NonNull;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class LensProperties extends AbstractProperty<Triple<Float, Float, Float>> {
|
||||
public static final float DEFAULT_FOCAL_DISTANCE = 5.0f;
|
||||
public static final float DEFAULT_APERTURE_RADIUS = 0.05f;
|
||||
|
||||
public static final LensProperties FOCAL_DISTANCE = new LensProperties("focalDistance", DEFAULT_FOCAL_DISTANCE);
|
||||
public static final LensProperties APERTURE_RADIUS = new LensProperties("apertureRadius", DEFAULT_APERTURE_RADIUS);
|
||||
|
||||
public final PropertyPart<Triple<Float, Float, Float>> VALUE =
|
||||
new PropertyParts.ForFloatTriple(this, true, PropertyParts.TripleElement.LEFT);
|
||||
|
||||
private LensProperties(String id, float defaultValue) {
|
||||
super(id, "replaymod.gui.editkeyframe." + id, null, Triple.of(defaultValue, 0f, 0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PropertyPart<Triple<Float, Float, Float>>> getParts() {
|
||||
return Collections.singletonList(VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToGame(Triple<Float, Float, Float> value, @NonNull Object replayHandler) {}
|
||||
|
||||
@Override
|
||||
public void toJson(JsonWriter writer, Triple<Float, Float, Float> value) throws IOException {
|
||||
writer.value(value.getLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Float, Float, Float> fromJson(JsonReader reader) throws IOException {
|
||||
return Triple.of((float) reader.nextDouble(), 0f, 0f);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||
|
||||
public class RenderSettings {
|
||||
public enum RenderMethod {
|
||||
DEFAULT, STEREOSCOPIC, CUBIC, EQUIRECTANGULAR, ODS, BLEND;
|
||||
DEFAULT, REALLENS, STEREOSCOPIC, CUBIC, EQUIRECTANGULAR, ODS, BLEND;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -155,6 +155,7 @@ public class RenderSettings {
|
||||
private final boolean depthMap;
|
||||
private final boolean cameraPathExport;
|
||||
private final AntiAliasing antiAliasing;
|
||||
private final int lensBlurSamples;
|
||||
|
||||
private final String exportCommand;
|
||||
// We switched from rgb24 to bgra for performance at one point, so for backwards compatibility we need to
|
||||
@@ -189,6 +190,7 @@ public class RenderSettings {
|
||||
false,
|
||||
false,
|
||||
RenderSettings.AntiAliasing.NONE,
|
||||
16,
|
||||
"",
|
||||
RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(),
|
||||
false
|
||||
@@ -215,6 +217,7 @@ public class RenderSettings {
|
||||
boolean depthMap,
|
||||
boolean cameraPathExport,
|
||||
AntiAliasing antiAliasing,
|
||||
int lensBlurSamples,
|
||||
String exportCommand,
|
||||
String exportArguments,
|
||||
boolean highPerformance
|
||||
@@ -238,6 +241,7 @@ public class RenderSettings {
|
||||
this.depthMap = depthMap;
|
||||
this.cameraPathExport = cameraPathExport;
|
||||
this.antiAliasing = antiAliasing;
|
||||
this.lensBlurSamples = lensBlurSamples;
|
||||
this.exportCommand = exportCommand;
|
||||
this.exportArguments = exportArguments;
|
||||
this.highPerformance = highPerformance;
|
||||
@@ -264,6 +268,7 @@ public class RenderSettings {
|
||||
depthMap,
|
||||
cameraPathExport,
|
||||
antiAliasing,
|
||||
lensBlurSamples,
|
||||
exportCommand,
|
||||
exportArguments,
|
||||
highPerformance
|
||||
@@ -457,6 +462,8 @@ public class RenderSettings {
|
||||
return antiAliasing;
|
||||
}
|
||||
|
||||
public int getLensBlurSamples() { return lensBlurSamples; }
|
||||
|
||||
public String getExportCommand() {
|
||||
return exportCommand;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.replaymod.render.capturer;
|
||||
|
||||
import com.replaymod.render.frame.OpenGlFrame;
|
||||
import com.replaymod.render.frame.RealLensOpenGlFrame;
|
||||
import com.replaymod.render.rendering.Channel;
|
||||
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
||||
import com.replaymod.pathing.properties.LensProperties;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RealLensOpenGlFrameCapturer
|
||||
extends OpenGlFrameCapturer<RealLensOpenGlFrame, RealLensOpenGlFrameCapturer.Data> {
|
||||
|
||||
public static class Data implements CaptureData {
|
||||
|
||||
public float dx, dy, dz;
|
||||
public float yaw, pitch;
|
||||
|
||||
public Data(float dx, float dy, float dz,
|
||||
float yaw, float pitch) {
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
this.dz = dz;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
}
|
||||
|
||||
private static Data[] golden_disk(int n, float r) {
|
||||
|
||||
Data[] points = new Data[n];
|
||||
|
||||
final float GOLDEN_ANGLE = (float) (Math.PI * (3.0 - Math.sqrt(5.0)));
|
||||
|
||||
float random_offset = (float) Math.sqrt(r*r/n) * 0.5f;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
float rr = r * (float) Math.sqrt((float) i / n);
|
||||
float t = i * GOLDEN_ANGLE;
|
||||
points[i] = new Data(
|
||||
rr * (float) Math.cos(t) + (ThreadLocalRandom.current().nextFloat() * 2f - 1f) * random_offset,
|
||||
rr * (float) Math.sin(t) + (ThreadLocalRandom.current().nextFloat() * 2f - 1f) * random_offset,
|
||||
0f, 0f, 0f
|
||||
);
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
private static final float FOCAL_DISTANCE = 5.0f;
|
||||
private static final float APERTURE_RADIUS = 0.05f;
|
||||
private static final int SAMPLES = 64;
|
||||
|
||||
|
||||
|
||||
private static Data[] calculateCameras(float focal_distance, float aperture_radius, int samples) {
|
||||
Data[] cameras = golden_disk(samples, aperture_radius);
|
||||
|
||||
for (Data cam : cameras) {
|
||||
// Направление от смещённой камеры к фокальной точке (0, 0, FOCAL_DISTANCE)
|
||||
float dirX = 0 - cam.dx;
|
||||
float dirY = 0 - cam.dy;
|
||||
float dirZ = focal_distance - cam.dz;
|
||||
|
||||
// Вычисляем yaw и pitch из направления
|
||||
cam.yaw = (float) -Math.toDegrees(Math.atan2(dirX, dirZ));
|
||||
cam.pitch = (float) Math.toDegrees(Math.atan2(dirY, Math.sqrt(dirX*dirX + dirZ*dirZ)));
|
||||
}
|
||||
|
||||
return cameras;
|
||||
}
|
||||
|
||||
private final Path positionPath;
|
||||
|
||||
public RealLensOpenGlFrameCapturer(
|
||||
WorldRenderer worldRenderer,
|
||||
RenderInfo renderInfo
|
||||
) {
|
||||
super(worldRenderer, renderInfo);
|
||||
this.positionPath = ReplayModSimplePathing.instance.getCurrentTimeline().getPositionPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Channel, RealLensOpenGlFrame> process() {
|
||||
float partialTicks = renderInfo.updateForNextFrame();
|
||||
int frameId = framesDone++;
|
||||
|
||||
int fps = renderInfo.getRenderSettings().getFramesPerSecond();
|
||||
long keyframeTime = (long) frameId * 1000 / fps;
|
||||
|
||||
float focalDistance = positionPath.getValue(LensProperties.FOCAL_DISTANCE, keyframeTime).map(Triple::getLeft).orElse(5.0f);
|
||||
float apertureRadius = positionPath.getValue(LensProperties.APERTURE_RADIUS, keyframeTime).map(Triple::getLeft).orElse(0.05f);
|
||||
int samples = renderInfo.getRenderSettings().getLensBlurSamples();
|
||||
|
||||
if (positionPath == null) {
|
||||
System.err.println("positionPath is null!");
|
||||
focalDistance = Float.MAX_VALUE;
|
||||
apertureRadius = 0.01f;
|
||||
}
|
||||
|
||||
Data[] cameras = calculateCameras(focalDistance, apertureRadius, samples);
|
||||
|
||||
OpenGlFrame[] frames = new OpenGlFrame[cameras.length];
|
||||
|
||||
for (int i = 0; i < cameras.length; i++) {
|
||||
frames[i] = renderFrame(frameId, partialTicks, cameras[i]);
|
||||
}
|
||||
|
||||
return Collections.singletonMap(Channel.BRGA, new RealLensOpenGlFrame(frames));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.replaymod.render.frame;
|
||||
|
||||
import com.replaymod.render.rendering.Frame;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
public class RealLensOpenGlFrame implements Frame {
|
||||
|
||||
private final OpenGlFrame[] frames;
|
||||
|
||||
public RealLensOpenGlFrame(OpenGlFrame[] frames) {
|
||||
Validate.notNull(frames, "frames");
|
||||
Validate.isTrue(frames.length > 0, "frames must not be empty");
|
||||
|
||||
int frameId = frames[0].getFrameId();
|
||||
int remaining = frames[0].getByteBuffer().remaining();
|
||||
|
||||
for (OpenGlFrame frame : frames) {
|
||||
Validate.isTrue(
|
||||
frame.getFrameId() == frameId,
|
||||
"Frame ids do not match."
|
||||
);
|
||||
Validate.isTrue(
|
||||
frame.getByteBuffer().remaining() == remaining,
|
||||
"Buffer sizes do not match."
|
||||
);
|
||||
}
|
||||
|
||||
this.frames = frames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrameId() {
|
||||
return frames[0].getFrameId();
|
||||
}
|
||||
|
||||
public OpenGlFrame[] getFrames() {
|
||||
return frames;
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,7 @@ public class GuiExportFailed extends GuiScreen {
|
||||
oldSettings.isDepthMap(),
|
||||
oldSettings.isCameraPathExport(),
|
||||
oldSettings.getAntiAliasing(),
|
||||
oldSettings.getLensBlurSamples(),
|
||||
oldSettings.getExportCommand(),
|
||||
oldSettings.getEncodingPreset().getValue(),
|
||||
oldSettings.isHighPerformance()
|
||||
|
||||
@@ -103,6 +103,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
|
||||
public final GuiNumberField videoWidth = new GuiNumberField().setSize(50, 20).setMinValue(1).setValidateOnFocusChange(true);
|
||||
public final GuiNumberField videoHeight = new GuiNumberField().setSize(50, 20).setMinValue(1).setValidateOnFocusChange(true);
|
||||
public final GuiNumberField lensBlurSamples = new GuiNumberField().setSize(50, 20).setMinValue(1).setMaxValue(512).setValidateOnFocusChange(true);
|
||||
public final GuiSlider frameRateSlider = new GuiSlider().onValueChanged(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -199,7 +200,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
injectSphericalMetadata, sphericalFovSlider,
|
||||
depthMap, new GuiLabel(),
|
||||
cameraPathExport, new GuiLabel(),
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendersettings.antialiasing"), antiAliasingDropdown));
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendersettings.antialiasing"), antiAliasingDropdown,
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendersettings.lensblursamples"), lensBlurSamples));
|
||||
|
||||
public final GuiTextField exportCommand = new GuiTextField().setI18nHint("replaymod.gui.rendersettings.command")
|
||||
.setSize(55, 20).setMaxLength(100).onTextChanged((old) -> updateInputs());
|
||||
@@ -416,6 +418,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
boolean commandChanged = !exportCommand.getText().isEmpty();
|
||||
boolean argsChanged = !encodingPresetDropdown.getSelectedValue().getValue().equals(exportArguments.getText());
|
||||
exportReset.setEnabled(commandChanged || argsChanged);
|
||||
lensBlurSamples.setEnabled(renderMethod == RenderSettings.RenderMethod.REALLENS);
|
||||
}
|
||||
|
||||
protected String updateResolution() {
|
||||
@@ -542,6 +545,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
depthMap.setChecked(settings.isDepthMap());
|
||||
cameraPathExport.setChecked(settings.isCameraPathExport());
|
||||
antiAliasingDropdown.setSelected(settings.getAntiAliasing());
|
||||
lensBlurSamples.setValue(settings.getLensBlurSamples());
|
||||
exportCommand.setText(settings.getExportCommand());
|
||||
String exportArguments = settings.getExportArguments();
|
||||
if (exportArguments == null || settings.getEncodingPreset() == null || invalidEncodingPreset) {
|
||||
@@ -575,6 +579,7 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
depthMap.isChecked() && (serialize || depthMap.isEnabled()),
|
||||
cameraPathExport.isChecked(),
|
||||
serialize || antiAliasingDropdown.isEnabled() ? antiAliasingDropdown.getSelectedValue() : RenderSettings.AntiAliasing.NONE,
|
||||
lensBlurSamples.getInteger(),
|
||||
exportCommand.getText(),
|
||||
exportArguments.getText(),
|
||||
highPerformance
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.replaymod.render.mixin;
|
||||
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public abstract class Mixin_DynamicFov {
|
||||
private static final String METHOD = "getBasicProjectionMatrix";
|
||||
//#if MC>=11903
|
||||
//#if MC>=12005
|
||||
//$$ private static final String TARGET = "Lorg/joml/Matrix4f;perspective(FFFF)Lorg/joml/Matrix4f;";
|
||||
//#else
|
||||
//$$ private static final String TARGET = "Lorg/joml/Matrix4f;setPerspective(FFFF)Lorg/joml/Matrix4f;";
|
||||
//#endif
|
||||
//$$ private static final boolean TARGET_REMAP = false;
|
||||
//#else
|
||||
private static final String TARGET = "Lnet/minecraft/util/math/Matrix4f;viewboxMatrix(DFFF)Lnet/minecraft/util/math/Matrix4f;";
|
||||
private static final boolean TARGET_REMAP = true;
|
||||
//#endif
|
||||
|
||||
@ModifyArg(method = METHOD, at = @At(value = "INVOKE", target = TARGET, remap = TARGET_REMAP), index = 0)
|
||||
//#if MC>=11903
|
||||
//$$ private float replayModRender_dynamicFov(float fovY) {
|
||||
//$$ Float override = FovProperty.currentOverride;
|
||||
//$$ if (override == null) return fovY;
|
||||
//$$ return (float) Math.toRadians(Math.max(1f, Math.min(179f, override)));
|
||||
//$$ }
|
||||
//#else
|
||||
private double replayModRender_dynamicFov(double fovY) {
|
||||
Float override = FovProperty.currentOverride;
|
||||
if (override == null) return fovY;
|
||||
return Math.max(1.0, Math.min(179.0, override));
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.replaymod.render.mixin;
|
||||
|
||||
import com.replaymod.render.capturer.RealLensOpenGlFrameCapturer;
|
||||
import com.replaymod.render.hooks.EntityRendererHandler;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
//#if MC>=12005
|
||||
//$$ import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||
//$$ import org.joml.Matrix4f;
|
||||
//#endif
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public abstract class Mixin_RealLens_Camera implements EntityRendererHandler.IEntityRenderer {
|
||||
|
||||
//#if MC>=12005
|
||||
//#if MC>=12100
|
||||
//$$ @ModifyExpressionValue(method = "renderWorld", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;rotation(Lorg/joml/Quaternionfc;)Lorg/joml/Matrix4f;"))
|
||||
//#else
|
||||
//$$ @ModifyExpressionValue(method = "renderWorld", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;rotationXYZ(FFF)Lorg/joml/Matrix4f;"))
|
||||
//#endif
|
||||
//$$ private Matrix4f realLens_applyCameraTransform(Matrix4f matrix) {
|
||||
//#else
|
||||
@Inject(method = "renderWorld", at = @At("HEAD"))
|
||||
private void realLens_applyCameraTransform(float partialTicks, long frameStartNano, MatrixStack matrixStack, CallbackInfo ci) {
|
||||
//#endif
|
||||
EntityRendererHandler handler = replayModRender_getHandler();
|
||||
if (!(handler != null && handler.data instanceof RealLensOpenGlFrameCapturer.Data)) {
|
||||
//#if MC>=12005
|
||||
//$$ return matrix;
|
||||
//#else
|
||||
return;
|
||||
//#endif
|
||||
}
|
||||
|
||||
RealLensOpenGlFrameCapturer.Data cam = (RealLensOpenGlFrameCapturer.Data) handler.data;
|
||||
|
||||
//#if MC>=12005
|
||||
//$$ matrix.translateLocal(cam.dx, cam.dy, cam.dz);
|
||||
//$$ return matrix;
|
||||
//#else
|
||||
matrixStack.translate(cam.dx, cam.dy, cam.dz);
|
||||
//#endif
|
||||
|
||||
// In Mixin_RealLens_Camera, add rotation after translation
|
||||
//#if MC>=12005
|
||||
//$$ matrix.rotateLocal((float) Math.toRadians(cam.pitch), 1, 0, 0);
|
||||
//$$ matrix.rotateLocal((float) Math.toRadians(cam.yaw), 0, 1, 0);
|
||||
//#else
|
||||
matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(cam.pitch));
|
||||
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(cam.yaw));
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.replaymod.render.processor;
|
||||
|
||||
import com.replaymod.render.frame.BitmapFrame;
|
||||
import com.replaymod.render.frame.OpenGlFrame;
|
||||
import com.replaymod.render.frame.RealLensOpenGlFrame;
|
||||
import com.replaymod.render.utils.ByteBufferPool;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.replaymod.render.utils.Utils.openGlBytesToBitmap;
|
||||
|
||||
public class RealLensToBitmapProcessor
|
||||
extends AbstractFrameProcessor<RealLensOpenGlFrame, BitmapFrame> {
|
||||
|
||||
@Override
|
||||
public BitmapFrame process(RealLensOpenGlFrame rawFrame) {
|
||||
|
||||
OpenGlFrame[] frames = rawFrame.getFrames();
|
||||
OpenGlFrame first = frames[0];
|
||||
|
||||
int width = first.getSize().getWidth();
|
||||
int height = first.getSize().getHeight();
|
||||
int bpp = first.getBytesPerPixel();
|
||||
|
||||
int totalBytes = width * height * bpp;
|
||||
|
||||
int[] accumulator = new int[totalBytes];
|
||||
|
||||
ByteBuffer converted = ByteBufferPool.allocate(totalBytes);
|
||||
|
||||
try {
|
||||
|
||||
for (OpenGlFrame frame : frames) {
|
||||
|
||||
converted.clear();
|
||||
|
||||
// BGRA -> bitmap layout (still BGRA at this point)
|
||||
openGlBytesToBitmap(
|
||||
frame,
|
||||
0,
|
||||
0,
|
||||
converted,
|
||||
width
|
||||
);
|
||||
|
||||
converted.rewind();
|
||||
|
||||
// accumulate per channel with B <-> R swap
|
||||
for (int i = 0; i < totalBytes; i += bpp) {
|
||||
|
||||
int b = converted.get(i) & 0xFF;
|
||||
int g = converted.get(i + 1) & 0xFF;
|
||||
int r = converted.get(i + 2) & 0xFF;
|
||||
int a = (bpp == 4) ? (converted.get(i + 3) & 0xFF) : 255;
|
||||
|
||||
// swap R and B here
|
||||
accumulator[i] += b;
|
||||
accumulator[i + 1] += g;
|
||||
accumulator[i + 2] += r;
|
||||
|
||||
if (bpp == 4) {
|
||||
accumulator[i + 3] += a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuffer output = ByteBufferPool.allocate(totalBytes);
|
||||
|
||||
int samples = frames.length;
|
||||
|
||||
for (int i = 0; i < totalBytes; i += bpp) {
|
||||
|
||||
output.put((byte) (accumulator[i] / samples)); // R
|
||||
output.put((byte) (accumulator[i + 1] / samples)); // G
|
||||
output.put((byte) (accumulator[i + 2] / samples)); // B
|
||||
|
||||
if (bpp == 4) {
|
||||
output.put((byte) (accumulator[i + 3] / samples)); // A
|
||||
}
|
||||
}
|
||||
|
||||
output.rewind();
|
||||
|
||||
return new BitmapFrame(
|
||||
rawFrame.getFrameId(),
|
||||
new Dimension(width, height),
|
||||
bpp,
|
||||
output
|
||||
);
|
||||
|
||||
} finally {
|
||||
|
||||
ByteBufferPool.release(converted);
|
||||
|
||||
for (OpenGlFrame frame : frames) {
|
||||
ByteBufferPool.release(frame.getByteBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,9 @@ import com.replaymod.render.processor.ODSToBitmapProcessor;
|
||||
import com.replaymod.render.processor.OpenGlToBitmapProcessor;
|
||||
import com.replaymod.render.processor.StereoscopicToBitmapProcessor;
|
||||
import com.replaymod.render.utils.PixelBufferObject;
|
||||
import com.replaymod.render.capturer.RealLensOpenGlFrameCapturer;
|
||||
import com.replaymod.render.frame.RealLensOpenGlFrame;
|
||||
import com.replaymod.render.processor.RealLensToBitmapProcessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,6 +35,8 @@ public class Pipelines {
|
||||
switch (method) {
|
||||
case DEFAULT:
|
||||
return newDefaultPipeline(renderInfo, consumer);
|
||||
case REALLENS:
|
||||
return newRealLensPipeline(renderInfo, consumer);
|
||||
case STEREOSCOPIC:
|
||||
return newStereoscopicPipeline(renderInfo, consumer);
|
||||
case CUBIC:
|
||||
@@ -58,6 +63,15 @@ public class Pipelines {
|
||||
return new Pipeline<>(worldRenderer, capturer, new OpenGlToBitmapProcessor(), consumer);
|
||||
}
|
||||
|
||||
public static Pipeline<RealLensOpenGlFrame, BitmapFrame> newRealLensPipeline(
|
||||
RenderInfo renderInfo, FrameConsumer<BitmapFrame> consumer) {
|
||||
RenderSettings settings = renderInfo.getRenderSettings();
|
||||
WorldRenderer worldRenderer = new EntityRendererHandler(settings, renderInfo);
|
||||
FrameCapturer<RealLensOpenGlFrame> capturer =
|
||||
new RealLensOpenGlFrameCapturer(worldRenderer, renderInfo);
|
||||
return new Pipeline<>(worldRenderer, capturer, new RealLensToBitmapProcessor(), consumer);
|
||||
}
|
||||
|
||||
public static Pipeline<StereoscopicOpenGlFrame, BitmapFrame> newStereoscopicPipeline(RenderInfo renderInfo, FrameConsumer<BitmapFrame> consumer) {
|
||||
RenderSettings settings = renderInfo.getRenderSettings();
|
||||
WorldRenderer worldRenderer = new EntityRendererHandler(settings, renderInfo);
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.google.gson.stream.JsonWriter;
|
||||
import com.replaymod.pathing.properties.CameraProperties;
|
||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||
import com.replaymod.pathing.properties.TimestampProperty;
|
||||
import com.replaymod.pathing.properties.LensProperties;
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||
import com.replaymod.replaystudio.pathing.change.AddKeyframe;
|
||||
import com.replaymod.replaystudio.pathing.change.Change;
|
||||
@@ -172,6 +174,9 @@ public class SPTimeline implements PathingRegistry {
|
||||
UpdateKeyframeProperties.Builder builder = UpdateKeyframeProperties.create(path, keyframe);
|
||||
builder.setValue(CameraProperties.POSITION, Triple.of(posX, posY, posZ));
|
||||
builder.setValue(CameraProperties.ROTATION, Triple.of(yaw, pitch, roll));
|
||||
builder.setValue(LensProperties.FOCAL_DISTANCE, Triple.of(LensProperties.DEFAULT_FOCAL_DISTANCE, 0f, 0f));
|
||||
builder.setValue(LensProperties.APERTURE_RADIUS, Triple.of(LensProperties.DEFAULT_APERTURE_RADIUS, 0f, 0f));
|
||||
builder.setValue(FovProperty.FOV, Triple.of(FovProperty.DEFAULT_FOV, 0f, 0f));
|
||||
if (spectated != -1) {
|
||||
builder.setValue(SpectatorProperty.PROPERTY, spectated);
|
||||
}
|
||||
@@ -307,6 +312,28 @@ public class SPTimeline implements PathingRegistry {
|
||||
timeline.pushChange(change);
|
||||
}
|
||||
|
||||
public Change updateLensProperties(long time, float focalDistance, float apertureRadius) {
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exist");
|
||||
|
||||
Change change = UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(LensProperties.FOCAL_DISTANCE, Triple.of(focalDistance, 0f, 0f))
|
||||
.setValue(LensProperties.APERTURE_RADIUS, Triple.of(apertureRadius, 0f, 0f))
|
||||
.done();
|
||||
change.apply(timeline);
|
||||
return change;
|
||||
}
|
||||
|
||||
public Change updateFov(long time, float fov) {
|
||||
Keyframe keyframe = positionPath.getKeyframe(time);
|
||||
Preconditions.checkState(keyframe != null, "Keyframe does not exist");
|
||||
Change change = UpdateKeyframeProperties.create(positionPath, keyframe)
|
||||
.setValue(FovProperty.FOV, Triple.of(fov, 0f, 0f))
|
||||
.done();
|
||||
change.apply(timeline);
|
||||
return change;
|
||||
}
|
||||
|
||||
public Change setInterpolatorToDefault(long time) {
|
||||
LOGGER.debug("Setting interpolator of position keyframe at {} to the default", time);
|
||||
|
||||
@@ -451,6 +478,9 @@ public class SPTimeline implements PathingRegistry {
|
||||
// otherwise create a new interpolator
|
||||
interpolator = new LinearInterpolator();
|
||||
interpolator.registerProperty(SpectatorProperty.PROPERTY);
|
||||
interpolator.registerProperty(LensProperties.FOCAL_DISTANCE);
|
||||
interpolator.registerProperty(LensProperties.APERTURE_RADIUS);
|
||||
interpolator.registerProperty(FovProperty.FOV);
|
||||
}
|
||||
// Now that we have an interpolator, set it for the current segment
|
||||
updates.put(segment, interpolator);
|
||||
@@ -569,6 +599,9 @@ public class SPTimeline implements PathingRegistry {
|
||||
private Interpolator registerPositionInterpolatorProperties(Interpolator interpolator) {
|
||||
interpolator.registerProperty(CameraProperties.POSITION);
|
||||
interpolator.registerProperty(CameraProperties.ROTATION);
|
||||
interpolator.registerProperty(LensProperties.FOCAL_DISTANCE);
|
||||
interpolator.registerProperty(LensProperties.APERTURE_RADIUS);
|
||||
interpolator.registerProperty(FovProperty.FOV);
|
||||
return interpolator;
|
||||
}
|
||||
|
||||
@@ -591,6 +624,9 @@ public class SPTimeline implements PathingRegistry {
|
||||
timeline.registerProperty(CameraProperties.POSITION);
|
||||
timeline.registerProperty(CameraProperties.ROTATION);
|
||||
timeline.registerProperty(SpectatorProperty.PROPERTY);
|
||||
timeline.registerProperty(LensProperties.FOCAL_DISTANCE);
|
||||
timeline.registerProperty(LensProperties.APERTURE_RADIUS);
|
||||
timeline.registerProperty(FovProperty.FOV);
|
||||
timeline.registerProperty(ExplicitInterpolationProperty.PROPERTY);
|
||||
|
||||
return timeline;
|
||||
|
||||
@@ -145,17 +145,24 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
protected abstract Change save();
|
||||
|
||||
public static class Spectator extends GuiEditKeyframe<Spectator> {
|
||||
public final GuiLensKeyframePanel lensPanel = new GuiLensKeyframePanel();
|
||||
|
||||
public Spectator(GuiPathing gui, SPPath path, long keyframe) {
|
||||
super(gui, path, keyframe, "spec");
|
||||
|
||||
link(timeMinField, timeSecField, timeMSecField);
|
||||
inputs.setLayout(new VerticalLayout().setSpacing(10)).addElements(new VerticalLayout.Data(0.5, false), lensPanel.load(this.keyframe));
|
||||
|
||||
link(lensPanel.focalDistanceField, lensPanel.apertureRadiusField, lensPanel.fovField, timeMinField, timeSecField, timeMSecField);
|
||||
|
||||
popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Change save() {
|
||||
return CombinedChange.createFromApplied();
|
||||
SPTimeline timeline = guiPathing.getMod().getCurrentTimeline();
|
||||
Change lensChange = timeline.updateLensProperties(time, lensPanel.getFocalDistance(), lensPanel.getApertureRadius());
|
||||
Change fovChange = timeline.updateFov(time, lensPanel.getFov());
|
||||
return CombinedChange.createFromApplied(lensChange, fovChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,6 +223,8 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
|
||||
public final InterpolationPanel interpolationPanel = new InterpolationPanel();
|
||||
|
||||
public final GuiLensKeyframePanel lensPanel = new GuiLensKeyframePanel();
|
||||
|
||||
{
|
||||
GuiPanel positionInputs = new GuiPanel()
|
||||
.setLayout(new GridLayout().setCellsEqualSize(false).setColumns(4).setSpacingX(3).setSpacingY(5))
|
||||
@@ -225,10 +234,11 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.ypos"), yField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.campitch"), pitchField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.zpos"), zField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.camroll"), rollField);
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.camroll"), rollField
|
||||
);
|
||||
|
||||
inputs.setLayout(new VerticalLayout().setSpacing(10)).addElements(new VerticalLayout.Data(0.5, false),
|
||||
positionInputs, interpolationPanel);
|
||||
positionInputs, lensPanel, interpolationPanel);
|
||||
}
|
||||
|
||||
public Position(GuiPathing gui, SPPath path, long keyframe) {
|
||||
@@ -245,7 +255,9 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
rollField.setValue(rot.getRight());
|
||||
});
|
||||
|
||||
link(xField, yField, zField, yawField, pitchField, rollField, timeMinField, timeSecField, timeMSecField);
|
||||
lensPanel.load(this.keyframe);
|
||||
|
||||
link(xField, yField, zField, yawField, pitchField, rollField, lensPanel.focalDistanceField, lensPanel.apertureRadiusField, lensPanel.fovField, timeMinField, timeSecField, timeMSecField);
|
||||
|
||||
popup.invokeAll(IGuiLabel.class, e -> e.setColor(Colors.BLACK));
|
||||
}
|
||||
@@ -257,16 +269,20 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
||||
xField.getDouble(), yField.getDouble(), zField.getDouble(),
|
||||
yawField.getFloat(), pitchField.getFloat(), rollField.getFloat()
|
||||
);
|
||||
Change lensChange = timeline.updateLensProperties(time,
|
||||
lensPanel.getFocalDistance(), lensPanel.getApertureRadius());
|
||||
Change fovChange = timeline.updateFov(time, lensPanel.getFov());
|
||||
if (interpolationPanel.getSettingsPanel() == null) {
|
||||
// The last keyframe doesn't have interpolator settings because there is no segment following it
|
||||
return positionChange;
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange, fovChange);
|
||||
}
|
||||
Interpolator interpolator = interpolationPanel.getSettingsPanel().createInterpolator();
|
||||
if (interpolationPanel.getInterpolatorType() == InterpolatorType.DEFAULT) {
|
||||
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolatorToDefault(time),
|
||||
timeline.setDefaultInterpolator(interpolator));
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange, fovChange,
|
||||
timeline.setInterpolatorToDefault(time), timeline.setDefaultInterpolator(interpolator));
|
||||
} else {
|
||||
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolator(time, interpolator));
|
||||
return CombinedChange.createFromApplied(positionChange, lensChange, fovChange,
|
||||
timeline.setInterpolator(time, interpolator));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.replaymod.simplepathing.gui;
|
||||
|
||||
import com.replaymod.pathing.properties.LensProperties;
|
||||
import com.replaymod.pathing.properties.FovProperty;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiNumberField;
|
||||
import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
public class GuiLensKeyframePanel extends AbstractGuiContainer<GuiLensKeyframePanel> {
|
||||
public final GuiNumberField focalDistanceField =
|
||||
new GuiNumberField().setValidateOnFocusChange(true).setSize(60, 20).setPrecision(3).setMinValue(0);
|
||||
public final GuiNumberField apertureRadiusField =
|
||||
new GuiNumberField().setValidateOnFocusChange(true).setSize(60, 20).setPrecision(4).setMinValue(0);
|
||||
public final GuiNumberField fovField =
|
||||
new GuiNumberField().setValidateOnFocusChange(true).setSize(60, 20).setPrecision(1).setMinValue(1).setMaxValue(179);
|
||||
|
||||
public GuiLensKeyframePanel() {
|
||||
setLayout(new GridLayout().setCellsEqualSize(false).setColumns(2).setSpacingX(3).setSpacingY(5));
|
||||
addElements(new GridLayout.Data(1, 0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.focalDistance"), focalDistanceField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.apertureRadius"), apertureRadiusField,
|
||||
new GuiLabel().setI18nText("replaymod.gui.editkeyframe.fov"), fovField);
|
||||
}
|
||||
|
||||
public GuiLensKeyframePanel load(Keyframe keyframe) {
|
||||
focalDistanceField.setValue(keyframe.getValue(LensProperties.FOCAL_DISTANCE)
|
||||
.map(Triple::getLeft).orElse(LensProperties.DEFAULT_FOCAL_DISTANCE));
|
||||
apertureRadiusField.setValue(keyframe.getValue(LensProperties.APERTURE_RADIUS)
|
||||
.map(Triple::getLeft).orElse(LensProperties.DEFAULT_APERTURE_RADIUS));
|
||||
fovField.setValue(keyframe.getValue(FovProperty.FOV)
|
||||
.map(Triple::getLeft).orElse(FovProperty.DEFAULT_FOV));
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFocalDistance() { return focalDistanceField.getFloat(); }
|
||||
public float getApertureRadius() { return apertureRadiusField.getFloat(); }
|
||||
public float getFov() { return fovField.getFloat(); }
|
||||
|
||||
@Override
|
||||
protected GuiLensKeyframePanel getThis() { return this; }
|
||||
}
|
||||
Submodule src/main/resources/assets/replaymod/lang updated: ed16d95cd3...9d5205f920
@@ -31,10 +31,12 @@
|
||||
"Mixin_SkipBlockOutlinesDuringRender",
|
||||
"Mixin_SkipHudDuringRender",
|
||||
"Mixin_StabilizeCamera",
|
||||
"Mixin_RealLens_Camera",
|
||||
"Mixin_Stereoscopic_Camera",
|
||||
"Mixin_Stereoscopic_HandRenderPass",
|
||||
"Mixin_SuppressFramebufferResizeDuringRender",
|
||||
"Mixin_UseGuiFramebufferDuringGuiRendering",
|
||||
"Mixin_DynamicFov",
|
||||
//#if MC>=11600
|
||||
"Mixin_AddIrisOdsShaderUniforms",
|
||||
"Mixin_LoadIrisOdsShaderPack",
|
||||
|
||||
0
versions/1.20.1/logs/latest.log
Normal file
0
versions/1.20.1/logs/latest.log
Normal file
0
versions/1.20.4/logs/latest.log
Normal file
0
versions/1.20.4/logs/latest.log
Normal file
0
versions/1.21.11/logs/latest.log
Normal file
0
versions/1.21.11/logs/latest.log
Normal file
0
versions/26.1/logs/latest.log
Normal file
0
versions/26.1/logs/latest.log
Normal file
Reference in New Issue
Block a user