Compare commits
3 Commits
0fae99c535
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
| 96bce7f38d | |||
| 4e7c027ec0 | |||
| 9be1fd8f6b |
@@ -156,6 +156,8 @@ public class RenderSettings {
|
|||||||
private final boolean cameraPathExport;
|
private final boolean cameraPathExport;
|
||||||
private final AntiAliasing antiAliasing;
|
private final AntiAliasing antiAliasing;
|
||||||
private final int lensBlurSamples;
|
private final int lensBlurSamples;
|
||||||
|
private final int motionBlurSubframes;
|
||||||
|
private final float shutterAngle;
|
||||||
|
|
||||||
private final String exportCommand;
|
private final String exportCommand;
|
||||||
// We switched from rgb24 to bgra for performance at one point, so for backwards compatibility we need to
|
// We switched from rgb24 to bgra for performance at one point, so for backwards compatibility we need to
|
||||||
@@ -191,6 +193,8 @@ public class RenderSettings {
|
|||||||
false,
|
false,
|
||||||
RenderSettings.AntiAliasing.NONE,
|
RenderSettings.AntiAliasing.NONE,
|
||||||
16,
|
16,
|
||||||
|
1,
|
||||||
|
180f,
|
||||||
"",
|
"",
|
||||||
RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(),
|
RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(),
|
||||||
false
|
false
|
||||||
@@ -218,6 +222,8 @@ public class RenderSettings {
|
|||||||
boolean cameraPathExport,
|
boolean cameraPathExport,
|
||||||
AntiAliasing antiAliasing,
|
AntiAliasing antiAliasing,
|
||||||
int lensBlurSamples,
|
int lensBlurSamples,
|
||||||
|
int motionBlurSubframes,
|
||||||
|
float shutterAngle,
|
||||||
String exportCommand,
|
String exportCommand,
|
||||||
String exportArguments,
|
String exportArguments,
|
||||||
boolean highPerformance
|
boolean highPerformance
|
||||||
@@ -242,6 +248,8 @@ public class RenderSettings {
|
|||||||
this.cameraPathExport = cameraPathExport;
|
this.cameraPathExport = cameraPathExport;
|
||||||
this.antiAliasing = antiAliasing;
|
this.antiAliasing = antiAliasing;
|
||||||
this.lensBlurSamples = lensBlurSamples;
|
this.lensBlurSamples = lensBlurSamples;
|
||||||
|
this.motionBlurSubframes = motionBlurSubframes;
|
||||||
|
this.shutterAngle = shutterAngle;
|
||||||
this.exportCommand = exportCommand;
|
this.exportCommand = exportCommand;
|
||||||
this.exportArguments = exportArguments;
|
this.exportArguments = exportArguments;
|
||||||
this.highPerformance = highPerformance;
|
this.highPerformance = highPerformance;
|
||||||
@@ -269,6 +277,8 @@ public class RenderSettings {
|
|||||||
cameraPathExport,
|
cameraPathExport,
|
||||||
antiAliasing,
|
antiAliasing,
|
||||||
lensBlurSamples,
|
lensBlurSamples,
|
||||||
|
motionBlurSubframes,
|
||||||
|
shutterAngle,
|
||||||
exportCommand,
|
exportCommand,
|
||||||
exportArguments,
|
exportArguments,
|
||||||
highPerformance
|
highPerformance
|
||||||
@@ -464,6 +474,10 @@ public class RenderSettings {
|
|||||||
|
|
||||||
public int getLensBlurSamples() { return lensBlurSamples; }
|
public int getLensBlurSamples() { return lensBlurSamples; }
|
||||||
|
|
||||||
|
public int getMotionBlurSubframes() { return motionBlurSubframes; }
|
||||||
|
|
||||||
|
public float getShutterAngle() { return shutterAngle; }
|
||||||
|
|
||||||
public String getExportCommand() {
|
public String getExportCommand() {
|
||||||
return exportCommand;
|
return exportCommand;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ import com.replaymod.replaystudio.pathing.path.Path;
|
|||||||
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
||||||
import com.replaymod.pathing.properties.LensProperties;
|
import com.replaymod.pathing.properties.LensProperties;
|
||||||
|
|
||||||
|
import com.replaymod.render.RenderSettings;
|
||||||
|
import com.replaymod.render.utils.ByteBufferPool;
|
||||||
|
import com.replaymod.replay.ReplayHandler;
|
||||||
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
|
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||||
|
import com.replaymod.simplepathing.SPTimeline;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -15,6 +22,10 @@ import java.util.Map;
|
|||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||||
|
|
||||||
public class RealLensOpenGlFrameCapturer
|
public class RealLensOpenGlFrameCapturer
|
||||||
extends OpenGlFrameCapturer<RealLensOpenGlFrame, RealLensOpenGlFrameCapturer.Data> {
|
extends OpenGlFrameCapturer<RealLensOpenGlFrame, RealLensOpenGlFrameCapturer.Data> {
|
||||||
|
|
||||||
@@ -39,7 +50,7 @@ public class RealLensOpenGlFrameCapturer
|
|||||||
|
|
||||||
final float GOLDEN_ANGLE = (float) (Math.PI * (3.0 - Math.sqrt(5.0)));
|
final float GOLDEN_ANGLE = (float) (Math.PI * (3.0 - Math.sqrt(5.0)));
|
||||||
|
|
||||||
float random_offset = (float) Math.sqrt(r*r/n) * 0.5f;
|
float random_offset = (float) Math.sqrt(r*r/n) * 0.0f;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
float rr = r * (float) Math.sqrt((float) i / n);
|
float rr = r * (float) Math.sqrt((float) i / n);
|
||||||
@@ -77,42 +88,107 @@ public class RealLensOpenGlFrameCapturer
|
|||||||
return cameras;
|
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 Path positionPath;
|
||||||
|
private final Timeline timeline;
|
||||||
|
private final ReplayHandler replayHandler;
|
||||||
|
|
||||||
public RealLensOpenGlFrameCapturer(
|
public RealLensOpenGlFrameCapturer(
|
||||||
WorldRenderer worldRenderer,
|
WorldRenderer worldRenderer,
|
||||||
RenderInfo renderInfo
|
RenderInfo renderInfo
|
||||||
) {
|
) {
|
||||||
super(worldRenderer, renderInfo);
|
super(worldRenderer, renderInfo);
|
||||||
this.positionPath = ReplayModSimplePathing.instance.getCurrentTimeline().getPositionPath();
|
SPTimeline spTimeline = ReplayModSimplePathing.instance.getCurrentTimeline();
|
||||||
|
this.positionPath = spTimeline.getPositionPath();
|
||||||
|
this.timeline = spTimeline.getTimeline();
|
||||||
|
this.replayHandler = ReplayModReplay.instance.getReplayHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Channel, RealLensOpenGlFrame> process() {
|
public Map<Channel, RealLensOpenGlFrame> process() {
|
||||||
float partialTicks = renderInfo.updateForNextFrame();
|
// Продвигает состояние игры к времени ТЕКУЩЕГО выходного кадра
|
||||||
|
// (через onTick -> timeline.applyToGame(videoTime)).
|
||||||
|
renderInfo.updateForNextFrame();
|
||||||
int frameId = framesDone++;
|
int frameId = framesDone++;
|
||||||
|
|
||||||
int fps = renderInfo.getRenderSettings().getFramesPerSecond();
|
RenderSettings settings = renderInfo.getRenderSettings();
|
||||||
long keyframeTime = (long) frameId * 1000 / fps;
|
int fps = settings.getFramesPerSecond();
|
||||||
|
int N = Math.max(1, settings.getLensBlurSamples()); // единый бюджет сэмплов
|
||||||
|
float shutter = settings.getShutterAngle(); // градусы
|
||||||
|
|
||||||
float focalDistance = positionPath.getValue(LensProperties.FOCAL_DISTANCE, keyframeTime).map(Triple::getLeft).orElse(5.0f);
|
boolean motionBlur = shutter > 0f;
|
||||||
float apertureRadius = positionPath.getValue(LensProperties.APERTURE_RADIUS, keyframeTime).map(Triple::getLeft).orElse(0.05f);
|
double dt = 1000.0 / fps; // длительность выходного кадра, мс
|
||||||
int samples = renderInfo.getRenderSettings().getLensBlurSamples();
|
double shutterFrac = motionBlur ? (shutter / 360.0) : 0.0;
|
||||||
|
|
||||||
if (positionPath == null) {
|
int width = getFrameWidth();
|
||||||
System.err.println("positionPath is null!");
|
int height = getFrameHeight();
|
||||||
focalDistance = Float.MAX_VALUE;
|
int bpp = 4;
|
||||||
apertureRadius = 0.01f;
|
int totalBytes = width * height * bpp;
|
||||||
|
|
||||||
|
long[] accumulator = new long[totalBytes];
|
||||||
|
|
||||||
|
// перемешанные слои времени, чтобы время не коррелировало с индексом апертурной спирали
|
||||||
|
int[] order = new int[N];
|
||||||
|
for (int i = 0; i < N; i++) order[i] = i;
|
||||||
|
for (int i = N - 1; i > 0; i--) { // Fisher-Yates
|
||||||
|
int j = ThreadLocalRandom.current().nextInt(i + 1);
|
||||||
|
int tmp = order[i];
|
||||||
|
order[i] = order[j];
|
||||||
|
order[j] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Data[] cameras = calculateCameras(focalDistance, apertureRadius, samples);
|
for (int i = 0; i < N; i++) {
|
||||||
|
// --- время: 1 стратифицированный джиттернутый сэмпл на слой ---
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
// partialTicks от РЕАЛЬНОГО времени реплея (frac(replayTime/50)),
|
||||||
|
// как в AbstractTimelinePlayer.onTick. (tSub % 50) даёт рассинхрон -> раздвоение.
|
||||||
|
long replayTime = replayHandler.getReplaySender().currentTimeStamp();
|
||||||
|
float subPartialTicks = (float) ((replayTime % 50L) / 50.0);
|
||||||
|
|
||||||
OpenGlFrame[] frames = new OpenGlFrame[cameras.length];
|
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(order[i], N, focal, apert);
|
||||||
|
|
||||||
for (int i = 0; i < cameras.length; i++) {
|
OpenGlFrame sub = renderFrame(frameId, subPartialTicks, cam);
|
||||||
frames[i] = renderFrame(frameId, partialTicks, cameras[i]);
|
ByteBuffer buf = sub.getByteBuffer();
|
||||||
|
buf.rewind();
|
||||||
|
for (int k = 0; k < totalBytes; k++) {
|
||||||
|
accumulator[k] += (buf.get(k) & 0xFF);
|
||||||
|
}
|
||||||
|
ByteBufferPool.release(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.singletonMap(Channel.BRGA, new RealLensOpenGlFrame(frames));
|
ByteBuffer out = ByteBufferPool.allocate(totalBytes);
|
||||||
|
for (int k = 0; k < totalBytes; k++) {
|
||||||
|
out.put((byte) (accumulator[k] / N));
|
||||||
|
}
|
||||||
|
out.rewind();
|
||||||
|
|
||||||
|
OpenGlFrame averaged = new OpenGlFrame(frameId, new Dimension(width, height), bpp, out);
|
||||||
|
return Collections.singletonMap(Channel.BRGA, new RealLensOpenGlFrame(new OpenGlFrame[]{averaged}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,6 +102,8 @@ public class GuiExportFailed extends GuiScreen {
|
|||||||
oldSettings.isCameraPathExport(),
|
oldSettings.isCameraPathExport(),
|
||||||
oldSettings.getAntiAliasing(),
|
oldSettings.getAntiAliasing(),
|
||||||
oldSettings.getLensBlurSamples(),
|
oldSettings.getLensBlurSamples(),
|
||||||
|
oldSettings.getMotionBlurSubframes(),
|
||||||
|
oldSettings.getShutterAngle(),
|
||||||
oldSettings.getExportCommand(),
|
oldSettings.getExportCommand(),
|
||||||
oldSettings.getEncodingPreset().getValue(),
|
oldSettings.getEncodingPreset().getValue(),
|
||||||
oldSettings.isHighPerformance()
|
oldSettings.isHighPerformance()
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
public final GuiNumberField videoWidth = new GuiNumberField().setSize(50, 20).setMinValue(1).setValidateOnFocusChange(true);
|
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 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 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() {
|
public final GuiSlider frameRateSlider = new GuiSlider().onValueChanged(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -201,7 +203,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
depthMap, new GuiLabel(),
|
depthMap, new GuiLabel(),
|
||||||
cameraPathExport, 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.lensblursamples"), lensBlurSamples,
|
||||||
|
new GuiLabel().setI18nText("replaymod.gui.rendersettings.shutterangle"), shutterAngle));
|
||||||
|
|
||||||
public final GuiTextField exportCommand = new GuiTextField().setI18nHint("replaymod.gui.rendersettings.command")
|
public final GuiTextField exportCommand = new GuiTextField().setI18nHint("replaymod.gui.rendersettings.command")
|
||||||
.setSize(55, 20).setMaxLength(100).onTextChanged((old) -> updateInputs());
|
.setSize(55, 20).setMaxLength(100).onTextChanged((old) -> updateInputs());
|
||||||
@@ -418,7 +421,10 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
boolean commandChanged = !exportCommand.getText().isEmpty();
|
boolean commandChanged = !exportCommand.getText().isEmpty();
|
||||||
boolean argsChanged = !encodingPresetDropdown.getSelectedValue().getValue().equals(exportArguments.getText());
|
boolean argsChanged = !encodingPresetDropdown.getSelectedValue().getValue().equals(exportArguments.getText());
|
||||||
exportReset.setEnabled(commandChanged || argsChanged);
|
exportReset.setEnabled(commandChanged || argsChanged);
|
||||||
lensBlurSamples.setEnabled(renderMethod == RenderSettings.RenderMethod.REALLENS);
|
boolean isRealLens = renderMethod == RenderSettings.RenderMethod.REALLENS;
|
||||||
|
lensBlurSamples.setEnabled(isRealLens);
|
||||||
|
motionBlurSubframes.setEnabled(isRealLens);
|
||||||
|
shutterAngle.setEnabled(isRealLens);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String updateResolution() {
|
protected String updateResolution() {
|
||||||
@@ -546,6 +552,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
cameraPathExport.setChecked(settings.isCameraPathExport());
|
cameraPathExport.setChecked(settings.isCameraPathExport());
|
||||||
antiAliasingDropdown.setSelected(settings.getAntiAliasing());
|
antiAliasingDropdown.setSelected(settings.getAntiAliasing());
|
||||||
lensBlurSamples.setValue(settings.getLensBlurSamples());
|
lensBlurSamples.setValue(settings.getLensBlurSamples());
|
||||||
|
motionBlurSubframes.setValue(settings.getMotionBlurSubframes());
|
||||||
|
shutterAngle.setValue((int) settings.getShutterAngle());
|
||||||
exportCommand.setText(settings.getExportCommand());
|
exportCommand.setText(settings.getExportCommand());
|
||||||
String exportArguments = settings.getExportArguments();
|
String exportArguments = settings.getExportArguments();
|
||||||
if (exportArguments == null || settings.getEncodingPreset() == null || invalidEncodingPreset) {
|
if (exportArguments == null || settings.getEncodingPreset() == null || invalidEncodingPreset) {
|
||||||
@@ -580,6 +588,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
|||||||
cameraPathExport.isChecked(),
|
cameraPathExport.isChecked(),
|
||||||
serialize || antiAliasingDropdown.isEnabled() ? antiAliasingDropdown.getSelectedValue() : RenderSettings.AntiAliasing.NONE,
|
serialize || antiAliasingDropdown.isEnabled() ? antiAliasingDropdown.getSelectedValue() : RenderSettings.AntiAliasing.NONE,
|
||||||
lensBlurSamples.getInteger(),
|
lensBlurSamples.getInteger(),
|
||||||
|
motionBlurSubframes.getInteger(),
|
||||||
|
(float) shutterAngle.getInteger(),
|
||||||
exportCommand.getText(),
|
exportCommand.getText(),
|
||||||
exportArguments.getText(),
|
exportArguments.getText(),
|
||||||
highPerformance
|
highPerformance
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import com.replaymod.core.versions.MCVer;
|
|||||||
import com.replaymod.pathing.properties.CameraProperties;
|
import com.replaymod.pathing.properties.CameraProperties;
|
||||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||||
import com.replaymod.pathing.properties.TimestampProperty;
|
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.replay.ReplayHandler;
|
||||||
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
import com.replaymod.replaystudio.pathing.interpolation.Interpolator;
|
||||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
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 SLOW_PATH_COLOR = 0xffcccc;
|
||||||
private static final int FAST_PATH_COLOR = 0x660000;
|
private static final int FAST_PATH_COLOR = 0x660000;
|
||||||
private static final double FASTEST_PATH_SPEED = 0.01;
|
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 ReplayModSimplePathing mod;
|
||||||
private final ReplayHandler replayHandler;
|
private final ReplayHandler replayHandler;
|
||||||
@@ -209,6 +213,9 @@ public class PathPreviewRenderer extends EventRegistrations {
|
|||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
int time = guiPathing.timeline.getCursorPosition();
|
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);
|
Optional<Integer> entityId = path.getValue(SpectatorProperty.PROPERTY, time);
|
||||||
if (entityId.isPresent()) {
|
if (entityId.isPresent()) {
|
||||||
// Spectating an entity
|
// Spectating an entity
|
||||||
@@ -218,6 +225,7 @@ public class PathPreviewRenderer extends EventRegistrations {
|
|||||||
Location loc = entityTracker.getEntityPositionAtTimestamp(entityId.get(), replayTime.get());
|
Location loc = entityTracker.getEntityPositionAtTimestamp(entityId.get(), replayTime.get());
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
drawCamera(viewPos, loc2Vec(loc), new Vector3f(loc.getYaw(), loc.getPitch(), 0f));
|
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);
|
Optional<Vector3f> cameraRot = path.getValue(CameraProperties.ROTATION, time).map(this::tripleF2Vec);
|
||||||
if (cameraPos.isPresent() && cameraRot.isPresent()) {
|
if (cameraPos.isPresent() && cameraRot.isPresent()) {
|
||||||
drawCamera(viewPos, cameraPos.get(), cameraRot.get());
|
drawCamera(viewPos, cameraPos.get(), cameraRot.get());
|
||||||
|
drawFocusGizmo(viewPos, cameraPos.get(), cameraRot.get(), focal, aperture, fov);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -526,6 +535,100 @@ public class PathPreviewRenderer extends EventRegistrations {
|
|||||||
popMatrix();
|
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
|
//#if MC>=12105
|
||||||
//$$ private void vertex(VertexConsumer buffer, float x, float y, float z, float u, float v, int alpha) {
|
//$$ private void vertex(VertexConsumer buffer, float x, float y, float z, float u, float v, int alpha) {
|
||||||
//#else
|
//#else
|
||||||
|
|||||||
Reference in New Issue
Block a user