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

Re-use worker state and ray while rendering. #1749

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 @@ -44,6 +44,7 @@ public static class RenderWorker extends Thread {

public final Random random;
public final int id;
public final WorkerState state = new WorkerState();

private long lastSleep;
private long sleepTime = 0;
Expand All @@ -56,6 +57,7 @@ public RenderWorker(RenderWorkerPool pool, int id, long seed) {
this.pool = pool;
this.id = id;
this.random = new Random(seed);
state.random = this.random;

lastSleep = System.currentTimeMillis();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ protected void submitTiles(DefaultRenderManager manager, BiConsumer<WorkerState,

cachedTiles.forEach(tile ->
manager.pool.submit(worker -> {
WorkerState state = new WorkerState();
state.ray = new Ray();
state.ray.setNormal(0, 0, -1);
state.random = worker.random;

WorkerState state = worker.state;
state.reset();
IntIntMutablePair pair = new IntIntMutablePair(0, 0);

for (int i = tile.x0; i < tile.x1; i++) {
Expand Down
15 changes: 14 additions & 1 deletion chunky/src/java/se/llbit/chunky/renderer/WorkerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package se.llbit.chunky.renderer;

import se.llbit.chunky.block.minecraft.Air;
import se.llbit.math.Ray;
import se.llbit.math.Vector4;

Expand All @@ -25,7 +26,19 @@
* State for a render worker.
*/
public class WorkerState {
public Ray ray;
public Ray ray = new Ray();
public Vector4 attenuation = new Vector4();
public Random random;

public void reset() {
ray.distance = 0;
ray.setPrevMaterial(Air.INSTANCE, 0);
ray.setCurrentMaterial(Air.INSTANCE, 0);
ray.depth = 0;
ray.t = 0;
ray.tNext = 0;
ray.specular = false;

attenuation.set(0, 0, 0, 0);
}
}
Loading