Skip to content

Commit 63546c9

Browse files
authored
Merge pull request #50 from GPUOpen-LibrariesAndSDKs/id_aov
Demo - more demo for AOVs
2 parents 09f5932 + 32ff66e commit 63546c9

File tree

1 file changed

+100
-2
lines changed

1 file changed

+100
-2
lines changed

tutorials/33_aov/main.cpp

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ int main()
8181
AOVlist.push_back(AOV_FB("geom_normal" ,RPR_AOV_GEOMETRIC_NORMAL, false));
8282
AOVlist.push_back(AOV_FB("shad_normal" ,RPR_AOV_SHADING_NORMAL, false));
8383
AOVlist.push_back(AOV_FB("obj_id" ,RPR_AOV_OBJECT_ID, false));
84+
AOVlist.push_back(AOV_FB("mat_id" ,RPR_AOV_MATERIAL_ID, false));
8485
AOVlist.push_back(AOV_FB("uv" ,RPR_AOV_UV, false));
8586

8687
// Create the list of AOVs
@@ -94,12 +95,109 @@ int main()
9495

9596
matballScene.Render("33_color.png");
9697

97-
// for each AOV, export it ot an image file and delete it.
98-
//
98+
// for each AOV, export it ot an image file
9999
for(auto& i : AOVlist)
100100
{
101101
CHECK( rprContextResolveFrameBuffer(context, i.framebuffer, i.framebuffer_res, !i.useDisplayGamma) );
102102
CHECK( rprFrameBufferSaveToFile(i.framebuffer_res, std::string("33_"+i.name+".png").c_str() ) );
103+
}
104+
105+
106+
// This is a demo for customized AOV lookup color :
107+
// For AOV representing ID ( like RPR_AOV_OBJECT_ID, RPR_AOV_MATERIAL_ID ), we can set custom colors for each ID instead of using the random colors assigned by the renderer.
108+
{
109+
std::cout<<"Demo for AOV lookup color..."<<std::endl;
110+
111+
// assign red to ID=0, green to ID=1 ... etc...
112+
CHECK( rprContextSetAOVindexLookup(context, 0, 1.0, 0.0, 0.0, 0.0) ); // red
113+
CHECK( rprContextSetAOVindexLookup(context, 1, 0.0, 1.0, 0.0, 0.0) ); // green
114+
CHECK( rprContextSetAOVindexLookup(context, 2, 0.0, 0.0, 1.0, 0.0) ); // blue
115+
CHECK( rprContextSetAOVindexLookup(context, 3, 1.0, 1.0, 0.0, 0.0) ); // yellow
116+
CHECK( rprContextSetAOVindexLookup(context, 4, 0.0, 1.0, 1.0, 0.0) ); // cyan
117+
CHECK( rprContextSetAOVindexLookup(context, 99, 1.0, 0.0, 1.0, 0.0) ); // magenta
118+
119+
// demo for the rprShapeSetObjectID function.
120+
// in this rendering, the inner ball will be rendered as mangenta inside the RPR_AOV_OBJECT_ID AOV. this is because the index 99 has been assigned to the magenta color
121+
CHECK( rprShapeSetObjectID(matBall0.inner, 99) );
122+
123+
// clear the framebuffers before starting a new rendering
124+
for(auto& i : AOVlist)
125+
{
126+
CHECK( rprFrameBufferClear(i.framebuffer) );
127+
}
128+
CHECK( rprFrameBufferClear(matballScene.m_frame_buffer) );
129+
130+
// render the scene
131+
CHECK( rprContextRender(matballScene.m_context) );
132+
133+
// resolve RPR_AOV_OBJECT_ID and RPR_AOV_MATERIAL_ID AOV, and export them to PNG.
134+
CHECK( rprContextResolveFrameBuffer(context, AOVlist[2].framebuffer, AOVlist[2].framebuffer_res, true) );
135+
CHECK( rprContextResolveFrameBuffer(context, AOVlist[3].framebuffer, AOVlist[3].framebuffer_res, true) );
136+
CHECK( rprFrameBufferSaveToFile(AOVlist[2].framebuffer_res, std::string("33_obj_id_2.png").c_str() ) );
137+
CHECK( rprFrameBufferSaveToFile(AOVlist[3].framebuffer_res, std::string("33_mat_id_2.png").c_str() ) );
138+
139+
// You will notice that colors from 33_obj_id_2.png are different compared to 33_obj_id.png.
140+
// Same thing for 33_mat_id.
141+
}
142+
143+
144+
// This is a demo for integer framebuffer
145+
// For AOV representing ID ( like RPR_AOV_OBJECT_ID, RPR_AOV_MATERIAL_ID ), we can choose to export them as 32bits integer format framebuffer instead of 3-float colors.
146+
{
147+
std::cout<<"Demo for integer framebuffer..."<<std::endl;
148+
149+
// create an Integer framebuffer :
150+
rpr_framebuffer framebuffer_INT_objID = nullptr;
151+
rpr_framebuffer framebuffer_INT_objID_resolve = nullptr;
152+
rpr_framebuffer_format fmt_INT = {4, RPR_COMPONENT_TYPE_UINT32}; // note that we use the UINT32 format, instead of FLOAT32
153+
CHECK( rprContextCreateFrameBuffer(context, fmt_INT, &matballScene.m_framebuffer_desc, &framebuffer_INT_objID) );
154+
CHECK( rprContextCreateFrameBuffer(context, fmt_INT, &matballScene.m_framebuffer_desc, &framebuffer_INT_objID_resolve) );
155+
156+
// assign this AOV to store Object ID
157+
CHECK( rprContextSetAOV(context, RPR_AOV_OBJECT_ID, framebuffer_INT_objID) );
158+
159+
// set the floor shape ID to 0x12345678
160+
CHECK( rprShapeSetObjectID(matballScene.m_shape_floor, 0x12345678) );
161+
162+
// clear color framebuffer before rendering ( because it's was used previously )
163+
CHECK( rprFrameBufferClear(matballScene.m_frame_buffer) );
164+
165+
// render the scene
166+
CHECK( rprContextRender(matballScene.m_context) );
167+
168+
// resolve the Object ID framebuffer
169+
CHECK( rprContextResolveFrameBuffer(context, framebuffer_INT_objID, framebuffer_INT_objID_resolve, true) );
170+
171+
// read data from the resolved Object ID framebuffer.
172+
size_t frame_buffer_resolve_dataSize = 0;
173+
CHECK( rprFrameBufferGetInfo(framebuffer_INT_objID_resolve, RPR_FRAMEBUFFER_DATA, 0 , NULL , &frame_buffer_resolve_dataSize ) );
174+
uint32_t* frame_buffer_resolve_data = (uint32_t*)malloc(frame_buffer_resolve_dataSize);
175+
CHECK( rprFrameBufferGetInfo(framebuffer_INT_objID_resolve, RPR_FRAMEBUFFER_DATA, frame_buffer_resolve_dataSize , frame_buffer_resolve_data , NULL ) );
176+
177+
// data of the first pixel:
178+
frame_buffer_resolve_data[0]; // <-- this value will be 0x12345678 because this pixel represents the floor shape
179+
frame_buffer_resolve_data[1];
180+
frame_buffer_resolve_data[2];
181+
frame_buffer_resolve_data[3];
182+
183+
// data of the second pixel:
184+
frame_buffer_resolve_data[4]; // <-- same value than frame_buffer_resolve_data[0]
185+
frame_buffer_resolve_data[5];
186+
frame_buffer_resolve_data[6];
187+
frame_buffer_resolve_data[7];
188+
189+
printf("frame_buffer_resolve_data[0] = 0x%x\n" , frame_buffer_resolve_data[0]);
190+
191+
// clear stuff from this demo.
192+
free(frame_buffer_resolve_data); frame_buffer_resolve_data=nullptr;
193+
CHECK( rprObjectDelete(framebuffer_INT_objID) );
194+
CHECK( rprObjectDelete(framebuffer_INT_objID_resolve) );
195+
}
196+
197+
198+
// delete AOVs
199+
for(auto& i : AOVlist)
200+
{
103201
CHECK( rprObjectDelete(i.framebuffer) );
104202
CHECK( rprObjectDelete(i.framebuffer_res) );
105203
}

0 commit comments

Comments
 (0)