working DOF

This commit is contained in:
2026-07-01 04:48:45 +04:00
parent 3b070a7efc
commit 69013c2124
8 changed files with 131 additions and 12 deletions

View File

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

View File

@@ -4,6 +4,12 @@ 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;
@@ -50,14 +56,14 @@ public class RealLensOpenGlFrameCapturer
private static Data[] calculateCameras() {
Data[] cameras = golden_disk(SAMPLES, APERTURE_RADIUS);
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;
float dirZ = focal_distance - cam.dz;
// Вычисляем yaw и pitch из направления
cam.yaw = (float) -Math.toDegrees(Math.atan2(dirX, dirZ));
@@ -67,11 +73,14 @@ public class RealLensOpenGlFrameCapturer
return cameras;
}
private final Path positionPath;
public RealLensOpenGlFrameCapturer(
WorldRenderer worldRenderer,
RenderInfo renderInfo
) {
super(worldRenderer, renderInfo);
this.positionPath = ReplayModSimplePathing.instance.getCurrentTimeline().getPositionPath();
}
@Override
@@ -79,13 +88,24 @@ public class RealLensOpenGlFrameCapturer
float partialTicks = renderInfo.updateForNextFrame();
int frameId = framesDone++;
Data[] cameras = calculateCameras();
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++) {
// CAMERAS[i] передаётся в renderFrame → worldRenderer.renderWorld(partialTicks, CAMERAS[i])
// → EntityRendererHandler.data = CAMERAS[i] (автоматически)
frames[i] = renderFrame(frameId, partialTicks, cameras[i]);
}

View File

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

View File

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