Skip to content

Commit 92bf51d

Browse files
committed
Demo - add DeepExr framebuffer export demo
1 parent 381bdbc commit 92bf51d

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

tutorials/31_framebuffer_access/main.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020
// Here we demonstrate usage of rprFrameBufferGetInfo: We can access the image data of a frame buffer
2121
// In this demo, we use the data of a first rendering and use it as an input texture for a second rendering.
22+
// It also contains an example of DeepEXR framebuffer export.
2223
//
2324

2425

@@ -134,7 +135,9 @@ int main()
134135
rpr_framebuffer frame_buffer = nullptr;
135136
rpr_framebuffer frame_buffer_resolved = nullptr;
136137
CHECK(rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer));
138+
g_gc.GCAdd(frame_buffer);
137139
CHECK( rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer_resolved) );
140+
g_gc.GCAdd(frame_buffer_resolved);
138141

139142

140143
// Set framebuffer for the context
@@ -153,6 +156,39 @@ int main()
153156
// CHECK( rprFrameBufferSaveToFile(frame_buffer_resolved, "31_temp.png") );
154157

155158

159+
//
160+
// Demo for DeepEXR export.
161+
//
162+
// This part of code can be ignored ( or commented-out ) if the reader is not interested by DeepEXR: it doesn't affect the rest.
163+
{
164+
rpr_framebuffer_format fmt_deepEXR = { 0, RPR_COMPONENT_TYPE_DEEP }; // note that rpr_framebuffer_format::num_components is not needed for deepEXR.
165+
rpr_framebuffer frame_buffer_deepEXR = NULL;
166+
CHECK( rprContextCreateFrameBuffer(context, fmt_deepEXR, &desc, &frame_buffer_deepEXR));
167+
g_gc.GCAdd(frame_buffer_deepEXR);
168+
CHECK( rprContextSetAOV(context, RPR_AOV_DEEP_COLOR, frame_buffer_deepEXR));
169+
170+
// MERGE_Z_THRESHOLD : Merge close samples in order to reduce the EXR file size. Any positive value can be set.
171+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_DEEP_SUBPIXEL_MERGE_Z_THRESHOLD, 0.1f));
172+
173+
// GPU_ALLOCATION_LEVEL : this sets the speed/memory usage trade-off on GPU when generating deepEXR. Should be 1~32.
174+
// It's advised to use 4 ( current default value )
175+
// Modifying this value do NOT change the generated deepEXR file, it's only about performance.
176+
CHECK( rprContextSetParameterByKey1u(context, RPR_CONTEXT_DEEP_GPU_ALLOCATION_LEVEL, 4));
177+
178+
// COLOR_ENABLED can be set to 0 in order to remove RGB data from the deepEXR. Advantages are smaller EXR file and faster generation.
179+
CHECK( rprContextSetParameterByKey1u(context, RPR_CONTEXT_DEEP_COLOR_ENABLED, 1));
180+
181+
// Render the scene
182+
CHECK(rprContextSetParameterByKey1u(context,RPR_CONTEXT_ITERATIONS,100)); // increasing interation makes bigger deepEXR file.
183+
CHECK(rprFrameBufferClear(frame_buffer));
184+
CHECK( rprContextRender(context) );
185+
186+
CHECK( rprFrameBufferSaveToFile(frame_buffer_deepEXR, "31_deepEXR.exr"));
187+
188+
std::cout << "DeepEXR exported." << std::endl;
189+
}
190+
191+
156192

157193
///////// Framebuffer Access Tutorial //////////
158194
//
@@ -229,8 +265,6 @@ int main()
229265
CHECK(rprObjectDelete(light));light=nullptr;
230266
CHECK(rprObjectDelete(diffuse));diffuse=nullptr;
231267
CHECK(rprObjectDelete(camera));camera=nullptr;
232-
CHECK(rprObjectDelete(frame_buffer));frame_buffer=nullptr;
233-
CHECK(rprObjectDelete(frame_buffer_resolved));frame_buffer_resolved=nullptr;
234268
g_gc.GCClean();
235269
CHECK(rprObjectDelete(scene));scene=nullptr;
236270
CheckNoLeak(context);

tutorials/common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class RPRGarbageCollector
174174
void GCAdd(rpr_image n) { m_rprNodesCollector.push_back(n); }
175175
void GCAdd(rpr_shape n) { m_rprNodesCollector.push_back(n); }
176176
void GCAdd(rpr_light n) { m_rprNodesCollector.push_back(n); }
177+
void GCAdd(rpr_framebuffer n) { m_rprNodesCollector.push_back(n); }
177178

178179
void GCClean()
179180
{

tutorials/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ List of tutorials in this SDK
1919
| [MaterialX Demo](26_materialx) | ![](26_materialx/screenshot.png) | Radeon ProRender is compatible with MaterialX. This tutorial demonstrates how to use it. |
2020
| [Cutting Planes](27_cutplanes) | ![](27_cutplanes/screenshot.png) | This demos shows how to add Cutting planes (also called Clipping plane). |
2121
| [Tiled Render](30_tiled_render) | ![](30_tiled_render/screenshot.png) | This demo illustrates how to break down the framebuffer into smaller render regions (tiles) |
22-
| [Framebuffer access](31_framebuffer_access) | ![](31_framebuffer_access/screenshot.png) | Here we demonstrate usage of rprFrameBufferGetInfo: We can access the image data of a frame buffer. In this demo, we use the data of a first rendering and use it as an input texture for a second rendering. |
22+
| [Framebuffer access](31_framebuffer_access) | ![](31_framebuffer_access/screenshot.png) | Here we demonstrate usage of rprFrameBufferGetInfo: We can access the image data of a frame buffer. In this demo, we use the data of a first rendering and use it as an input texture for a second rendering. It also contains an example of DeepEXR framebuffer export. |
2323
| [OpenGL interop](32_gl_interop) | ![](32_gl_interop/screenshot.png) | Demo covering an RPR rendering inside an OpenGL app. |
2424
| [AOVs](33_aov) | ![](33_aov/screenshot.png) | This demo covers AOV (Arbitrary Output Variables), providing way to render different material component - mostly used for scene debugging. |
2525
| [Curves](50_curve) | ![](50_curve/screenshot.png) | Demo covering Curves rendering. Curves are often used for hair rendering. |

0 commit comments

Comments
 (0)