Skip to content

Commit

Permalink
Fix transparent sky not working with render regions. (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik authored Oct 27, 2024
1 parent a62785d commit 37bcdf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions chunky/src/java/se/llbit/chunky/renderer/scene/AlphaBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ void computeAlpha(Scene scene, Type type, TaskTracker taskTracker) {

try (TaskTracker.Task task = taskTracker.task("Computing alpha channel")) {
this.type = type;
int cropX = scene.canvasConfig.getCropX();
int cropY = scene.canvasConfig.getCropY();
int width = scene.canvasConfig.getWidth();
int height = scene.canvasConfig.getHeight();
int fullWidth = scene.canvasConfig.getCropWidth();
int fullHeight = scene.canvasConfig.getCropHeight();
buffer = ByteBuffer.allocate(scene.canvasConfig.getPixelCount() * type.byteSize);

AtomicInteger done = new AtomicInteger(0);
Expand All @@ -83,10 +87,10 @@ void computeAlpha(Scene scene, Type type, TaskTracker taskTracker) {
state.ray = new Ray();

for (int y = 0; y < height; y++) {
computeAlpha(scene, x, y, width, height, state);
computeAlpha(scene, x, y, cropX, cropY, width, height, fullWidth, fullHeight, state);
}

task.update(width, done.incrementAndGet());
task.update(height, done.incrementAndGet());
});
}).get();
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -97,10 +101,10 @@ void computeAlpha(Scene scene, Type type, TaskTracker taskTracker) {
/**
* Compute the alpha channel based on sky visibility.
*/
public void computeAlpha(Scene scene, int x, int y, int width, int height, WorkerState state) {
public void computeAlpha(Scene scene, int x, int y, int cropX, int cropY, int width, int height, int fullWidth, int fullHeight, WorkerState state) {
Ray ray = state.ray;
double halfWidth = width / (2.0 * height);
double invHeight = 1.0 / height;
double halfWidth = fullWidth / (2.0 * fullHeight);
double invHeight = 1.0 / fullHeight;

// Rotated grid supersampling.
double[][] offsets = new double[][]{
Expand All @@ -113,8 +117,8 @@ public void computeAlpha(Scene scene, int x, int y, int width, int height, Worke
double occlusion = 0.0;
for (double[] offset : offsets) {
scene.camera.calcViewRay(ray,
-halfWidth + (x + offset[0]) * invHeight,
-0.5 + (y + offset[1]) * invHeight);
-halfWidth + (x + offset[0] + cropX) * invHeight,
-0.5 + (y + offset[1] + cropY) * invHeight);
ray.o.x -= scene.origin.x;
ray.o.y -= scene.origin.y;
ray.o.z -= scene.origin.z;
Expand Down
4 changes: 2 additions & 2 deletions chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -2060,9 +2060,9 @@ public synchronized void writeFrame(OutputStream out, PictureExportFormat mode,
if (transparentSky) {
if (mode.getTransparencyType() == AlphaBuffer.Type.UNSUPPORTED) {
Log.warn("You selected \"transparent sky\", but the selected picture format \"" + mode.getName() + "\" does not support alpha layers.\nUse a different format like PNG instead.");
}
alphaBuffer.computeAlpha(this, mode.getTransparencyType(), taskTracker);
}
alphaBuffer.computeAlpha(this, mode.getTransparencyType(), taskTracker);
}
if (mode.wantsPostprocessing() && !finalized) {
postProcessFrame(taskTracker);
}
Expand Down

0 comments on commit 37bcdf5

Please sign in to comment.