summaryrefslogtreecommitdiff
path: root/modules/denoise/denoise_wrapper.cpp
blob: feeeaef50723af372b69b0fc655206ab6f2df305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "denoise_wrapper.h"
#include "thirdparty/oidn/include/OpenImageDenoise/oidn.h"
#include <stdio.h>

void *oidn_denoiser_init() {
	OIDNDeviceImpl *device = oidnNewDevice(OIDN_DEVICE_TYPE_CPU);
	oidnCommitDevice(device);
	return device;
}

bool oidn_denoise(void *deviceptr, float *p_floats, int p_width, int p_height) {
	OIDNDeviceImpl *device = (OIDNDeviceImpl *)deviceptr;
	OIDNFilter filter = oidnNewFilter(device, "RTLightmap");
	oidnSetSharedFilterImage(filter, "color", (void *)p_floats, OIDN_FORMAT_FLOAT3, p_width, p_height, 0, 0, 0);
	oidnSetSharedFilterImage(filter, "output", (void *)p_floats, OIDN_FORMAT_FLOAT3, p_width, p_height, 0, 0, 0);
	oidnSetFilter1b(filter, "hdr", true);
	//oidnSetFilter1f(filter, "hdrScale", 1.0f);
	oidnCommitFilter(filter);
	oidnExecuteFilter(filter);

	const char *msg;
	bool success = true;
	if (oidnGetDeviceError(device, &msg) != OIDN_ERROR_NONE) {
		printf("LightmapDenoiser: %s\n", msg);
		success = false;
	}

	oidnReleaseFilter(filter);
	return success;
}

void oidn_denoiser_finish(void *device) {
	oidnReleaseDevice((OIDNDeviceImpl *)device);
}