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

Skip rendering tiles that only contain sky. #1748

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void render(DefaultRenderManager manager) throws InterruptedException {
double halfWidth = fullWidth / (2.0 * fullHeight);
double invHeight = 1.0 / fullHeight;

resetTiles(manager); // reset previously skipped tiles

double[] sampleBuffer = scene.getSampleBuffer();

while (scene.spp < scene.getTargetSpp()) {
Expand Down
2 changes: 2 additions & 0 deletions chunky/src/java/se/llbit/chunky/renderer/PreviewRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void render(DefaultRenderManager manager) throws InterruptedException {
int ty = (int) Math.floor(target.o.y + target.d.y * Ray.OFFSET);
int tz = (int) Math.floor(target.o.z + target.d.z * Ray.OFFSET);

resetTiles(manager); // reset previously skipped tiles

double[] sampleBuffer = scene.getSampleBuffer();

for (int i = 0; i < 2; i++) {
Expand Down
21 changes: 17 additions & 4 deletions chunky/src/java/se/llbit/chunky/renderer/TileBasedRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public abstract class TileBasedRenderer implements Renderer {
public static class RenderTile {
public int x0, x1;
public int y0, y1;
public boolean skip = false;

public RenderTile(int x0, int x1, int y0, int y1) {
this.x0 = x0;
Expand All @@ -67,7 +68,10 @@ public void setPostRender(BooleanSupplier callback) {
protected void submitTiles(DefaultRenderManager manager, BiConsumer<WorkerState, IntIntPair> perPixel) {
initTiles(manager);

cachedTiles.forEach(tile ->
cachedTiles.forEach(tile -> {
if (tile.skip) {
return;
}
manager.pool.submit(worker -> {
WorkerState state = new WorkerState();
state.ray = new Ray();
Expand All @@ -82,7 +86,12 @@ protected void submitTiles(DefaultRenderManager manager, BiConsumer<WorkerState,
perPixel.accept(state, pair);
}
}
})

if (!state.hit) {
tile.skip = true;
}
});
}
);
}

Expand All @@ -92,17 +101,21 @@ private void initTiles(DefaultRenderManager manager) {
int width = scene.canvasConfig.getWidth();
int height = scene.canvasConfig.getHeight();

if (prevWidth != width || prevHeight != height) {
if (prevWidth != width || prevHeight != height || cachedTiles.isEmpty()) {
prevWidth = width;
prevHeight = height;
cachedTiles.clear();

for (int i = 0; i < width; i += tileWidth) {
for (int j = 0; j < height; j += tileWidth) {
cachedTiles.add(new RenderTile(i, FastMath.min(i + tileWidth, width),
j, FastMath.min(j + tileWidth, height)));
j, FastMath.min(j + tileWidth, height)));
}
}
}
}

public void resetTiles(DefaultRenderManager manager) {
cachedTiles.clear();
}
}
1 change: 1 addition & 0 deletions chunky/src/java/se/llbit/chunky/renderer/WorkerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public class WorkerState {
public Ray ray;
public Vector4 attenuation = new Vector4();
public Random random;
public boolean hit = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state,
if (ray.getPrevMaterial().isWater()) {
ray.color.set(0, 0, 0, 1);
hit = true;
state.hit = true;
} else if (ray.depth == 0) {
// Direct sky hit.
if (!scene.transparentSky()) {
Expand All @@ -81,11 +82,13 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state,
scene.sky.getSkyColor(ray, true);
addSkyFog(scene, ray, state, ox, od);
hit = true;
state.hit = true;
} else {
// Indirect sky hit - diffuse color.
scene.sky.getSkyColorDiffuseSun(ray, scene.getSunSamplingStrategy().isDiffuseSun());
// Skip sky fog - likely not noticeable in diffuse reflection.
hit = true;
state.hit = true;
}
break;
}
Expand Down
Loading