Compare commits

...

12 Commits

Author SHA1 Message Date
4fce67a560 subframe tick interpollation fix 2026-07-09 06:20:51 +04:00
088fb3bb30 gpu optimization done 2026-07-08 22:43:57 +04:00
e2e04fa86f first try 2026-07-08 21:34:37 +04:00
96bce7f38d free moution blur optimization 2026-07-08 18:10:13 +04:00
4e7c027ec0 add motion blur feature 2026-07-08 02:13:44 +04:00
9be1fd8f6b focus gizmo add 2026-07-08 01:16:31 +04:00
0fae99c535 add FOV feature 2026-07-07 06:35:07 +04:00
9f51c59508 DOF polished 2026-07-07 05:04:16 +04:00
6024227716 Update lang submodule 2026-07-02 08:44:23 +04:00
69013c2124 working DOF 2026-07-01 04:48:45 +04:00
3b070a7efc thin lens aproximation mode MVP 2026-06-30 22:14:05 +04:00
646577e97f test worked 2026-06-30 11:44:24 +04:00
24 changed files with 945 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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,9 @@ public class RenderSettings {
private final boolean depthMap;
private final boolean cameraPathExport;
private final AntiAliasing antiAliasing;
private final int lensBlurSamples;
private final int motionBlurSubframes;
private final float shutterAngle;
private final String exportCommand;
// We switched from rgb24 to bgra for performance at one point, so for backwards compatibility we need to
@@ -189,6 +192,9 @@ public class RenderSettings {
false,
false,
RenderSettings.AntiAliasing.NONE,
16,
1,
180f,
"",
RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(),
false
@@ -215,6 +221,9 @@ public class RenderSettings {
boolean depthMap,
boolean cameraPathExport,
AntiAliasing antiAliasing,
int lensBlurSamples,
int motionBlurSubframes,
float shutterAngle,
String exportCommand,
String exportArguments,
boolean highPerformance
@@ -238,6 +247,9 @@ public class RenderSettings {
this.depthMap = depthMap;
this.cameraPathExport = cameraPathExport;
this.antiAliasing = antiAliasing;
this.lensBlurSamples = lensBlurSamples;
this.motionBlurSubframes = motionBlurSubframes;
this.shutterAngle = shutterAngle;
this.exportCommand = exportCommand;
this.exportArguments = exportArguments;
this.highPerformance = highPerformance;
@@ -264,6 +276,9 @@ public class RenderSettings {
depthMap,
cameraPathExport,
antiAliasing,
lensBlurSamples,
motionBlurSubframes,
shutterAngle,
exportCommand,
exportArguments,
highPerformance
@@ -457,6 +472,12 @@ public class RenderSettings {
return antiAliasing;
}
public int getLensBlurSamples() { return lensBlurSamples; }
public int getMotionBlurSubframes() { return motionBlurSubframes; }
public float getShutterAngle() { return shutterAngle; }
public String getExportCommand() {
return exportCommand;
}

View File

@@ -87,6 +87,11 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
}
protected OpenGlFrame renderFrame(int frameId, float partialTicks, D captureData) {
renderWorldOnly(partialTicks, captureData);
return captureFrame(frameId, captureData);
}
protected void renderWorldOnly(float partialTicks, D captureData) {
resizeMainWindow(mc, getFrameWidth(), getFrameHeight());
pushMatrix();
@@ -115,8 +120,6 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
frameBuffer().endWrite();
//#endif
popMatrix();
return captureFrame(frameId, captureData);
}
protected OpenGlFrame captureFrame(int frameId, D captureData) {

View File

@@ -0,0 +1,199 @@
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 com.replaymod.render.RenderSettings;
import com.replaymod.render.utils.ByteBufferPool;
import com.replaymod.render.utils.AccumulationBuffer;
import com.replaymod.replay.ReplayHandler;
import com.replaymod.replay.ReplayModReplay;
import com.replaymod.replaystudio.pathing.path.Timeline;
import com.replaymod.simplepathing.SPTimeline;
import com.replaymod.core.mixin.MinecraftAccessor;
import com.replaymod.pathing.player.ReplayTimer;
import org.apache.commons.lang3.tuple.Triple;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.nio.ByteBuffer;
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
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.0f;
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 static Data singleDiskSample(int i, int n, float focalDistance, float apertureRadius) {
final float GOLDEN_ANGLE = (float) (Math.PI * (3.0 - Math.sqrt(5.0)));
float rr = apertureRadius * (float) Math.sqrt((float) i / n);
float t = i * GOLDEN_ANGLE;
float dx = rr * (float) Math.cos(t);
float dy = rr * (float) Math.sin(t);
float dz = 0f;
Data cam = new Data(dx, dy, dz, 0f, 0f);
float dirX = -dx, dirY = -dy, dirZ = focalDistance - dz;
cam.yaw = (float) -Math.toDegrees(Math.atan2(dirX, dirZ));
cam.pitch = (float) Math.toDegrees(Math.atan2(dirY, Math.sqrt(dirX * dirX + dirZ * dirZ)));
return cam;
}
private final Path positionPath;
private final Timeline timeline;
private final ReplayHandler replayHandler;
private final AccumulationBuffer accum = new AccumulationBuffer();
private long lastConsumedTime = -1;
public RealLensOpenGlFrameCapturer(
WorldRenderer worldRenderer,
RenderInfo renderInfo
) {
super(worldRenderer, renderInfo);
SPTimeline spTimeline = ReplayModSimplePathing.instance.getCurrentTimeline();
this.positionPath = spTimeline.getPositionPath();
this.timeline = spTimeline.getTimeline();
this.replayHandler = ReplayModReplay.instance.getReplayHandler();
}
@Override
public Map<Channel, RealLensOpenGlFrame> process() {
renderInfo.updateForNextFrame();
int frameId = framesDone++;
RenderSettings settings = renderInfo.getRenderSettings();
int fps = settings.getFramesPerSecond();
int N = Math.max(1, settings.getLensBlurSamples());
float shutter = settings.getShutterAngle();
boolean motionBlur = shutter > 0f;
double dt = 1000.0 / fps;
double shutterFrac = motionBlur ? (shutter / 360.0) : 0.0;
int width = getFrameWidth();
int height = getFrameHeight();
// перемешанный апертурный индекс (декорреляция DOF <-> время)
int[] apertureOrder = new int[N];
for (int i = 0; i < N; i++) apertureOrder[i] = i;
for (int i = N - 1; i > 0; i--) {
int j = ThreadLocalRandom.current().nextInt(i + 1);
int tmp = apertureOrder[i]; apertureOrder[i] = apertureOrder[j]; apertureOrder[j] = tmp;
}
accum.begin(width, height); // float-FBO нужного размера + очистка в 0
for (int i = 0; i < N; i++) {
long tSub;
if (motionBlur) {
double u = (i + ThreadLocalRandom.current().nextDouble()) / N; // монотонно вперёд
tSub = (long) (frameId * dt + u * shutterFrac * dt);
timeline.applyToGame(tSub, replayHandler);
} else {
tSub = (long) (frameId * dt);
}
long replayTime = replayHandler.getReplaySender().currentTimeStamp();
if (lastConsumedTime < 0) lastConsumedTime = replayTime;
int pendingTicks = (int) (replayTime / 50L - lastConsumedTime / 50L);
if (pendingTicks > 0) {
ReplayTimer timer = (ReplayTimer) ((MinecraftAccessor) mc).getTimer();
while (pendingTicks-- > 0) {
mc.tick(); // двигает prev/cur частиц через границу тика
timer.tickDelta -= 1f; // компенсация: VideoRenderer не должен тикнуть повторно
}
}
if (replayTime > lastConsumedTime) lastConsumedTime = replayTime;
float subPartialTicks = (float) ((replayTime % 50L) / 50.0);
float focal = positionPath.getValue(LensProperties.FOCAL_DISTANCE, tSub).map(Triple::getLeft).orElse(5.0f);
float apert = positionPath.getValue(LensProperties.APERTURE_RADIUS, tSub).map(Triple::getLeft).orElse(0.05f);
Data cam = singleDiskSample(apertureOrder[i], N, focal, apert);
renderWorldOnly(subPartialTicks, cam); // мир -> главный FBO, без readback
accum.add(frameBuffer().getColorAttachment()); // прибавить на GPU
}
ByteBuffer out = accum.finishAveraged(N); // ОДИН readback + деление на N
accum.unbind(); // вернуться в главный FBO
OpenGlFrame averaged = new OpenGlFrame(frameId, new Dimension(width, height), 4, out);
return Collections.singletonMap(Channel.BRGA, new RealLensOpenGlFrame(new OpenGlFrame[]{ averaged }));
}
@Override
public void close() throws java.io.IOException {
super.close();
accum.close();
}
}

View File

@@ -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;
}
}

View File

@@ -101,6 +101,9 @@ public class GuiExportFailed extends GuiScreen {
oldSettings.isDepthMap(),
oldSettings.isCameraPathExport(),
oldSettings.getAntiAliasing(),
oldSettings.getLensBlurSamples(),
oldSettings.getMotionBlurSubframes(),
oldSettings.getShutterAngle(),
oldSettings.getExportCommand(),
oldSettings.getEncodingPreset().getValue(),
oldSettings.isHighPerformance()

View File

@@ -103,6 +103,9 @@ 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 GuiNumberField motionBlurSubframes = new GuiNumberField().setSize(50, 20).setMinValue(1).setMaxValue(512).setValidateOnFocusChange(true);
public final GuiNumberField shutterAngle = new GuiNumberField().setSize(50, 20).setMinValue(0).setMaxValue(360).setValidateOnFocusChange(true);
public final GuiSlider frameRateSlider = new GuiSlider().onValueChanged(new Runnable() {
@Override
public void run() {
@@ -199,7 +202,9 @@ 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,
new GuiLabel().setI18nText("replaymod.gui.rendersettings.shutterangle"), shutterAngle));
public final GuiTextField exportCommand = new GuiTextField().setI18nHint("replaymod.gui.rendersettings.command")
.setSize(55, 20).setMaxLength(100).onTextChanged((old) -> updateInputs());
@@ -416,6 +421,10 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
boolean commandChanged = !exportCommand.getText().isEmpty();
boolean argsChanged = !encodingPresetDropdown.getSelectedValue().getValue().equals(exportArguments.getText());
exportReset.setEnabled(commandChanged || argsChanged);
boolean isRealLens = renderMethod == RenderSettings.RenderMethod.REALLENS;
lensBlurSamples.setEnabled(isRealLens);
motionBlurSubframes.setEnabled(isRealLens);
shutterAngle.setEnabled(isRealLens);
}
protected String updateResolution() {
@@ -542,6 +551,9 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
depthMap.setChecked(settings.isDepthMap());
cameraPathExport.setChecked(settings.isCameraPathExport());
antiAliasingDropdown.setSelected(settings.getAntiAliasing());
lensBlurSamples.setValue(settings.getLensBlurSamples());
motionBlurSubframes.setValue(settings.getMotionBlurSubframes());
shutterAngle.setValue((int) settings.getShutterAngle());
exportCommand.setText(settings.getExportCommand());
String exportArguments = settings.getExportArguments();
if (exportArguments == null || settings.getEncodingPreset() == null || invalidEncodingPreset) {
@@ -575,6 +587,9 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
depthMap.isChecked() && (serialize || depthMap.isEnabled()),
cameraPathExport.isChecked(),
serialize || antiAliasingDropdown.isEnabled() ? antiAliasingDropdown.getSelectedValue() : RenderSettings.AntiAliasing.NONE,
lensBlurSamples.getInteger(),
motionBlurSubframes.getInteger(),
(float) shutterAngle.getInteger(),
exportCommand.getText(),
exportArguments.getText(),
highPerformance

View File

@@ -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
}

View File

@@ -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
}
}

View File

@@ -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());
}
}
}
}

