Skip to content

Commit 381bdbc

Browse files
committed
update demos and add DOF + Adaptive sampling demo
1 parent 54c400d commit 381bdbc

File tree

34 files changed

+876
-677
lines changed

34 files changed

+876
-677
lines changed
24.9 MB
Binary file not shown.

license.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ FreeGLUT
2424
picoJson - JSON parser - 2-clause BSD license - https://github.com/kazuho/picojson
2525
tinyObjLoader - OBJ parser - MIT License - https://github.com/tinyobjloader/tinyobjloader
2626
Premake - https://github.com/premake/premake-core - BSD 3-Clause "New" or "Revised" License - https://github.com/premake/premake-core/blob/master/LICENSE.txt
27+
turning_area_4k.hdr image - https://polyhaven.com/a/turning_area - License: CC0 (public domain)
28+

tutorials/05_basic_scene/main.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ int main()
132132
// There are ways to call rprContextRender in a separate thread but this won't be done in this tutorial.
133133
CHECK( rprContextRender(context) );
134134

135-
// "resolve" to create a framebuffer that can be displayed.
136-
// the 'normalizeOnly' argument means we want to do the basic framebuffer resolution.
137-
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,true));
135+
// 'frame_buffer' is not supposed to be used for rendering, we need to process it with rprContextResolveFrameBuffer.
136+
// This function transforms the raw 'frame_buffer' into a new 'frame_buffer_resolved' that can be displayed on screen as final rendering.
137+
// The 'normalizeOnly' argument means we only want to do a normalization of 'frame_buffer'.
138+
// In most of cases, this argument can be left to FALSE: this lets the Renderer choose the correct operation(s) to process.
139+
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,false));
138140

139141
// save the rendering to an image file.
140142
CHECK(rprFrameBufferSaveToFile(frame_buffer_resolved,"05_00.png"));
@@ -226,7 +228,7 @@ int main()
226228
CHECK( rprFrameBufferClear(frame_buffer) );
227229

228230
CHECK( rprContextRender(context) );
229-
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,true));
231+
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,false));
230232
CHECK(rprFrameBufferSaveToFile(frame_buffer_resolved,"05_01.png"));
231233

232234

@@ -263,9 +265,6 @@ int main()
263265
rpr_material_node materialImage2 = nullptr;
264266
rpr_material_node uv_node = NULL;
265267
{
266-
267-
268-
269268
const std::string pathImageFileA = "../../Resources/Textures/amd.png";
270269
rpr_status status = rprContextCreateImageFromFile(context, pathImageFileA.c_str(), &image2);
271270
if (status == RPR_ERROR_IO_ERROR)
@@ -316,7 +315,7 @@ int main()
316315
{
317316
CHECK(rprContextCreateEnvironmentLight(context, &lightEnv));
318317

319-
const std::string pathImageFile = "../../Resources/Textures/envLightImage.exr";
318+
const std::string pathImageFile = "../../Resources/Textures/turning_area_4k.hdr";
320319
rpr_status status = rprContextCreateImageFromFile(context, pathImageFile.c_str(), &imgEnvLight); // import image use by the Env light
321320
if (status == RPR_ERROR_IO_ERROR)
322321
{
@@ -329,17 +328,28 @@ int main()
329328
CHECK(rprEnvironmentLightSetImage(lightEnv, imgEnvLight));
330329

331330
// adjust the intensity of the Env light
332-
CHECK(rprEnvironmentLightSetIntensityScale(lightEnv, 1.0f));
331+
CHECK(rprEnvironmentLightSetIntensityScale(lightEnv, 0.8f));
332+
333+
//optional: env light can be rotated :
334+
//RadeonProRender::matrix lightm = RadeonProRender::rotation_y(MY_PI/2.0f);
335+
//CHECK( rprLightSetTransform(lightEnv, true, &lightm.m00));
333336

334337
// Set Env light as a background for the scene
335338
CHECK(rprSceneAttachLight(scene, lightEnv));
336339
}
337340

341+
// move camera
342+
CHECK( rprCameraLookAt(camera, 0, 4, 10, 0, 1, 0, 0, 1, 0) );
343+
344+
// modify display gamma. In most of the cases, display gamma should be around 2.2.
345+
// This makes image brightness looking better on majority of monitors.
346+
// Gamma is applied during the "rprContextResolveFrameBuffer" call.
347+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_DISPLAY_GAMMA , 2.2f ) );
338348

339349
// render the current scene the same way we did for 05_01.png
340350
CHECK(rprFrameBufferClear(frame_buffer) );
341351
CHECK(rprContextRender(context) );
342-
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,true));
352+
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,false));
343353
CHECK(rprFrameBufferSaveToFile(frame_buffer_resolved,"05_02.png"));
344354

345355

