Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transparent sky not working with render regions. #1790

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... This should be width

});
}).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 @@ -2059,9 +2059,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