@@ -71,22 +71,41 @@ int main()
71
71
// Set transform for the light
72
72
CHECK (rprLightSetTransform (light, RPR_TRUE, &lightm.m00 ));
73
73
// Set light radiant power in Watts
74
- CHECK (rprPointLightSetRadiantPower3f (light, 100 , 100 , 100 ));
74
+ CHECK (rprPointLightSetRadiantPower3f (light, 80 , 80 , 80 ));
75
75
// Attach the light to the scene
76
76
CHECK (rprSceneAttachLight (scene, light));
77
77
}
78
+
79
+ // Create env light
80
+ rpr_light env_light = nullptr ;
81
+ rpr_image env_img = nullptr ;
82
+ {
83
+ CHECK (rprContextCreateEnvironmentLight (context, &env_light));
84
+
85
+ const std::string pathImageFile = " ../../Resources/Textures/envLightImage.exr" ;
86
+ CHECK (rprContextCreateImageFromFile (context, pathImageFile.c_str (), &env_img));
87
+ if (status == RPR_ERROR_IO_ERROR)
88
+ {
89
+ std::cout << " Error : " << pathImageFile << " not found.\n " ;
90
+ return -1 ;
91
+ }
92
+
93
+ // Set an image for the light to take the radiance values from
94
+ CHECK (rprEnvironmentLightSetImage (env_light, env_img));
95
+
96
+ // Set IBL as a background for the scene
97
+ CHECK (rprSceneAttachLight (scene, env_light));
98
+ }
99
+
78
100
// Create camera
79
101
rpr_camera camera=nullptr ;
80
102
{
81
103
CHECK ( rprContextCreateCamera (context, &camera) );
82
104
83
105
// Position camera in world space:
84
- // Camera position is (5,5,20)
85
- // Camera aimed at (0,0,0)
86
- // Camera up vector is (0,1,0)
87
- CHECK ( rprCameraLookAt (camera, 0 , 5 , 80 , 0 , 1 , 0 , 0 , 1 , 0 ) );
106
+ CHECK ( rprCameraLookAt (camera, 5 , 5 , 20 , 0 , 0 , 0 , 0 , 1 , 0 ) );
88
107
89
- CHECK ( rprCameraSetFocalLength (camera, 75 .f ) );
108
+ CHECK ( rprCameraSetFocalLength (camera, 10 .f ) );
90
109
91
110
// Set camera for the scene
92
111
CHECK ( rprSceneSetCamera (scene, camera) );
@@ -134,8 +153,8 @@ int main()
134
153
{
135
154
CHECK (rprMaterialSystemCreateNode (matsys, RPR_MATERIAL_NODE_DIFFUSE, &diffuse));
136
155
137
- // Set diffuse color parameter to gray
138
- CHECK (rprMaterialNodeSetInputFByKey (diffuse, RPR_MATERIAL_INPUT_COLOR, 0 .5f , 0 . 5f , 0 .5f , 1 .f ));
156
+ // Set diffuse color parameter
157
+ CHECK (rprMaterialNodeSetInputFByKey (diffuse, RPR_MATERIAL_INPUT_COLOR, 0 .5f , 1 . 0f , 0 .5f , 1 .f ));
139
158
140
159
// Set shader for cube & plane meshes
141
160
CHECK (rprShapeSetMaterial (cube, diffuse));
@@ -161,17 +180,23 @@ int main()
161
180
162
181
163
182
// Progressively render an image
164
- CHECK (rprContextSetParameterByKey1u (context,RPR_CONTEXT_ITERATIONS,NUM_ITERATIONS ));
183
+ CHECK (rprContextSetParameterByKey1u (context,RPR_CONTEXT_ITERATIONS,128 ));
165
184
CHECK ( rprContextRender (context) );
166
185
CHECK (rprContextResolveFrameBuffer (context,frame_buffer,frame_buffer_resolved,true ));
167
186
187
+ // This can be uncommented to see the framebuffer
188
+ // CHECK( rprFrameBufferSaveToFile(frame_buffer_resolved, "31_temp.png") );
189
+
168
190
// /////// Framebuffer Access Tutorial //////////
191
+ //
192
+ // We are going to take the frame_buffer_resolved data, and use it as a material texture for a plane.
169
193
170
- size_t size;
194
+ size_t size = 0 ;
171
195
CHECK (rprFrameBufferGetInfo (frame_buffer_resolved, RPR_FRAMEBUFFER_DATA, 0 , NULL , &size));
172
196
float * buffer = new float [size / sizeof (float )];
173
197
CHECK (rprFrameBufferGetInfo (frame_buffer_resolved, RPR_FRAMEBUFFER_DATA, size, buffer, 0 ));
174
198
199
+
175
200
// Apply this buffer as a texture
176
201
177
202
rpr_material_node diffuse1=nullptr ;
@@ -181,27 +206,43 @@ int main()
181
206
rpr_image_format format;
182
207
format.num_components = 4 ;
183
208
format.type = RPR_COMPONENT_TYPE_FLOAT32;
184
- rpr_image_desc desc ;
185
- desc .image_width = 800 ;
186
- desc .image_height = 600 ;
187
- desc .image_row_pitch = 0 ;
188
- desc .image_slice_pitch = 0 ;
189
- desc .image_depth = 1 ;
209
+ rpr_image_desc desc2 ;
210
+ desc2 .image_width = desc. fb_width ;
211
+ desc2 .image_height = desc. fb_height ;
212
+ desc2 .image_row_pitch = 0 ;
213
+ desc2 .image_slice_pitch = 0 ;
214
+ desc2 .image_depth = 0 ;
190
215
191
- CHECK (rprContextCreateImage (context, format, &desc , buffer, &img1));
216
+ CHECK (rprContextCreateImage (context, format, &desc2 , buffer, &img1));
192
217
CHECK (rprMaterialSystemCreateNode (matsys, RPR_MATERIAL_NODE_IMAGE_TEXTURE, &tex));
193
218
// Set image data
194
219
CHECK (rprMaterialNodeSetInputImageDataByKey (tex, RPR_MATERIAL_INPUT_DATA, img1));
195
220
CHECK (rprMaterialSystemCreateNode (matsys, RPR_MATERIAL_NODE_DIFFUSE, &diffuse1));
196
221
// Set diffuse color parameter to gray
222
+
197
223
CHECK (rprMaterialNodeSetInputNByKey (diffuse1, RPR_MATERIAL_INPUT_COLOR, tex));
224
+ // CHECK(rprMaterialNodeSetInputFByKey(diffuse1, RPR_MATERIAL_INPUT_COLOR, 1,0,0,0));
225
+
198
226
CHECK (rprShapeSetMaterial (plane, diffuse1));
199
227
}
200
228
201
229
// Remove the cube and turn plane to dislay the texture in front of us like a screenshot
202
230
CHECK (rprSceneDetachShape (scene, cube));
203
231
RadeonProRender::matrix m = RadeonProRender::rotation (RadeonProRender::float3 (1 , 0 , 0 ), -PI / 2 .0f );
204
232
CHECK (rprShapeSetTransform (plane, RPR_TRUE, &m.m00 ));
233
+
234
+ // set camera to point on the plane
235
+ CHECK ( rprCameraSetFocalLength (camera, 75 .f ) );
236
+ CHECK ( rprCameraLookAt (camera, 0 , 0 , 150 , 0 , 0 , 0 , 0 , 1 , 0 ) );
237
+
238
+ // move point light
239
+ RadeonProRender::matrix lightm = RadeonProRender::translation (RadeonProRender::float3 (1 , 1 , 100 ));
240
+ CHECK (rprLightSetTransform (light, RPR_TRUE, &lightm.m00 ));
241
+ CHECK (rprPointLightSetRadiantPower3f (light, 30000 , 30000 , 30000 ));
242
+
243
+ // remove the env light
244
+ CHECK (rprSceneDetachLight (scene, env_light));
245
+
205
246
// Clear the buffer to render again
206
247
rprFrameBufferClear (frame_buffer);
207
248
@@ -212,6 +253,7 @@ int main()
212
253
std::cout << " Rendering finished.\n " ;
213
254
214
255
// delete buffer;
256
+ delete[] buffer; buffer=nullptr ;
215
257
216
258
// Save the result to file
217
259
CHECK ( rprFrameBufferSaveToFile (frame_buffer_resolved, " 31.png" ) );
@@ -221,6 +263,8 @@ int main()
221
263
CHECK (rprObjectDelete (img1));img1=nullptr ;
222
264
CHECK (rprObjectDelete (diffuse1));diffuse1=nullptr ;
223
265
CHECK (rprObjectDelete (matsys));matsys=nullptr ;
266
+ CHECK (rprObjectDelete (env_light));env_light=nullptr ;
267
+ CHECK (rprObjectDelete (env_img));env_img=nullptr ;
224
268
CHECK (rprObjectDelete (plane));plane=nullptr ;
225
269
CHECK (rprObjectDelete (cube));cube=nullptr ;
226
270
CHECK (rprObjectDelete (light));light=nullptr ;
0 commit comments