-
Notifications
You must be signed in to change notification settings - Fork 185
Description
For context, I'm working on a Godot pull request that adds shadowmasking to the CPU lightmapper, which uses OpenImageDenoise. The shadowmask is stored in the lightmap's alpha channel to prevent the need to use a separate texture (which adds a whole lot of complexity). However, if I enable the denoiser, this alpha channels is lost when the image is denoised.
I've tried the following to allow preserving the alpha channel of the input image:
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);
+ // Pass 16-byte pixel stride to preserve the unmodified 32-bit alpha channel.
+ oidnSetSharedFilterImage(filter, "color", (void *)p_floats, OIDN_FORMAT_FLOAT3, p_width, p_height, 0, 16, 0);
+ oidnSetSharedFilterImage(filter, "output", (void *)p_floats, OIDN_FORMAT_FLOAT3, p_width, p_height, 0, 16, 0);
oidnSetFilter1b(filter, "hdr", true);
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;
}I'm not sure I understand what size to pass as a stride. My image data is always Image::FORMAT_RGBAF (floating-point RGBA with 32 bpc precision).
I've tried different values such as 4, 8, 12, 16 but they all resulted in an error message (LightmapDenoiser: pixel stride smaller than pixel size), or an image that looked corrupted. I've also tried specifying different strides for the "color" and "output" images to no avail.
Would it be possible to add a code sample to the README that describes how to preserve an image's alpha channel, assuming the image uses RGBAF format (not ARGBF)? Thanks in advance 🙂