View File

@@ -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);

View File

@@ -0,0 +1,140 @@
package com.replaymod.render.utils;
//#if MC<12105
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.systems.VertexSorter;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.GameRenderer;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL33;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class AccumulationBuffer {
private int fbo = 0;
private int tex = 0;
private int width = 0;
private int height = 0;
public void begin(int width, int height) {
if (fbo == 0 || width != this.width || height != this.height) {
allocate(width, height);
}
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
GL11.glViewport(0, 0, width, height);
GL11.glClearColor(0f, 0f, 0f, 0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
}
private void allocate(int width, int height) {
close();
this.width = width;
this.height = height;
// Сырые GL-вызовы не обновляют кэш GlStateManager -> сохраняем и
// возвращаем привязки, иначе MC пропустит ребинд (текстура неба и т.п.).
int prevTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
int prevFbo = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING);
tex = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_RGBA32F, width, height, 0,
GL11.GL_RGBA, GL11.GL_FLOAT, (ByteBuffer) null);
fbo = GL30.glGenFramebuffers();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0,
GL11.GL_TEXTURE_2D, tex, 0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, prevTex);
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, prevFbo);
}
public void add(int srcColorTex) {
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
GL11.glViewport(0, 0, width, height);
RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_ONE, GL11.GL_ONE);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
Matrix4f savedProj = RenderSystem.getProjectionMatrix();
VertexSorter savedSorter = RenderSystem.getVertexSorting();
RenderSystem.setProjectionMatrix(new Matrix4f(), VertexSorter.BY_Z);
RenderSystem.getModelViewStack().push();
RenderSystem.getModelViewStack().loadIdentity();
RenderSystem.applyModelViewMatrix();
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderTexture(0, srcColorTex);
int prevTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, srcColorTex);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL33.GL_TEXTURE_SWIZZLE_A, GL11.GL_ONE);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, prevTex);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bb = tessellator.getBuffer();
bb.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE);
bb.vertex(-1f, -1f, 0f).texture(0f, 0f).next();
bb.vertex( 1f, -1f, 0f).texture(1f, 0f).next();
bb.vertex( 1f, 1f, 0f).texture(1f, 1f).next();
bb.vertex(-1f, 1f, 0f).texture(0f, 1f).next();
tessellator.draw();
prevTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, srcColorTex);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL33.GL_TEXTURE_SWIZZLE_A, GL11.GL_ALPHA);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, prevTex);
RenderSystem.getModelViewStack().pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.setProjectionMatrix(savedProj, savedSorter);
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
RenderSystem.enableDepthTest();
RenderSystem.defaultBlendFunc();
}
public ByteBuffer finishAveraged(int samples) {
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
int pixels = width * height;
FloatBuffer fb = org.lwjgl.BufferUtils.createFloatBuffer(pixels * 4);
GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL11.GL_FLOAT, fb);
ByteBuffer out = ByteBufferPool.allocate(pixels * 4);
float inv = 1f / samples;
for (int i = 0; i < pixels * 4; i++) {
float v = fb.get(i) * inv;
int b = (int) (v * 255f + 0.5f);
if (b < 0) b = 0; else if (b > 255) b = 255;
out.put((byte) b);
}
out.rewind();
return out;
}
public void unbind() {
net.minecraft.client.MinecraftClient.getInstance().getFramebuffer().beginWrite(true);
}
public void close() {
if (fbo != 0) { GL30.glDeleteFramebuffers(fbo); fbo = 0; }
if (tex != 0) { GL11.glDeleteTextures(tex); tex = 0; }
}
}
//#else
//$$ // TODO: путь под MC>=12105 (GpuDevice/CommandEncoder) — заполнить позже.
//#endif

