Skip to content

Commit df3ddf0

Browse files
committed
Demo - add Contour and Toon Material
1 parent 8e12f80 commit df3ddf0

File tree

14 files changed

+502
-7
lines changed

14 files changed

+502
-7
lines changed

tutorials/21_material/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int main()
7070

7171
MatballScene matballScene;
7272

73-
MatballScene::MATBALL matBall0 = matballScene.Init(context);
73+
MatballScene::MATBALL matBall0 = matballScene.Init(context,0,0);
7474

7575

7676
// demo for a Layered material : blending a DIFFUSE and a MICROFACET

tutorials/22_material_uber/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int main()
7070

7171
MatballScene matballScene;
7272

73-
MatballScene::MATBALL matBall0 = matballScene.Init(context);
73+
MatballScene::MATBALL matBall0 = matballScene.Init(context,0,0);
7474

7575
{
7676
rpr_material_node material = nullptr;

tutorials/24_contour/main.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*****************************************************************************\
2+
*
3+
* Module Name Contour 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+
#include "RadeonProRender.h"
12+
#include "Math/mathutils.h"
13+
#include "../common/common.h"
14+
15+
#include <cassert>
16+
#include <iostream>
17+
18+
19+
//
20+
// Demo of the Contour Rendering (also called Outline) that allows you to render contours of 3D objects.
21+
//
22+
//
23+
24+
25+
int main()
26+
{
27+
28+
// for Debugging you can enable Radeon ProRender API trace
29+
// set this before any RPR API calls
30+
// rprContextSetParameterByKey1u(0,RPR_CONTEXT_TRACING_ENABLED,1);
31+
32+
33+
// the RPR context object.
34+
rpr_context context = nullptr;
35+
36+
// Register the RPR DLL
37+
rpr_int tahoePluginID = rprRegisterPlugin(RPR_PLUGIN_FILE_NAME);
38+
CHECK_NE(tahoePluginID , -1);
39+
rpr_int plugins[] = { tahoePluginID };
40+
size_t pluginCount = sizeof(plugins) / sizeof(plugins[0]);
41+
42+
// Create context using a single GPU
43+
// note that multiple GPUs can be enabled for example with creation_flags = RPR_CREATION_FLAGS_ENABLE_GPU0 | RPR_CREATION_FLAGS_ENABLE_GPU1
44+
CHECK( rprCreateContext(RPR_API_VERSION, plugins, pluginCount, g_ContextCreationFlags, NULL, NULL, &context) );
45+
46+
// Set the active plugin.
47+
CHECK( rprContextSetActivePlugin(context, plugins[0]) );
48+
49+
std::cout << "RPR Context creation succeeded." << std::endl;
50+
51+
// create the matball scene.
52+
MatballScene matballScene;
53+
MatballScene::MATBALL matBall0 = matballScene.Init(context,0,0);
54+
55+
56+
//
57+
// For any Contour Rendering, we always need 4 AOV : RPR_AOV_MATERIAL_ID, RPR_AOV_SHADING_NORMAL, RPR_AOV_OBJECT_ID, RPR_AOV_UV
58+
//
59+
rpr_framebuffer fb_matid = nullptr;
60+
CHECK( rprContextCreateFrameBuffer(context, matballScene.m_framebuffer_fmt, &matballScene.m_framebuffer_desc, &fb_matid) );
61+
CHECK( rprContextSetAOV(context, RPR_AOV_MATERIAL_ID, fb_matid) );
62+
63+
rpr_framebuffer fb_shadNormal = nullptr;
64+
CHECK( rprContextCreateFrameBuffer(context, matballScene.m_framebuffer_fmt, &matballScene.m_framebuffer_desc, &fb_shadNormal) );
65+
CHECK( rprContextSetAOV(context, RPR_AOV_SHADING_NORMAL, fb_shadNormal) );
66+
67+
rpr_framebuffer fb_objId = nullptr;
68+
CHECK( rprContextCreateFrameBuffer(context, matballScene.m_framebuffer_fmt, &matballScene.m_framebuffer_desc, &fb_objId) );
69+
CHECK( rprContextSetAOV(context, RPR_AOV_OBJECT_ID, fb_objId) );
70+
71+
rpr_framebuffer fb_uv = nullptr;
72+
CHECK( rprContextCreateFrameBuffer(context, matballScene.m_framebuffer_fmt, &matballScene.m_framebuffer_desc, &fb_uv) );
73+
CHECK( rprContextSetAOV(context, RPR_AOV_UV, fb_uv) );
74+
75+
// Enable the Contour Rendering
76+
CHECK( rprContextSetParameterByKeyString(context, RPR_CONTEXT_GPUINTEGRATOR, "gpucontour") );
77+
78+
79+
//
80+
// Set the contour parameters
81+
//
82+
83+
CHECK( rprContextSetParameterByKey1u(context, RPR_CONTEXT_CONTOUR_USE_OBJECTID, 1) );
84+
CHECK( rprContextSetParameterByKey1u(context, RPR_CONTEXT_CONTOUR_USE_MATERIALID, 1) );
85+
CHECK( rprContextSetParameterByKey1u(context, RPR_CONTEXT_CONTOUR_USE_NORMAL, 1) );
86+
CHECK( rprContextSetParameterByKey1u(context, RPR_CONTEXT_CONTOUR_USE_UV, 0) ); // we don't want to use UV in this contour rendering
87+
88+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_NORMAL_THRESHOLD, 20.0) );
89+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_UV_THRESHOLD, 0.03) );
90+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_LINEWIDTH_OBJECTID, 3) );
91+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_LINEWIDTH_MATERIALID, 1) );
92+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_LINEWIDTH_NORMAL, 2.0f) );
93+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_LINEWIDTH_UV, 1.0f) );
94+
CHECK( rprContextSetParameterByKey1f(context, RPR_CONTEXT_CONTOUR_ANTIALIASING, 1) );
95+
96+
97+
// render the scene
98+
matballScene.Render("24_contour.png");
99+
100+
101+
// Delete RPR nodes.
102+
CHECK( rprObjectDelete(fb_matid) ); fb_matid=nullptr;
103+
CHECK( rprObjectDelete(fb_shadNormal) ); fb_shadNormal=nullptr;
104+
CHECK( rprObjectDelete(fb_objId) ); fb_objId=nullptr;
105+
CHECK( rprObjectDelete(fb_uv) ); fb_uv=nullptr;
106+
matballScene.Clean();
107+
CheckNoLeak(context);
108+
CHECK(rprObjectDelete(context)); context=nullptr;
109+
return 0;
110+
111+
}
112+
113+
114+
115+
116+

tutorials/24_contour/premake4.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project "24_contour"
2+
kind "ConsoleApp"
3+
location "../build"
4+
files { "../24_contour/**.h", "../24_contour/**.cpp"}
5+
files { "../common/common.cpp","../common/common.h"}
6+
7+
-- remove filters for Visual Studio
8+
vpaths { [""] = { "../24_contour/**.h", "../24_contour/**.cpp","../common/common.cpp","../common/common.h"} }
9+
10+
11+
includedirs{ "../../RadeonProRender/inc" }
12+
13+
buildoptions "-std=c++11"
14+
15+
configuration {"x64"}
16+
links {"RadeonProRender64"}
17+
18+
configuration {"x64", "Debug"}
19+
targetdir "../Bin"
20+
configuration {"x64", "Release"}
21+
targetdir "../Bin"
22+
configuration {}
23+

tutorials/24_contour/screenshot.png

6.65 KB
Loading

0 commit comments

Comments
 (0)