Compare commits
6 Commits
0fae99c535
...
gpu-accumu
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fce67a560 | |||
| 088fb3bb30 | |||
| e2e04fa86f | |||
| 96bce7f38d | |||
| 4e7c027ec0 | |||
| 9be1fd8f6b |
@@ -156,6 +156,8 @@ public class RenderSettings {
|
||||
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
|
||||
@@ -191,6 +193,8 @@ public class RenderSettings {
|
||||
false,
|
||||
RenderSettings.AntiAliasing.NONE,
|
||||
16,
|
||||
1,
|
||||
180f,
|
||||
"",
|
||||
RenderSettings.EncodingPreset.MP4_CUSTOM.getValue(),
|
||||
false
|
||||
@@ -218,6 +222,8 @@ public class RenderSettings {
|
||||
boolean cameraPathExport,
|
||||
AntiAliasing antiAliasing,
|
||||
int lensBlurSamples,
|
||||
int motionBlurSubframes,
|
||||
float shutterAngle,
|
||||
String exportCommand,
|
||||
String exportArguments,
|
||||
boolean highPerformance
|
||||
@@ -242,6 +248,8 @@ public class RenderSettings {
|
||||
this.cameraPathExport = cameraPathExport;
|
||||
this.antiAliasing = antiAliasing;
|
||||
this.lensBlurSamples = lensBlurSamples;
|
||||
this.motionBlurSubframes = motionBlurSubframes;
|
||||
this.shutterAngle = shutterAngle;
|
||||
this.exportCommand = exportCommand;
|
||||
this.exportArguments = exportArguments;
|
||||
this.highPerformance = highPerformance;
|
||||
@@ -269,6 +277,8 @@ public class RenderSettings {
|
||||
cameraPathExport,
|
||||
antiAliasing,
|
||||
lensBlurSamples,
|
||||
motionBlurSubframes,
|
||||
shutterAngle,
|
||||
exportCommand,
|
||||
exportArguments,
|
||||
highPerformance
|
||||
@@ -464,6 +474,10 @@ public class RenderSettings {
|
||||
|
||||
public int getLensBlurSamples() { return lensBlurSamples; }
|
||||
|
||||
public int getMotionBlurSubframes() { return motionBlurSubframes; }
|
||||
|
||||
public float getShutterAngle() { return shutterAngle; }
|
||||
|
||||
public String getExportCommand() {
|
||||
return exportCommand;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -8,6 +8,17 @@ 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;
|
||||
@@ -15,6 +26,10 @@ 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> {
|
||||
|
||||
@@ -39,7 +54,7 @@ public class RealLensOpenGlFrameCapturer
|
||||
|
||||
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++) {
|
||||
float rr = r * (float) Math.sqrt((float) i / n);
|
||||
@@ -77,42 +92,108 @@ public class RealLensOpenGlFrameCapturer
|
||||
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);
|
||||
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
|
||||
public Map<Channel, RealLensOpenGlFrame> process() {
|
||||
float partialTicks = renderInfo.updateForNextFrame();
|
||||
renderInfo.updateForNextFrame();
|
||||
int frameId = framesDone++;
|
||||
|
||||
int fps = renderInfo.getRenderSettings().getFramesPerSecond();
|
||||
long keyframeTime = (long) frameId * 1000 / fps;
|
||||
RenderSettings settings = renderInfo.getRenderSettings();
|
||||
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);
|
||||
float apertureRadius = positionPath.getValue(LensProperties.APERTURE_RADIUS, keyframeTime).map(Triple::getLeft).orElse(0.05f);
|
||||
int samples = renderInfo.getRenderSettings().getLensBlurSamples();
|
||||
boolean motionBlur = shutter > 0f;
|
||||
double dt = 1000.0 / fps;
|
||||
double shutterFrac = motionBlur ? (shutter / 360.0) : 0.0;
|
||||
|
||||
if (positionPath == null) {
|
||||
System.err.println("positionPath is null!");
|
||||
focalDistance = Float.MAX_VALUE;
|
||||
apertureRadius = 0.01f;
|
||||
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;
|
||||
}
|
||||
|
||||
Data[] cameras = calculateCameras(focalDistance, apertureRadius, samples);
|
||||
accum.begin(width, height); // float-FBO нужного размера + очистка в 0
|
||||
|
||||
OpenGlFrame[] frames = new OpenGlFrame[cameras.length];
|
||||
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);
|
||||
|
||||
for (int i = 0; i < cameras.length; i++) {
|
||||
frames[i] = renderFrame(frameId, partialTicks, cameras[i]);
|
||||
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
|
||||
}
|
||||
|
||||
return Collections.singletonMap(Channel.BRGA, new RealLensOpenGlFrame(frames));
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,8 @@ public class GuiExportFailed extends GuiScreen {
|
||||
oldSettings.isCameraPathExport(),
|
||||
oldSettings.getAntiAliasing(),
|
||||
oldSettings.getLensBlurSamples(),
|
||||
oldSettings.getMotionBlurSubframes(),
|
||||
oldSettings.getShutterAngle(),
|
||||
oldSettings.getExportCommand(),
|
||||
oldSettings.getEncodingPreset().getValue(),
|
||||
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 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() {
|
||||
@@ -201,7 +203,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
depthMap, new GuiLabel(),
|
||||
cameraPathExport, new GuiLabel(),
|
||||
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")
|
||||
.setSize(55, 20).setMaxLength(100).onTextChanged((old) -> updateInputs());
|
||||
@@ -418,7 +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);
|
||||
lensBlurSamples.setEnabled(renderMethod == RenderSettings.RenderMethod.REALLENS);
|
||||
boolean isRealLens = renderMethod == RenderSettings.RenderMethod.REALLENS;
|
||||
lensBlurSamples.setEnabled(isRealLens);
|
||||
motionBlurSubframes.setEnabled(isRealLens);
|
||||
shutterAngle.setEnabled(isRealLens);
|
||||
}
|
||||
|
||||
protected String updateResolution() {
|
||||
@@ -546,6 +552,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
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) {
|
||||
@@ -580,6 +588,8 @@ public class GuiRenderSettings extends AbstractGuiPopup<GuiRenderSettings> {
|
||||
cameraPathExport.isChecked(),
|
||||
serialize || antiAliasingDropdown.isEnabled() ? antiAliasingDropdown.getSelectedValue() : RenderSettings.AntiAliasing.NONE,
|
||||
lensBlurSamples.getInteger(),
|
||||
motionBlurSubframes.getInteger(),
|
||||
(float) shutterAngle.getInteger(),
|
||||
exportCommand.getText(),
|
||||
exportArguments.getText(),
|
||||
highPerformance
|
||||
|
||||
140
src/main/java/com/replaymod/render/utils/AccumulationBuffer.java
Normal file
140
src/main/java/com/replaymod/render/utils/AccumulationBuffer.java
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user