Skip to content

Commit 2bae2a0

Browse files
committed
froxel vizualization can now be turned on/off per view
Before this change once the froxel vizualizaition was enabled via the Engine debug framework, it applied to all views. This adds a debug API on View to control whether the view will display this vizualization.
1 parent f34bb3d commit 2bae2a0

File tree

10 files changed

+26
-5
lines changed

10 files changed

+26
-5
lines changed

filament/include/filament/View.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ class UTILS_PUBLIC View : public FilamentAPI {
757757
//! debugging: returns a Camera from the point of view of *the* dominant directional light used for shadowing.
758758
utils::FixedCapacityVector<Camera const*> getDirectionalShadowCameras() const noexcept;
759759

760+
//! debugging: enable or disable froxel visualisation for this view.
761+
void setFroxelVizEnabled(bool enabled) noexcept;
760762

761763
/** Result of a picking query */
762764
struct PickingQueryResult {

filament/src/View.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ utils::FixedCapacityVector<Camera const*> View::getDirectionalShadowCameras() co
7777
return downcast(this)->getDirectionalShadowCameras();
7878
}
7979

80+
void View::setFroxelVizEnabled(bool const enabled) noexcept {
81+
downcast(this)->setFroxelVizEnabled(enabled);
82+
}
83+
8084
void View::setShadowingEnabled(bool const enabled) noexcept {
8185
downcast(this)->setShadowingEnabled(enabled);
8286
}

filament/src/details/View.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void FView::prepare(FEngine& engine, DriverApi& driver, RootArenaScope& rootAren
662662
cameraInfo.projection, cameraInfo.zn, cameraInfo.zf)) {
663663
// TODO: might be more consistent to do this in prepareLighting(), but it's not
664664
// strictly necessary
665-
getColorPassDescriptorSet().prepareDynamicLights(mFroxelizer);
665+
getColorPassDescriptorSet().prepareDynamicLights(mFroxelizer, mFroxelVizEnabled);
666666
}
667667
// We need to pass viewMatrix by value here because it extends the scope of this
668668
// function.

filament/src/details/View.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ class FView : public View {
240240
return mShadowMapManager->getDirectionalShadowCameras();
241241
}
242242

243+
void setFroxelVizEnabled(bool const enabled) noexcept {
244+
mFroxelVizEnabled = enabled;
245+
}
246+
243247
void setRenderTarget(FRenderTarget* renderTarget) noexcept {
244248
assert_invariant(!renderTarget || !mMultiSampleAntiAliasingOptions.enabled ||
245249
!renderTarget->hasSampleableDepth());
@@ -552,6 +556,7 @@ class FView : public View {
552556

553557
mutable Froxelizer mFroxelizer;
554558
utils::JobSystem::Job* mFroxelizerSync = nullptr;
559+
bool mFroxelVizEnabled = false;
555560

556561
Viewport mViewport;
557562
bool mCulling = true;

filament/src/ds/ColorPassDescriptorSet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,13 @@ void ColorPassDescriptorSet::prepareAmbientLight(FEngine const& engine, FIndirec
372372
});
373373
}
374374

375-
void ColorPassDescriptorSet::prepareDynamicLights(Froxelizer& froxelizer) noexcept {
375+
void ColorPassDescriptorSet::prepareDynamicLights(Froxelizer& froxelizer, bool const enableFroxelViz) noexcept {
376376
auto& s = mUniforms.edit();
377377
froxelizer.updateUniforms(s);
378378
float const f = froxelizer.getLightFar();
379379
// TODO: make the falloff rate a parameter
380380
s.lightFarAttenuationParams = 0.5f * float2{ 10.0f, 10.0f / (f * f) };
381+
s.enableFroxelViz = enableFroxelViz;
381382
}
382383

383384
void ColorPassDescriptorSet::prepareShadowMapping(BufferObjectHandle shadowUniforms) noexcept {

filament/src/ds/ColorPassDescriptorSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ColorPassDescriptorSet {
118118
void prepareAmbientLight(FEngine const& engine,
119119
FIndirectLight const& ibl, float intensity, float exposure) noexcept;
120120

121-
void prepareDynamicLights(Froxelizer& froxelizer) noexcept;
121+
void prepareDynamicLights(Froxelizer& froxelizer, bool enableFroxelViz) noexcept;
122122

123123
void prepareShadowVSM(TextureHandle texture,
124124
VsmShadowOptions const& options) noexcept;

libs/filabridge/include/private/filament/UibStructs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ struct PerViewUib { // NOLINT(cppcoreguidelines-pro-type-member-init)
120120
math::uint3 fParams; // stride-x, stride-y, stride-z
121121
int32_t lightChannels; // light channel bits
122122
math::float2 froxelCountXY;
123+
int enableFroxelViz;
124+
int dynReserved0;
125+
int dynReserved1;
126+
int dynReserved2;
123127

124128
// IBL
125129
float iblLuminance;
@@ -204,7 +208,7 @@ struct PerViewUib { // NOLINT(cppcoreguidelines-pro-type-member-init)
204208
float es2Reserved2;
205209

206210
// bring PerViewUib to 2 KiB
207-
math::float4 reserved[39];
211+
math::float4 reserved[38];
208212
};
209213

210214
// 2 KiB == 128 float4s

libs/filamat/src/shaders/UibGenerator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ BufferInterfaceBlock const& UibGenerator::getPerViewUib() noexcept {
140140
{ "fParams", 0, Type::UINT3 },
141141
{ "lightChannels", 0, Type::INT },
142142
{ "froxelCountXY", 0, Type::FLOAT2 },
143+
{ "enableFroxelViz", 0, Type::INT },
144+
{ "dynReserved0", 0, Type::INT },
145+
{ "dynReserved1", 0, Type::INT },
146+
{ "dynReserved2", 0, Type::INT },
143147

144148
{ "iblLuminance", 0, Type::FLOAT, Precision::DEFAULT, FeatureLevel::FEATURE_LEVEL_0 },
145149
{ "iblRoughnessOneLevel", 0, Type::FLOAT, Precision::DEFAULT, FeatureLevel::FEATURE_LEVEL_0 },

libs/filamentapp/src/FilamentApp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback,
192192
mScene = mEngine->createScene();
193193

194194
window->mMainView->getView()->setVisibleLayers(0x4, 0x4);
195+
window->mMainView->getView()->setFroxelVizEnabled(true);
195196

196197
if (config.splitView) {
197198
auto& rcm = mEngine->getRenderableManager();

shaders/src/surface_light_punctual.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void evaluatePunctualLights(const MaterialInputs material,
247247
}
248248

249249
if (CONFIG_DEBUG_FROXEL_VISUALIZATION) {
250-
if (froxel.count > 0u) {
250+
if (froxel.count > 0u && frameUniforms.enableFroxelViz != 0) {
251251
const vec3 debugColors[17] = vec3[](
252252
vec3(0.0, 0.0, 0.0), // black
253253
vec3(0.0, 0.0, 0.1647), // darkest blue

0 commit comments

Comments
 (0)