@@ -385,7 +395,7 @@ int main()
385395
// render the current scene the same way we did for 05_01.png
386396
CHECK(rprFrameBufferClear(frame_buffer) );
387397
CHECK(rprContextRender(context) );
388-
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,true));
398+
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,false));
389399
CHECK(rprFrameBufferSaveToFile(frame_buffer_resolved,"05_03.png"));
390400

391401

6.92 KB
Loading

tutorials/12_transform_motion_blur/main.cpp

Lines changed: 10 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ RadeonProRender::matrix CameraLookAtToMatrix( RadeonProRender::float3 pos , Rad
4242
}
4343

4444

45+
RPRGarbageCollector g_gc;
46+
47+
4548
int main()
4649
{
4750
// enable Radeon ProRender API trace
@@ -110,40 +113,11 @@ int main()
110113
CHECK(rprShapeSetTransform(teapot01, RPR_TRUE, &m0.m00));
111114
}
112115

113-
// Create plane mesh
114-
rpr_shape plane = nullptr;
115-
{
116-
CHECK(rprContextCreateMesh(context,
117-
(rpr_float const*)&plane_data[0], 4, sizeof(vertex),
118-
(rpr_float const*)((char*)&plane_data[0] + sizeof(rpr_float) * 3), 4, sizeof(vertex),
119-
(rpr_float const*)((char*)&plane_data[0] + sizeof(rpr_float) * 6), 4, sizeof(vertex),
120-
(rpr_int const*)indices, sizeof(rpr_int),
121-
(rpr_int const*)indices, sizeof(rpr_int),
122-
(rpr_int const*)indices, sizeof(rpr_int),
123-
num_face_vertices, 2, &plane));
124-
CHECK(rprSceneAttachShape(scene, plane));
125-
}
126-
116+
// create the floor
117+
CHECK( CreateAMDFloor(context, scene, matsys, g_gc, 1.0f, 1.0f) );
127118

128-
// Create an Environment Light light
129-
rpr_light lightEnv = nullptr;
130-
rpr_image imgEnvLight = nullptr;
131-
{
132-
CHECK(rprContextCreateEnvironmentLight(context, &lightEnv));
133-
134-
const std::string pathImageFile = "../../Resources/Textures/envLightImage.exr";
135-
rpr_status status = rprContextCreateImageFromFile(context, pathImageFile.c_str(), &imgEnvLight); // import image use by the Env light
136-
if (status == RPR_ERROR_IO_ERROR)
137-
{
138-
std::cout << "Error : " << pathImageFile << " not found.\n";
139-
return -1;
140-
}
141-
CHECK(status);
142-
143-
CHECK(rprEnvironmentLightSetImage(lightEnv, imgEnvLight));
144-
CHECK(rprEnvironmentLightSetIntensityScale(lightEnv, 1.0f));
145-
CHECK(rprSceneAttachLight(scene, lightEnv));
146-
}
119+
// Create an environment light
120+
CHECK( CreateNatureEnvLight(context, scene, g_gc, 0.8f) );
147121

148122

149123
// create a DIFFUSE material for the Teapot
@@ -161,49 +135,9 @@ int main()
161135
}
162136

163137

