Skip to content

Commit 3580f75

Browse files
authored
Add a denoising renderer. (#28)
* Integrated denoised path tracing renderer. * Don't call callback on last frame of beauty pass. * Render all passes at the same time. * Reorder passes. * Refactor the denoiser and create a `Denoiser` interface. Add inplace denoiser. Move settings to its own class. * Implement saving the beauty pass. * Bump the plugin version. * Add support for headless mode. Clean up imports. * Remove albedo and normal tracers. Clean up some code. * Update README * Update settings to use observables instead of making the entire object an observable. Fix settings to load every field from scene. * Update settings tab with settings once it has loaded in. * Fix NPE where normal tracer settings were not set.
1 parent 4d4db51 commit 3580f75

20 files changed

+879
-490
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ Please use [version 0.3.2](https://github.com/chunky-dev/chunky-denoiser/release
88

99
Download the latest plugin release for your Chunky version from the [releases page](https://github.com/leMaik/chunky-denoiser/releases). In the Chunky Launcher, click on _Manage plugins_ and then on _Add_ and select the `.jar` file you just downloaded. Click on `Save` to store the updated configuration, then start Chunky as usual.
1010

11-
**Compatibility note:** If you are using the [Discord plugin](https://github.com/leMaik/chunky-discord), make sure that it is loaded _after_ the Denoising plugin, i.e. use the _Down_ button to move it below it in the plugin list. Otherwise the denoiser plugin will not work.
11+
Download the Intel Open Image Denoiser [here][openimagedenoise-dl]. After unpacking the archive in a safe location, you can configure the denoiser executable (`denoiser.exe` on Windows, `denoiser` on Linux) in the `Denoiser` tab inside Chunky.
1212

1313
## Usage
1414

15-
Just render a scene as usual. It will render three images and save them as _Portable Float Maps_.
15+
Select the `DenoisedPathTracer` in the `Advanced` tab:
1616

17-
### Denoise automatically
17+
![image](https://user-images.githubusercontent.com/42661490/147403029-54d291c2-8142-4a36-b6ea-4485156f9484.png)
1818

19-
The Intel Open Image Denoiser can be downloaded [here][openimagedenoise-dl]. After unpacking the archive, you can configure the denoiser executable (`denoiser.exe` on Windows, `denoiser` on Linux) in the _Denoiser_ tab inside Chunky. If you do this, it will output the denoised image alongside the original image in the scene's snapshots directory.
19+
Then render the scene as usual. It will automatically render all passes and denoise the final image.
2020

21-
### Invoke the denoiser manually
21+
### Denoising an Existing Render
2222

23-
After the rendering is done, the plugin will save the resulting image as `scene-name.pfm` in the scene directory and start to render a normal image (saved as `scene-name.normal.pfm`) and an Albedo image (`scene-name.albedo.pfm`). These files can be used by [Intel Open Image Denoise][openimagedenoise-dl] like this:
23+
Existing renders can be denoised by clicking on the `Denoise Current Render` button in the `Denoiser` tab:
24+
25+
![image](https://user-images.githubusercontent.com/42661490/147403139-67f3661c-1575-407f-af05-1d8780f68c73.png)
26+
27+
**WARNING: this will overwrite your existing render.**
28+
29+
It will automatically render all passes and denoise the final image.
30+
31+
### Denoising Outside Chunky
32+
33+
By checking `Save albedo map` and `Save normal map`, the denoised renderers will automatically save the albedo and normal maps as `.pfm` files inside the scene directory.
34+
35+
![image](https://user-images.githubusercontent.com/42661490/147403108-78aa1b33-5549-46de-8194-3f33d2e799a0.png)
36+
37+
These files can be used by [Intel Open Image Denoise][openimagedenoise-dl] like this:
2438

2539
```
2640
./denoise -ldr scene-name.pfm -alb scene-name.albedo.pfm -nrm scene-name.normal.pfm -o output.pfm
2741
```
2842

29-
To view the resulting image, it needs to be converted back to an actual image file. This can be done by the `pfm2png.py` Python 3 script included in this repository or using an online converter, e.g. [this one][convertio].
30-
3143
## License
3244

3345
Copyright 2019-2021 Maik Marschner (leMaik)

build.gradle

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,40 @@
11
apply plugin: 'java'
22
jar.enabled = false
33

4-
compileJava {
5-
sourceCompatibility = JavaVersion.VERSION_1_8
6-
targetCompatibility = JavaVersion.VERSION_1_8
4+
sourceCompatibility = '1.8'
5+
targetCompatibility = '1.8'
6+
7+
configurations {
8+
implementation.extendsFrom(provided)
9+
implementation.extendsFrom(bundled)
710
}
811

9-
sourceSets {
10-
main {
11-
if (project.properties.get("chunky") == "1") {
12-
java.srcDir 'src/main/java'
13-
java.srcDir 'src/chunky-1/java'
14-
resources.srcDir 'src/main/resources'
15-
resources.srcDir 'src/chunky-1/resources'
16-
} else {
17-
java.srcDir 'src/main/java'
18-
java.srcDir 'src/chunky-2/java'
19-
resources.srcDir 'src/main/resources'
20-
resources.srcDir 'src/chunky-2/resources'
21-
}
22-
}
12+
dependencies {
13+
provided 'se.llbit:chunky-core:2.4.0'
14+
provided 'org.apache.commons:commons-math3:3.2'
15+
provided 'it.unimi.dsi:fastutil:8.4.4'
16+
provided 'se.llbit:jo-json:1.3.1'
2317
}
2418

2519
task pluginJar(type: Jar) {
26-
classifier = 'chunky' + project.properties.get("chunky")
2720
with jar
2821
}
2922

30-
dependencies {
31-
if (project.properties.get("chunky") == "1") {
32-
compile 'se.llbit:chunky-core:1.4.5'
33-
} else {
34-
compile 'se.llbit:chunky-core:2.0-beta6'
23+
jar {
24+
manifest {
25+
attributes "Main-Class": "de.lemaik.chunky.denoiser.DenoiserPlugin"
26+
}
27+
28+
from {
29+
configurations.bundled.collect { it.isDirectory() ? it : zipTree(it) }
3530
}
36-
runtimeClasspath 'org.apache.commons:commons-math3:3.2'
3731
}
3832

3933
repositories {
4034
mavenLocal()
4135
mavenCentral()
4236
maven {
43-
url 'https://oss.sonatype.org/content/repositories/snapshots/'
37+
url 'https://repo.lemaik.de/'
4438
}
4539
}
40+

src/main/java/de/lemaik/chunky/denoiser/AlbedoRenderer.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package de.lemaik.chunky.denoiser;
2+
3+
import se.llbit.chunky.block.Air;
4+
import se.llbit.chunky.block.Water;
5+
import se.llbit.chunky.renderer.WorkerState;
6+
import se.llbit.chunky.renderer.scene.PreviewRayTracer;
7+
import se.llbit.chunky.renderer.scene.RayTracer;
8+
import se.llbit.chunky.renderer.scene.Scene;
9+
import se.llbit.math.Ray;
10+
11+
public class AlbedoTracer implements RayTracer {
12+
@Override
13+
public void trace(Scene scene, WorkerState state) {
14+
Ray ray = state.ray;
15+
if (scene.isInWater(ray)) {
16+
ray.setCurrentMaterial(Water.INSTANCE, 0);
17+
} else {
18+
ray.setCurrentMaterial(Air.INSTANCE, 0);
19+
}
20+
21+
while (true) {
22+
if (!PreviewRayTracer.nextIntersection(scene, ray)) {
23+
if (ray.getPrevMaterial().isWater()) {
24+
// set water color to white
25+
ray.color.set(1, 1, 1, 1);
26+
} else if (ray.depth == 0) {
27+
// direct sky hit
28+
if (!scene.transparentSky()) {
29+
scene.sky().getSkyColorInterpolated(ray);
30+
}
31+
}
32+
// ignore indirect sky hits
33+
break;
34+
}
35+
36+
if (ray.getCurrentMaterial() != Air.INSTANCE && ray.color.w > 0.0D) {
37+
break;
38+
}
39+
40+
ray.o.scaleAdd(1.0E-4D, ray.d);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)