thin lens aproximation mode MVP
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package com.replaymod.render.capturer;
|
||||
|
||||
public final class RealLensCameraContext {
|
||||
|
||||
private static final ThreadLocal<RealLensOpenGlFrameCapturer.Data> CURRENT =
|
||||
new ThreadLocal<>();
|
||||
|
||||
private RealLensCameraContext() {}
|
||||
|
||||
public static void set(RealLensOpenGlFrameCapturer.Data data) {
|
||||
CURRENT.set(data);
|
||||
}
|
||||
|
||||
public static RealLensOpenGlFrameCapturer.Data get() {
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
CURRENT.remove();
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ public class RealLensOpenGlFrameCapturer
|
||||
|
||||
public static class Data implements CaptureData {
|
||||
|
||||
public final float dx, dy, dz;
|
||||
public final float yaw, pitch;
|
||||
public float dx, dy, dz;
|
||||
public float yaw, pitch;
|
||||
|
||||
public Data(float dx, float dy, float dz,
|
||||
float yaw, float pitch) {
|
||||
@@ -25,12 +25,47 @@ public class RealLensOpenGlFrameCapturer
|
||||
}
|
||||
}
|
||||
|
||||
private static final Data[] CAMERAS = {
|
||||
new Data( 0.25f, 0.00f, 0f, 0f, 0f),
|
||||
new Data( 0.00f, 0.25f, 0f, 0f, 0f),
|
||||
new Data(-0.25f, 0.00f, 0f, 0f, 0f),
|
||||
new Data( 0.00f, -0.25f, 0f, 0f, 0f)
|
||||
};
|
||||
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)));
|
||||
|
||||
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),
|
||||
rr * (float) Math.sin(t),
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
|
||||
public RealLensOpenGlFrameCapturer(
|
||||
WorldRenderer worldRenderer,
|
||||
@@ -41,30 +76,19 @@ public class RealLensOpenGlFrameCapturer
|
||||
|
||||
@Override
|
||||
public Map<Channel, RealLensOpenGlFrame> process() {
|
||||
|
||||
float partialTicks = renderInfo.updateForNextFrame();
|
||||
int frameId = framesDone++;
|
||||
|
||||
OpenGlFrame[] frames = new OpenGlFrame[CAMERAS.length];
|
||||
Data[] cameras = calculateCameras();
|
||||
|
||||
try {
|
||||
for (int i = 0; i < CAMERAS.length; i++) {
|
||||
OpenGlFrame[] frames = new OpenGlFrame[cameras.length];
|
||||
|
||||
RealLensCameraContext.set(CAMERAS[i]);
|
||||
|
||||
frames[i] = renderFrame(
|
||||
frameId,
|
||||
partialTicks,
|
||||
CAMERAS[i]
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
RealLensCameraContext.clear();
|
||||
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]);
|
||||
}
|
||||
|
||||
return Collections.singletonMap(
|
||||
Channel.BRGA,
|
||||
new RealLensOpenGlFrame(frames)
|
||||
);
|
||||
return Collections.singletonMap(Channel.BRGA, new RealLensOpenGlFrame(frames));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user