Skip to content

Commit f8b5a83

Browse files
committed
Tutorials - improve parameter enum demo
1 parent 331c43d commit f8b5a83

File tree

6 files changed

+236
-95
lines changed

6 files changed

+236
-95
lines changed
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*****************************************************************************\
2+
*
3+
* Module Name Parameter Enumeration Demo
4+
* Project Radeon ProRender rendering tutorial
5+
*
6+
* Description Radeon ProRender SDK tutorials
7+
*
8+
* Copyright(C) 2011-2021 Advanced Micro Devices, Inc. All rights reserved.
9+
*
10+
\*****************************************************************************/
11+
12+
#include "RadeonProRender.h"
13+
14+
#include "../common/common.h"
15+
#include <iostream>
16+
#include <vector>
17+
#include <string>
18+
#include "../rprTools/RPRStringIDMapper.h"
19+
20+
//
21+
// This tutorials illustrates how to use getters of the RPR API to get current states/values of different objects.
22+
//
23+
24+
25+
int main()
26+
{
27+
std::cout << "Radeon ProRender SDK parameters enumeration tutorial.\n";
28+
29+
// Create the RPR context
30+
rpr_context context = nullptr;
31+
rpr_int tahoePluginID = rprRegisterPlugin(RPR_PLUGIN_FILE_NAME);
32+
CHECK_NE(tahoePluginID , -1);
33+
rpr_int plugins[] = { tahoePluginID };
34+
size_t pluginCount = sizeof(plugins) / sizeof(plugins[0]);
35+
CHECK( rprCreateContext(RPR_API_VERSION, plugins, pluginCount, RPR_CREATION_FLAGS_ENABLE_GPU0, NULL, NULL, &context) );
36+
CHECK( rprContextSetActivePlugin(context, plugins[0]) );
37+
std::cout << "Context successfully created.\n";
38+
39+
// class defined in rprTools/RPRStringIDMapper.h .
40+
// this class helps to turn parameters id into strings.
41+
RPRStringIDMapper stringMapper;
42+
43+
44+
//
45+
// List parameters from rpr_context
46+
//
47+
{
48+
std::cout<<std::endl<<"=== CONTEXT PARAMETERS ==="<<std::endl;
49+
50+
uint64_t param_count = 0;
51+
CHECK( rprContextGetInfo(context, RPR_CONTEXT_PARAMETER_COUNT, sizeof(uint64_t), &param_count, NULL) );
52+
53+
std::cout<<param_count<<" parameters :"<<std::endl;
54+
55+
for (uint64_t i = 0; i < param_count; i++)
56+
{
57+
rpr_context_info paramID = (rpr_context_info)0;
58+
CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_NAME, sizeof(paramID), &paramID, NULL) );
59+
60+
std::string paramName_;
61+
stringMapper.RPRContextInput_id_to_string(paramID, paramName_);
62+
63+
rpr_parameter_type type;
64+
CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_TYPE, sizeof(type), &type, NULL));
65+
66+
uint64_t value_length = 0;
67+
CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_VALUE, 0, NULL, &value_length) );
68+
char* paramValue = nullptr;
69+
if (value_length > 0)
70+
{
71+
paramValue = new char[value_length];
72+
CHECK( rprContextGetParameterInfo(context, int(i), RPR_PARAMETER_VALUE, value_length, paramValue, NULL) );
73+
}
74+
75+
std::cout<<paramName_<<" = ";
76+
77+
if ( type == RPR_PARAMETER_TYPE_STRING )
78+
{
79+
std::cout<<"\""<<std::string(paramValue)<<"\"";
80+
}
81+
else if ( type == RPR_PARAMETER_TYPE_FLOAT )
82+
{
83+
float f = *(float*)(paramValue);
84+
std::cout<<f;
85+
}
86+
else if ( type == RPR_PARAMETER_TYPE_FLOAT2 )
87+
{
88+
float* f = (float*)(paramValue);
89+
std::cout<<f[0]<<" , "<<f[1];
90+
}
91+
else if ( type == RPR_PARAMETER_TYPE_FLOAT3 )
92+
{
93+
float* f = (float*)(paramValue);
94+
std::cout<<f[0]<<" , "<<f[1]<<" , "<<f[2];
95+
}
96+
else if ( type == RPR_PARAMETER_TYPE_FLOAT4 )
97+
{
98+
float* f = (float*)(paramValue);
99+
std::cout<<f[0]<<" , "<<f[1]<<" , "<<f[2]<<" , "<<f[3];
100+
}
101+
else if ( type == RPR_PARAMETER_TYPE_UINT )
102+
{
103+
rpr_uint v = *(rpr_uint*)(paramValue);
104+
std::cout<<v;
105+
}
106+
else if ( type == RPR_PARAMETER_TYPE_ULONG )
107+
{
108+
rpr_ulong v = *(rpr_ulong*)(paramValue);
109+
std::cout<<v;
110+
}
111+
else if ( type == RPR_PARAMETER_TYPE_LONGLONG )
112+
{
113+
rpr_longlong v = *(rpr_longlong*)(paramValue);
114+
std::cout<<v;
115+
}
116+
else
117+
{
118+
std::cout<<"???";
119+
}
120+
121+
if ( paramValue ) { delete[] paramValue; paramValue = NULL; }
122+
123+
std::cout<<std::endl;
124+
}
125+
}
126+
127+
128+
// create the material system
129+
rpr_material_system matsys = nullptr;
130+
CHECK( rprContextCreateMaterialSystem(context, 0, &matsys) );
131+
132+
// Create a MICROFACET material
133+
rpr_material_node microfacet;
134+
CHECK( rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_MICROFACET, &microfacet) );
135+
136+
//
137+
// List parameters from rpr_material
138+
//
139+
{
140+
std::cout<<std::endl<<"=== MATERIAL PARAMETERS ==="<<std::endl;
141+
142+
// Get the number of parameters for the material
143+
size_t num_params = 0;
144+
CHECK( rprMaterialNodeGetInfo(microfacet, RPR_MATERIAL_NODE_INPUT_COUNT, sizeof(size_t), &num_params , NULL));
145+
146+
std::cout << "Number of MICROFACET material parameters: " << num_params <<"\n";
147+
148+
// get the material type.
149+
rpr_material_node_type nodeType = (rpr_material_node_type)0;
150+
CHECK( rprMaterialNodeGetInfo(microfacet,RPR_MATERIAL_NODE_TYPE, sizeof(nodeType),&nodeType,NULL));
151+
// in this example, we have nodeType = RPR_MATERIAL_NODE_MICROFACET
152+
153+
// For each parameter
154+
for (size_t i = 0; i < num_params; ++i)
155+
{
156+
157+
rpr_material_node_input paramNameID = (rpr_material_node_input)0;
158+
CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_NAME, sizeof(paramNameID), &paramNameID, NULL));
159+
160+
std::string paramName_;
161+
stringMapper.RPRMaterialInput_id_to_string(paramNameID, paramName_);
162+
163+
std::cout<<paramName_<<" = ";
164+
165+
rpr_uint nodeInputType = 0;
166+
CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_TYPE, sizeof(nodeInputType), &nodeInputType, NULL) );
167+
168+
uint64_t inputValueSizeB = 0;
169+
CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_VALUE, 0, NULL, &inputValueSizeB));
170+
char* materialParameterValue = new char[inputValueSizeB];
171+
CHECK( rprMaterialNodeGetInputInfo(microfacet, i, RPR_MATERIAL_NODE_INPUT_VALUE, inputValueSizeB, materialParameterValue, NULL));
172+
173+
if ( nodeInputType == RPR_MATERIAL_NODE_INPUT_TYPE_NODE )
174+
{
175+
rpr_material_node* mat = (rpr_material_node*)materialParameterValue;
176+
if ( *mat )
177+
{
178+
std::cout<<"material:"<<(void*)(*mat);
179+
}
180+
else
181+
{
182+
std::cout<<"null-material";
183+
}
184+
}
185+
else if ( nodeInputType == RPR_MATERIAL_NODE_INPUT_TYPE_FLOAT4 )
186+
{
187+
float* f = (float*)(materialParameterValue);
188+
std::cout<<f[0]<<" , "<<f[1]<<" , "<<f[2]<<" , "<<f[3];
189+
}
190+
else
191+
{
192+
std::cout<<"???";
193+
}
194+
195+
if ( materialParameterValue ) { delete[] materialParameterValue; materialParameterValue = NULL; }
196+
197+
std::cout<<std::endl;
198+
199+
}
200+
}
201+
202+
CHECK(rprObjectDelete(matsys)); matsys=nullptr;
203+
CHECK(rprObjectDelete(microfacet)); microfacet=nullptr;
204+
CheckNoLeak(context);
205+
CHECK(rprObjectDelete(context)); context=nullptr;
206+
return 0;
207+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
project "03_parameters_enumeration"
2+
kind "ConsoleApp"
3+
location "../build"
4+
files { "../03_parameters_enumeration/**.h", "../03_parameters_enumeration/**.cpp"}
5+
files { "../common/common.cpp","../common/common.h"}
6+
files { "../../RadeonProRender/rprTools/RPRStringIDMapper.cpp","../../RadeonProRender/rprTools/RPRStringIDMapper.h"}
7+
8+
-- remove filters for Visual Studio
9+
vpaths { [""] = {
10+
"../03_parameters_enumeration/**.h", "../03_parameters_enumeration/**.cpp",
11+
"../common/common.cpp","../common/common.h",
12+
"../../RadeonProRender/rprTools/RPRStringIDMapper.cpp", "../../RadeonProRender/rprTools/RPRStringIDMapper.h"
13+
} }
14+
15+
includedirs{ "../../RadeonProRender/inc" }
16+
17+
buildoptions "-std=c++11"
18+
19+
configuration {"x64"}
20+
links {"RadeonProRender64"}
21+
22+
configuration {"x64", "Debug"}
23+
targetdir "../Bin"
24+
configuration {"x64", "Release"}
25+
targetdir "../Bin"
26+
configuration {}
27+
3.67 KB
Loading