164-
165-
// create a DIFFUSE material for the Floor
166-
//
167-
rpr_material_node uv_scaled_node = NULL;
168-
rpr_material_node diffuse5 = nullptr;
169-
rpr_image image2 = nullptr;
170-
rpr_material_node materialImage2 = nullptr;
171-
rpr_material_node uv_node = NULL;
172-
{
173-
174-
175-
const std::string pathImageFileA = "../../Resources/Textures/amd.png";
176-
rpr_status status = rprContextCreateImageFromFile(context, pathImageFileA.c_str(), &image2);
177-
if (status == RPR_ERROR_IO_ERROR)
178-
{
179-
std::cout << "Error : " << pathImageFileA << " not found.\n";
180-
return -1;
181-
}
182-
CHECK(status);
183-
184-
CHECK(rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_IMAGE_TEXTURE, &materialImage2));
185-
CHECK(rprMaterialNodeSetInputImageDataByKey(materialImage2, RPR_MATERIAL_INPUT_DATA, image2)); // Set image data
186-
187-
CHECK(rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_DIFFUSE, &diffuse5));
188-
CHECK(rprMaterialNodeSetInputNByKey(diffuse5, RPR_MATERIAL_INPUT_COLOR, materialImage2)); // set image sampler as the color input of diffuse material
189-
190-
CHECK(rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_INPUT_LOOKUP, &uv_node));
191-
CHECK(rprMaterialNodeSetInputUByKey(uv_node, RPR_MATERIAL_INPUT_VALUE, RPR_MATERIAL_NODE_LOOKUP_UV));
192-
193-
CHECK(rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_ARITHMETIC, &uv_scaled_node));
194-
CHECK(rprMaterialNodeSetInputUByKey(uv_scaled_node, RPR_MATERIAL_INPUT_OP, RPR_MATERIAL_NODE_OP_MUL));
195-
CHECK(rprMaterialNodeSetInputNByKey(uv_scaled_node, RPR_MATERIAL_INPUT_COLOR0, uv_node));
196-
CHECK(rprMaterialNodeSetInputFByKey(uv_scaled_node, RPR_MATERIAL_INPUT_COLOR1, 2.0f, 4.0f, 0, 0));
197-
198-
CHECK(rprMaterialNodeSetInputNByKey(materialImage2, RPR_MATERIAL_INPUT_UV, uv_scaled_node));
199-
200-
CHECK(rprShapeSetMaterial(plane, diffuse5));
201-
}
202-
203-
204138
// First, Render scene without any motion
205139
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_DISPLAY_GAMMA , 2.2f ) ); // set display gamma
206-
CHECK( rprContextSetParameterByKey1u(context,RPR_CONTEXT_ITERATIONS,NUM_ITERATIONS));
140+
CHECK( rprContextSetParameterByKey1u(context,RPR_CONTEXT_ITERATIONS,200));
207141
CHECK( rprContextRender(context) );
208142
CHECK( rprContextResolveFrameBuffer(context,fb_color,fb_color_resolved,false));
209143
CHECK( rprContextResolveFrameBuffer(context,fb_velocity,fb_velocity_resolved,false));
@@ -267,22 +201,15 @@ int main()
267201
//
268202
CHECK(rprObjectDelete(img)); img=nullptr;
269203
CHECK(rprObjectDelete(imgSampler)); imgSampler=nullptr;
270-
CHECK(rprObjectDelete(uv_scaled_node)); uv_scaled_node=nullptr;
271-
CHECK(rprObjectDelete(diffuse5)); diffuse5=nullptr;
272-
CHECK(rprObjectDelete(image2)); image2=nullptr;
273-
CHECK(rprObjectDelete(materialImage2)); materialImage2=nullptr;
274-
CHECK(rprObjectDelete(uv_node)); uv_node=nullptr;
275204
CHECK(rprObjectDelete(diffuse1)); diffuse1=nullptr;
276-
CHECK(rprObjectDelete(lightEnv)); lightEnv=nullptr;
277-
CHECK(rprObjectDelete(imgEnvLight)); imgEnvLight=nullptr;
278205
CHECK(rprObjectDelete(camera)); camera=nullptr;
279206
CHECK(rprObjectDelete(fb_color)); fb_color=nullptr;
280207
CHECK(rprObjectDelete(fb_color_resolved)); fb_color_resolved=nullptr;
281208
CHECK(rprObjectDelete(fb_velocity)); fb_velocity=nullptr;
282209
CHECK(rprObjectDelete(fb_velocity_resolved)); fb_velocity_resolved=nullptr;
283-
CHECK(rprObjectDelete(scene)); scene=nullptr;
284210
CHECK(rprObjectDelete(teapot01)); teapot01=nullptr;
285-
CHECK(rprObjectDelete(plane)); plane=nullptr;
211+
g_gc.GCClean();
212+
CHECK(rprObjectDelete(scene)); scene=nullptr;
286213
CHECK(rprObjectDelete(matsys)); matsys=nullptr;
287214
CheckNoLeak(context);
288215
CHECK(rprObjectDelete(context));context=nullptr; // Always delete the RPR Context in last.
Loading

tutorials/13_deformation_motion_blur/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ int main()
7878
CHECK( rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer) );
7979
CHECK( rprContextCreateFrameBuffer(context, fmt, &desc, &frame_buffer_resolved) );
8080

81-
// Clear framebuffer to black color
82-
CHECK( rprFrameBufferClear(frame_buffer) );
83-
8481
// Set framebuffer for the context
8582
CHECK( rprContextSetAOV(context, RPR_AOV_COLOR, frame_buffer) );
8683

@@ -228,7 +225,7 @@ int main()
228225
// Set transform for the light
229226
CHECK(rprLightSetTransform(light, RPR_TRUE, &lightm.m00));
230227

231-
// Set light radiant power in Watts
228+
// Set light radiant power
232229
CHECK(rprPointLightSetRadiantPower3f(light, 200, 200, 200));
233230

234231
// Attach the light to the scene
@@ -284,6 +281,7 @@ int main()
284281
// Progressively render an image
285282
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_DISPLAY_GAMMA , 2.2f ) ); // set display gamma
286283
CHECK(rprContextSetParameterByKey1u(context,RPR_CONTEXT_ITERATIONS,NUM_ITERATIONS));
284+
CHECK( rprFrameBufferClear(frame_buffer) );
287285
CHECK( rprContextRender(context) );
288286
CHECK(rprContextResolveFrameBuffer(context,frame_buffer,frame_buffer_resolved,false));
289287

0 commit comments

Comments
 (0)