-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhowTo02_CreateOneFramePass.cpp
More file actions
103 lines (74 loc) · 3.43 KB
/
Copy pathhowTo02_CreateOneFramePass.cpp
File metadata and controls
103 lines (74 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2025 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
#include <RenderingFramework/TestContextCreator.h>
#include <hvt/engine/viewportEngine.h>
#include <gtest/gtest.h>
#include <RenderingFramework/TestFlags.h>
//
// How to create one frame pass using Storm?
//
HVT_TEST(howTo, createOneFramePass)
{
// Helper to create the Hgi implementation.
auto context = TestHelpers::CreateTestContext();
TestHelpers::TestStage stage(context->_backend);
ASSERT_TRUE(stage.open(context->_sceneFilepath));
hvt::RenderIndexProxyPtr renderIndex;
hvt::FramePassPtr sceneFramePass;
// Defines the main frame pass i.e., the one containing the scene to display.
{
// Creates the render index by providing the hgi driver and the requested renderer name.
hvt::RendererDescriptor renderDesc;
renderDesc.hgiDriver = &context->_backend->hgiDriver();
renderDesc.rendererName = "HdStormRendererPlugin";
hvt::ViewportEngine::CreateRenderer(renderIndex, renderDesc);
// Creates the scene index containing the model.
pxr::HdSceneIndexBaseRefPtr sceneIndex =
hvt::ViewportEngine::CreateUSDSceneIndex(stage.stage());
renderIndex->RenderIndex()->InsertSceneIndex(sceneIndex, pxr::SdfPath::AbsoluteRootPath());
// Creates the frame pass instance.
hvt::FramePassDescriptor passDesc;
passDesc.renderIndex = renderIndex->RenderIndex();
passDesc.uid = pxr::SdfPath("/sceneFramePass");
sceneFramePass = hvt::ViewportEngine::CreateFramePass(passDesc);
}
// Renders 10 times (i.e., arbitrary number to guarantee best result).
int frameCount = 10;
auto render = [&]()
{
// Updates the main frame pass.
auto& params = sceneFramePass->params();
params.renderBufferSize = pxr::GfVec2i(context->width(), context->height());
params.viewInfo.framing =
hvt::ViewParams::GetDefaultFraming(context->width(), context->height());
params.viewInfo.viewMatrix = stage.viewMatrix();
params.viewInfo.projectionMatrix = stage.projectionMatrix();
params.viewInfo.lights = stage.defaultLights();
params.viewInfo.material = stage.defaultMaterial();
params.viewInfo.ambient = stage.defaultAmbient();
params.colorspace = pxr::HdxColorCorrectionTokens->sRGB;
params.backgroundColor = TestHelpers::ColorDarkGrey;
params.selectionColor = TestHelpers::ColorYellow;
params.enablePresentation = context->presentationEnabled();
sceneFramePass->Render();
return --frameCount > 0;
};
// Runs the render loop (i.e., that's backend specific).
context->run(render, sceneFramePass.get());
// Validates the rendering result.
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
}