GPUOpen-LibrariesAndSDKs / RadeonImageFilter

https://gpuopen.com/radeon-prorender-suite/
Other
49 stars 15 forks source link

Depth of field effect not working with RPR generated images (color/depth) #3

Closed marceloroca closed 3 years ago

marceloroca commented 3 years ago

I've generated color and depth images with RPR , and using the RIF_IMAGE_FILTER_DEPTH_OF_FIELD filter, but the result image is the same that the source.

this is the code:

//Create image filter
status = rifContextCreateImageFilter(context, RIF_IMAGE_FILTER_DEPTH_OF_FIELD, &filter);
if (status != RIF_SUCCESS)
{
    return -1;
}

// Load input image
inputImage = ImageTools::LoadImage("images/22.png", context);
inputImageDepth = ImageTools::LoadImage("images/22_Depth.png", context);

if (!(inputImage && inputImageDepth))
{
    return -1;
}

//Create output image
rif_image_desc desc;
size_t retSize;
rifImageGetInfo(inputImage, RIF_IMAGE_DESC, sizeof(desc), &desc, &retSize);
status = rifContextCreateImage(context, &desc, nullptr, &outputImage);
if (status != RIF_SUCCESS)
{
    return -1;
}

//Attach filter and set parameters
if (rifImageFilterSetParameter1u(filter, "kernelSize", RIF_DEPTH_OF_FIELD_FILTER_KERNEL_SIZE_LARGE) != RIF_SUCCESS) { return -1; }
if (rifImageFilterSetParameter1f(filter, "focusD", 1.8f) != RIF_SUCCESS) { return -1; }
if (rifImageFilterSetParameter1f(filter, "aperture", 0.8f) != RIF_SUCCESS) { return -1; }
if (rifImageFilterSetParameterImage(filter, "depthImg", inputImageDepth) != RIF_SUCCESS) { return -1; }
if (rifCommandQueueAttachImageFilter(queue, filter, inputImage, outputImage) != RIF_SUCCESS) { return -1; }

//Execute queue
if (rifContextExecuteCommandQueue(context, queue, nullptr, nullptr, nullptr) != RIF_SUCCESS) { return -1; }

//Save output image
ImageTools::SaveImage(outputImage, "22_final.png");

the depth image is generated with RPR with this code:

rpr_framebuffer frame_buffer_depth, frame_buffer_depth2;
CHECK(rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer_depth));
CHECK(rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer_depth2));
CHECK(rprFrameBufferClear(frame_buffer_depth));
CHECK(rprFrameBufferClear(frame_buffer_depth2));
CHECK(rprContextSetAOV(context, RPR_AOV_DEPTH, frame_buffer_depth));

// Progressively render an image

CHECK(rprContextResolveFrameBuffer(context, frame_buffer_depth, frame_buffer_depth2, true));
CHECK(rprFrameBufferSaveToFile(frame_buffer_depth2, "22_depth.png"));

The depth image has pixel values between 1 and 10000.

RPR SDK version: 0x00103503 build: 0x92f604e2 RIF SDK version: 1.5.3 commit: 0x47b72111 OS: Windows 10 GPU: Radeon RX 5500 XT Driver: 20.5.1

stmuxa commented 3 years ago

Can you share the generated images as well? I think it's because png format cannot keep your depth buffer values (between 1 and 10000), they are all clamped to 256. Try saving it to exr like this CHECK(rprFrameBufferSaveToFile(frame_buffer_depth2, "22_depth.exr"));

marceloroca commented 3 years ago

I've changed to "exr", but I have the same problem, and others problems:

I'm sharing the generated images, the RPR program to generate the images and the RIF program to apply the filter

dof test.zip

RPR program is a modified of SDK tutorial 22_material_uber RIF program is a modified from Bloom filter

stmuxa commented 3 years ago

@marceloroca can you also collect trace files accodring to this manual https://radeon-pro.github.io/RadeonProRenderDocs/en/rif/tracing.html archive them and attach. Thanks.

marceloroca commented 3 years ago

Here is, rif_trace_1595437696.zip

stmuxa commented 3 years ago

So, the gray cubes are at about 19-21 meters from camera I set:

rifImageFilterSetParameter1f(filter, "focusD", 20);

I also changed focal length parameter to 100 mm (https://radeon-pro.github.io/RadeonProRenderDocs/en/rif/filters/depth_of_field.html)

rifImageFilterSetParameter1f(filter, "focalL", 100);

and got the image blurred.

image

marceloroca commented 3 years ago

thanks for your help, it's working