|
| 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 | + |
0 commit comments