View File

@@ -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;

View File

@@ -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));
}
}

View File

@@ -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; }
}

View File

@@ -7,6 +7,8 @@ import com.replaymod.core.versions.MCVer;
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.replay.ReplayHandler;
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
import com.replaymod.replaystudio.pathing.path.Keyframe;
@@ -72,6 +74,8 @@ public class PathPreviewRenderer extends EventRegistrations {
private static final int SLOW_PATH_COLOR = 0xffcccc;
private static final int FAST_PATH_COLOR = 0x660000;
private static final double FASTEST_PATH_SPEED = 0.01;
private static final float DOF_GIZMO_SCALE = 10f;
private static final float DOF_GIZMO_FAR_LEN = 64f;
private final ReplayModSimplePathing mod;
private final ReplayHandler replayHandler;
@@ -209,6 +213,9 @@ public class PathPreviewRenderer extends EventRegistrations {
//#endif
int time = guiPathing.timeline.getCursorPosition();
float focal = path.getValue(LensProperties.FOCAL_DISTANCE, time).map(Triple::getLeft).orElse(LensProperties.DEFAULT_FOCAL_DISTANCE);
float aperture = path.getValue(LensProperties.APERTURE_RADIUS, time).map(Triple::getLeft).orElse(LensProperties.DEFAULT_APERTURE_RADIUS);
float fov = path.getValue(FovProperty.FOV, time).map(Triple::getLeft).orElse(FovProperty.DEFAULT_FOV);
Optional<Integer> entityId = path.getValue(SpectatorProperty.PROPERTY, time);
if (entityId.isPresent()) {
// Spectating an entity
@@ -218,6 +225,7 @@ public class PathPreviewRenderer extends EventRegistrations {
Location loc = entityTracker.getEntityPositionAtTimestamp(entityId.get(), replayTime.get());
if (loc != null) {
drawCamera(viewPos, loc2Vec(loc), new Vector3f(loc.getYaw(), loc.getPitch(), 0f));
drawFocusGizmo(viewPos, loc2Vec(loc), new Vector3f(loc.getYaw(), loc.getPitch(), 0f), focal, aperture, fov);
}
}
}
@@ -227,6 +235,7 @@ public class PathPreviewRenderer extends EventRegistrations {
Optional<Vector3f> cameraRot = path.getValue(CameraProperties.ROTATION, time).map(this::tripleF2Vec);
if (cameraPos.isPresent() && cameraRot.isPresent()) {
drawCamera(viewPos, cameraPos.get(), cameraRot.get());
drawFocusGizmo(viewPos, cameraPos.get(), cameraRot.get(), focal, aperture, fov);
}
}
} finally {
@@ -526,6 +535,100 @@ public class PathPreviewRenderer extends EventRegistrations {
popMatrix();
}
private void drawFocusGizmo(Vector3f view, Vector3f pos, Vector3f rot, float focalDistance, float apertureRadius, float fov) {
float a = Math.max(0.15f, apertureRadius * DOF_GIZMO_SCALE);
int rayColor = 0x66ccffaa; // RGBA: голубой (лучи апертуры)
int markerColor = 0xffaa00ff; // RGBA: оранжевый (маркер плоскости фокуса)
float mr = focalDistance * (float) Math.tan(Math.toRadians(fov) / 2.0); // радиус кольца-маркера
int markerSeg = 12;
pushMatrix();
Vector3f t = Vector3f.sub(pos, view, null);
GL11.glTranslatef(t.x, t.y, t.z);
GL11.glRotatef(-rot.x, 0, 1, 0); // Yaw
GL11.glRotatef(rot.y, 1, 0, 0); // Pitch
GL11.glRotatef(rot.z, 0, 0, 1); // Roll
//#if MC>=12105
//$$ VertexConsumerProvider.Immediate immediate = mc.getBufferBuilders().getEntityVertexConsumers();
//$$ immediate.draw();
//#if MC>=12111
//$$ VertexConsumer buffer = immediate.getBuffer(RenderLayers.LINES);
//#else
//$$ VertexConsumer buffer = immediate.getBuffer(RenderLayer.LINES);
//#endif
//#else
Tessellator tessellator = Tessellator.getInstance();
//#if MC>=12100
//$$ BufferBuilder buffer = tessellator.begin(net.minecraft.client.render.VertexFormat.DrawMode.LINES, VertexFormats.LINES);
//#else
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
//#endif
//#endif
MatrixStack ms = new MatrixStack();
Vector3f apex = new Vector3f(0f, 0f, focalDistance); // точка схождения
for (Vector3f edge : new Vector3f[]{
new Vector3f( a, 0f, 0f), new Vector3f(-a, 0f, 0f),
new Vector3f(0f, a, 0f), new Vector3f(0f, -a, 0f)}) {
Vector3f dir = Vector3f.sub(apex, edge, null); // apex - edge
dir.normalise();
dir.scale(DOF_GIZMO_FAR_LEN);
Vector3f far = Vector3f.add(apex, dir, null);
emitLine(ms, buffer, edge, far, rayColor, 2f);
}
// маркер фокальной плоскости: крестик
emitLine(ms, buffer, new Vector3f(-mr, 0f, focalDistance), new Vector3f(mr, 0f, focalDistance), markerColor, 2f);
emitLine(ms, buffer, new Vector3f(0f, -mr, focalDistance), new Vector3f(0f, mr, focalDistance), markerColor, 2f);
// маркер фокальной плоскости: кольцо
Vector3f prev = null;
for (int i = 0; i <= markerSeg; i++) {
double ang = 2 * Math.PI * i / markerSeg;
Vector3f p = new Vector3f((float) (mr * Math.cos(ang)), (float) (mr * Math.sin(ang)), focalDistance);
if (prev != null) emitLine(ms, buffer, prev, p, markerColor, 2f);
prev = p;
}
//#if MC>=12105
//$$ immediate.draw();
//#else
//#if MC>=12102
//$$ RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
//#elseif MC>=11700
//$$ RenderSystem.applyModelViewMatrix();
//$$ RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
//#else
GL11.glDisable(GL11.GL_TEXTURE_2D);
//#endif
//#if MC>=11700
//$$ RenderSystem.disableCull();
//#endif
//#if MC>=12100
//$$ try (var builtBuffer = buffer.end()) {
//$$ net.minecraft.client.render.BufferRenderer.drawWithGlobalProgram(builtBuffer);
//$$ }
//#else
tessellator.draw();
//#endif
//#if MC>=11700
//$$ RenderSystem.enableCull();
//#endif
//#if MC<11700
GL11.glEnable(GL11.GL_TEXTURE_2D);
//#endif
//#endif
popMatrix();
}
//#if MC>=12105
//$$ private void vertex(VertexConsumer buffer, float x, float y, float z, float u, float v, int alpha) {
//#else

View File

@@ -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",

View File

View File

View File

View File