tutorials/parameters_enumeration/parameters_enumeration.cpp

Lines changed: 0 additions & 95 deletions
This file was deleted.

tutorials/premake5.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ solution "Tutorials"
7474
defines{ "RPR_API_USE_HEADER_V2" } -- make sure to use the API V2: it's a safer C API
7575

7676
include "00_context_creation"
77+
include "03_parameters_enumeration"
7778
include "05_basic_scene"
7879
include "13_deformation_motion_blur"
7980
include "21_material"

tutorials/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ List of tutorials in this SDK
66
| Model | Screenshot | Description |
77
|------------------------------------------------------------|-----------------------------------------------------|-------------|
88
| [Context Creation](00_context_creation) | ![](00_context_creation/screenshot.png) | This demo shows how to create a RPR context. The RPR context is the first object that needs to be created before any RPR renderings. |
9+
| [Parameters Enumeration](03_parameters_enumeration) | ![](03_parameters_enumeration/screenshot.png) | This tutorials illustrates how to use getters of the RPR API to get current states/values of different objects. |
910
| [Basic Scene](05_basic_scene) | ![](05_basic_scene/screenshot.png) | This demo is a good starting point to learn all the basic features of RPR. You'll learn how to manage geometry, light, camera, framebuffer, materials for simple cubes renderings. |
1011
| [Deformation Motion Blur](13_deformation_motion_blur) | ![](13_deformation_motion_blur/screenshot.png) | This demo covers vertices deformation over time for a blur effect. |
1112
| [Material](21_material) | ![](21_material/screenshot.png) | This demo illustrates how to create materials in RPR. It's not covering the UBER material which is used inside the 22_material_uber demo. |

0 commit comments

Comments
 (0)