Skip to content

Commit 0cc5787

Browse files
author
Alin
committed
added depth for schoolls draw keys
1 parent 70df44c commit 0cc5787

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

example/ThreadedRenderingGL/School.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,20 @@ void School::UpdateInstanceDataBuffer()
691691
m_pInstanceData->EndUpdate();
692692
}
693693

694-
uint32_t School::Render(uint32_t batchSize, GeometryCommandBuffer& geometryCommands)
694+
uint32_t School::Render(const nv::matrix4f& projView, uint32_t batchSize, GeometryCommandBuffer& geometryCommands)
695695
{
696696
uint32_t drawCallCount = 0;
697697
if (nullptr == m_pInstancedModel)
698698
{
699699
return drawCallCount;
700700
}
701701

702+
// draw closest opaque first for early-z culling
703+
nv::vec4f position = projView * nv::vec4f(m_lastCentroid.x, 1.f);
704+
float invDepth = (1.f - position.z / position.w);
705+
invDepth *= 10000.f;
706+
m_pInstancedModel->DrawKey().setDepth(invDepth);
707+
702708
m_pInstancedModel->SetBatchSize(batchSize);
703709
drawCallCount += m_pInstancedModel->Render(geometryCommands, 0, 1, 2);
704710

example/ThreadedRenderingGL/School.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class School
285285
/// Render the school using GL commands and structures
286286
/// \param batchSize Number of instances rendered per draw call
287287
/// \return Returns the number of draw calls invoked during the Render call
288-
uint32_t Render(uint32_t batchSize, GeometryCommandBuffer& geometryCommands);
288+
uint32_t Render(const nv::matrix4f& projView, uint32_t batchSize, GeometryCommandBuffer& geometryCommands);
289289

290290
/// Set the values used by the flocking simulation that drives the school
291291
/// \param params A SchoolFlockingParams object initialized with the

example/ThreadedRenderingGL/ThreadedRenderingGL.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ void ThreadedRenderingGL::animateJobFunction(uint32_t threadIndex)
272272
// its update). In our fixed school size case, this is not an issue, so
273273
// thread utilization should not be significantly impacted.
274274

275+
const nv::matrix4f projView = m_projUBO_Data.m_projectionMatrix * m_projUBO_Data.m_viewMatrix;
276+
275277
schoolsDone = me.m_schoolCount;
276278
if (!m_animPaused || m_forceUpdateMode != ForceUpdateMode::eNone)
277279
{
@@ -288,7 +290,7 @@ void ThreadedRenderingGL::animateJobFunction(uint32_t threadIndex)
288290
m_schools[i]->Update(m_geometryCommands);
289291
}
290292
// Dispatch render commands
291-
m_schoolsDrawCount[i] = m_schools[i]->Render(m_uiBatchSize, m_geometryCommands);
293+
m_schoolsDrawCount[i] = m_schools[i]->Render(projView, m_uiBatchSize, m_geometryCommands);
292294
}
293295
}
294296

@@ -532,8 +534,9 @@ void ThreadedRenderingGL::helperJobFunction()
532534
drawCmd.texGBuffer[i] = m_texGBuffer[i];
533535
CB_DEBUG_COMMAND_TAG(drawCmd);
534536

535-
if(i > 4)
537+
if(i > 4 || !m_useVolumetricLights)
536538
continue;
539+
537540
transform.make_identity();
538541
transform.set_scale(lightRadius * 0.005f + 0.5f);
539542
transform.set_translate(nv::vec3f(position));
@@ -629,6 +632,7 @@ ThreadedRenderingGL::ThreadedRenderingGL() :
629632
m_pFishplosionVar(nullptr),
630633
m_animPaused(false),
631634
m_avoidance(true),
635+
m_useVolumetricLights(true),
632636
m_currentTime(0.0f),
633637
m_forceUpdateMode(ForceUpdateMode::eNone),
634638
m_bUIDirty(true),
@@ -1210,6 +1214,8 @@ void ThreadedRenderingGL::initUI(void)
12101214
&m_pBatchSlider, &m_pBatchVar);
12111215
mTweakBar->addMenu("Mode", m_uiRenderingTechnique, &(RENDER_TECHNIQUES[0]), TECHNIQUE_GLAZDO_POOLED, UIACTION_RENDERINGTECHNIQUE);
12121216
mTweakBar->addMenu("BRDF", (uint32_t&)m_brdf, &(BRDF_OPTIONS[0]), BRDF_COUNT, UIACTION_UIBRDF);
1217+
var = mTweakBar->addValue("Use Volumetric Lights", m_useVolumetricLights);
1218+
addTweakKeyBind(var, NvKey::K_V);
12131219

12141220
mTweakBar->addPadding();
12151221
mTweakBar->addLabel("Animation Settings", true);

example/ThreadedRenderingGL/ThreadedRenderingGL.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ class ThreadedRenderingGL : public NvSampleAppGL
521521
// Flag indicating whether schools should be aware of each other and
522522
// attempt to avoid each other
523523
bool m_avoidance;
524+
bool m_useVolumetricLights;
524525

525526
// Current application time in seconds
526527
float m_currentTime;

example/ThreadedRenderingGL/assets/src_shaders/volumetric_FS.glsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
// Based on: Volumetric Light Scattering as a Post-Process by Kenny Mitchell
3+
24
#version 310 es
35

46
precision mediump float;
@@ -43,4 +45,4 @@ void main()
4345
illuminationDecay *= decay;
4446
}
4547
outColor = vec4(color * uExposure, 1.0);
46-
}
48+
}

0 commit comments

Comments
 (0)