MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / loadScene

Method loadScene

Source/Samples/HelloDXR/HelloDXR.cpp:126–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126void HelloDXR::loadScene(const std::filesystem::path& path, const Fbo* pTargetFbo)
127{
128 mpScene = Scene::create(getDevice(), path);
129 mpCamera = mpScene->getCamera();
130
131 // Update the controllers
132 float radius = mpScene->getSceneBounds().radius();
133 mpScene->setCameraSpeed(radius * 0.25f);
134 float nearZ = std::max(0.1f, radius / 750.0f);
135 float farZ = radius * 10;
136 mpCamera->setDepthRange(nearZ, farZ);
137 mpCamera->setAspectRatio((float)pTargetFbo->getWidth() / (float)pTargetFbo->getHeight());
138
139 // Get shader modules and type conformances for types used by the scene.
140 // These need to be set on the program in order to use Falcor's material system.
141 auto shaderModules = mpScene->getShaderModules();
142 auto typeConformances = mpScene->getTypeConformances();
143
144 // Get scene defines. These need to be set on any program using the scene.
145 auto defines = mpScene->getSceneDefines();
146
147 // Create raster pass.
148 // This utility wraps the creation of the program and vars, and sets the necessary scene defines.
149 ProgramDesc rasterProgDesc;
150 rasterProgDesc.addShaderModules(shaderModules);
151 rasterProgDesc.addShaderLibrary("Samples/HelloDXR/HelloDXR.3d.slang").vsEntry("vsMain").psEntry("psMain");
152 rasterProgDesc.addTypeConformances(typeConformances);
153
154 mpRasterPass = RasterPass::create(getDevice(), rasterProgDesc, defines);
155
156 // We'll now create a raytracing program. To do that we need to setup two things:
157 // - A program description (ProgramDesc). This holds all shader entry points, compiler flags, macro defintions,
158 // etc.
159 // - A binding table (RtBindingTable). This maps shaders to geometries in the scene, and sets the ray generation and
160 // miss shaders.
161 //
162 // After setting up these, we can create the Program and associated RtProgramVars that holds the variable/resource
163 // bindings. The Program can be reused for different scenes, but RtProgramVars needs to binding table which is
164 // Scene-specific and needs to be re-created when switching scene. In this example, we re-create both the program
165 // and vars when a scene is loaded.
166
167 ProgramDesc rtProgDesc;
168 rtProgDesc.addShaderModules(shaderModules);
169 rtProgDesc.addShaderLibrary("Samples/HelloDXR/HelloDXR.rt.slang");
170 rtProgDesc.addTypeConformances(typeConformances);
171 rtProgDesc.setMaxTraceRecursionDepth(3); // 1 for calling TraceRay from RayGen, 1 for calling it from the
172 // primary-ray ClosestHit shader for reflections, 1 for reflection ray
173 // tracing a shadow ray
174 rtProgDesc.setMaxPayloadSize(24); // The largest ray payload struct (PrimaryRayData) is 24 bytes. The payload size
175 // should be set as small as possible for maximum performance.
176
177 ref<RtBindingTable> sbt = RtBindingTable::create(2, 2, mpScene->getGeometryCount());
178 sbt->setRayGen(rtProgDesc.addRayGen("rayGen"));
179 sbt->setMiss(0, rtProgDesc.addMiss("primaryMiss"));
180 sbt->setMiss(1, rtProgDesc.addMiss("shadowMiss"));
181 auto primary = rtProgDesc.addHitGroup("primaryClosestHit", "primaryAnyHit");
182 auto shadow = rtProgDesc.addHitGroup("", "shadowAnyHit");
183 sbt->setHitGroup(0, mpScene->getGeometryIDs(Scene::GeometryType::TriangleMesh), primary);

Callers

nothing calls this directly

Calls 15

setCameraSpeedMethod · 0.80
getWidthMethod · 0.80
getHeightMethod · 0.80
getSceneDefinesMethod · 0.80
getGeometryCountMethod · 0.80
setRayGenMethod · 0.80
addRayGenMethod · 0.80
setMissMethod · 0.80
addMissMethod · 0.80
addHitGroupMethod · 0.80
setHitGroupMethod · 0.80
getGeometryIDsMethod · 0.80

Tested by

no test coverage detected