Skip to content

Commit 7aa29ae

Browse files
committed
Propose shadow-cone tracing for final frame render.
1 parent 388cc39 commit 7aa29ae

File tree

6 files changed

+232
-116
lines changed

6 files changed

+232
-116
lines changed

src/apps/ch11_voxel/ch11_voxel/FrameGraph.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ void FrameGraph::loadPrograms()
208208
}
209209

210210

211+
GLfloat toTanHalf(math::Radian<GLfloat> aAngle)
212+
{
213+
return math::tan(aAngle / 2.f);
214+
}
215+
211216
void FrameGraph::renderFinalScene(const scenic::SceneTree & aSceneTree,
212217
Voxelizer & aVoxelizer)
213218
{
@@ -221,9 +226,11 @@ void FrameGraph::renderFinalScene(const scenic::SceneTree & aSceneTree,
221226
graphics::setUniform(program, "u_VoxelSize", aVoxelizer.mVoxelSize);
222227
graphics::setUniform(program, "u_AabbMin", aVoxelizer.mSceneAabb.leftBottomZMin());
223228

224-
graphics::setUniform(program, "u_TanHalfAperture", mFrameControl.mConeAperture.data());
229+
graphics::setUniform(program, "u_TanHalfAperture", toTanHalf(mFrameControl.mDiffuseConeAperture));
230+
graphics::setUniform(program, "u_TanHalfShadow", toTanHalf(mFrameControl.mShadowConeAperture));
225231

226232
graphics::setUniform(program, "u_ToneMapping", (GLuint)mFrameControl.mToneMapping);
233+
graphics::setUniform(program, "u_ShadowMethod", (GLuint)mFrameControl.mFinalSceneShadow);
227234

228235
glProgramUniform4fv(program,
229236
glGetUniformLocation(program, "u_LightingFactors"),
@@ -242,7 +249,7 @@ void FrameGraph::renderConeTrace(const scenic::SceneTree & aSceneTree,
242249
graphics::setUniform(program, "u_VoxelSize", aVoxelizer.mVoxelSize);
243250
graphics::setUniform(program, "u_AabbMin", aVoxelizer.mSceneAabb.leftBottomZMin());
244251

245-
graphics::setUniform(program, "u_TanHalfAperture", mFrameControl.mConeAperture.data());
252+
graphics::setUniform(program, "u_TanHalfAperture", toTanHalf(mFrameControl.mDiffuseConeAperture));
246253
graphics::setUniform(program, "u_GridAlign", mFrameControl.mGridAlign);
247254

248255
graphics::setUniform(program, "u_ConeTraceMode", aMode);
@@ -296,7 +303,8 @@ void FrameGraph::appendUi()
296303
imguiui::addComboContinuousEnum<FrameControl::ToneMapping::_End>(
297304
"Tone Mapping", mFrameControl.mToneMapping);
298305

299-
ImGui::SliderAngle("Diffuse Cone Aperture", &mFrameControl.mConeAperture.data(), 1.f, 180.f);
306+
ImGui::SliderAngle("Diffuse Cone Aperture", &mFrameControl.mDiffuseConeAperture.data(), 1.f, 180.f);
307+
ImGui::SliderAngle("Shadow Cone Aperture", &mFrameControl.mShadowConeAperture.data(), 1.f, 180.f);
300308

301309
ImGui::Checkbox("Grid Aligned Trace Origin", &mFrameControl.mGridAlign);
302310

@@ -307,6 +315,8 @@ void FrameGraph::appendUi()
307315
ImGui::SliderFloat("Indirect specular", &mFrameControl.mIndirectSpecularFactor, 0.f, 4.f);
308316

309317
ImGui::SeparatorText("Shadow");
318+
imguiui::addComboContinuousEnum<FrameControl::ShadowMethod::_End>(
319+
"Final Scene Shadow", mFrameControl.mFinalSceneShadow);
310320
ImGui::InputFloat("Scale", &mFrameControl.mShadowScaleBias.x());
311321
ImGui::InputFloat("Bias", &mFrameControl.mShadowScaleBias.y());
312322
}
@@ -327,4 +337,18 @@ std::string to_string(FrameGraph::FrameControl::ToneMapping aValue)
327337
#undef STR
328338
}
329339

340+
341+
std::string to_string(FrameGraph::FrameControl::ShadowMethod aValue)
342+
{
343+
#define STR(enumerator) case FrameGraph::FrameControl::ShadowMethod::enumerator: return #enumerator
344+
switch (aValue)
345+
{
346+
STR(ShadowMap);
347+
STR(ConeTracing);
348+
default:
349+
throw std::logic_error{ "Unhandled shadow method." };
350+
}
351+
#undef STR
352+
}
353+
330354
} // namespace ad

src/apps/ch11_voxel/ch11_voxel/FrameGraph.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,22 @@ struct FrameGraph
4343
_End/* keep last */
4444
};
4545

46+
enum class ShadowMethod : GLuint
47+
{
48+
ShadowMap,
49+
ConeTracing,
50+
_End/* keep last */
51+
};
52+
4653
decltype(gPolygonModes)::const_iterator mPolygonMode = gPolygonModes.begin() + 2;
4754

4855
ToneMapping mToneMapping = ToneMapping::AcesApprox;
4956

50-
math::Radian<GLfloat> mConeAperture = math::Degree<GLfloat>{30.f};
57+
ShadowMethod mFinalSceneShadow = ShadowMethod::ShadowMap;
58+
59+
// Aperture means full angle (2 * angle to the axis)
60+
math::Radian<GLfloat> mDiffuseConeAperture = math::Degree<GLfloat>{60.f};
61+
math::Radian<GLfloat> mShadowConeAperture = math::Degree<GLfloat>{10.f};
5162
bool mGridAlign = false;
5263

5364
float mDirectDiffuseFactor{1.0f};

src/apps/ch11_voxel/ch11_voxel/Scene.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,18 @@ void Scene::presentUi(bool * aOpen)
567567
ImGui::Checkbox("Show Punctual Lights", &mSceneControl.mShowPunctualLights);
568568
ImGui::Checkbox("Draw BB", &mSceneControl.mDrawBoundingBoxes);
569569

570-
ImGui::SeparatorText("Voxelization:");
571570
mVoxelizationRequest |= ImGui::Button("Force voxelize");
572-
mVoxelizationRequest |= ImGui::Checkbox("Dominant Axis Method", &mVoxelizer.mControl.mUseDominantAxis);
573-
mVoxelizationRequest |= ImGui::Checkbox("Conservative Rasterization", &mVoxelizer.mControl.mConservativeRasterization);
574-
mVoxelizationRequest |= ImGui::Checkbox("Conservative Depth Range", &mVoxelizer.mControl.mConservativeDepthRange);
575-
mVoxelizationRequest |= ImGui::Checkbox("Average Samples in Voxel", &mVoxelizer.mControl.mAverageSamples);
576-
mVoxelizationRequest |= ImGui::Checkbox("Average Normals by axis", &mVoxelizer.mControl.mAverageNormalByAxis);
577-
mVoxelizationRequest |= ImGui::Checkbox("Trace linear filtering", &mVoxelizer.mControl.mLinearFiltering);
578-
mVoxelizationRequest |= ImGui::Checkbox("Compute Shader Irradiance Filtering", &mVoxelizer.mControl.mComputeIrradianceMipmapping);
579-
ImGui::Checkbox("Voxel POV", &mSceneControl.mVoxelPov);
571+
if (ImGui::CollapsingHeader("Voxelization"))
572+
{
573+
mVoxelizationRequest |= ImGui::Checkbox("Dominant Axis Method", &mVoxelizer.mControl.mUseDominantAxis);
574+
mVoxelizationRequest |= ImGui::Checkbox("Conservative Rasterization", &mVoxelizer.mControl.mConservativeRasterization);
575+
mVoxelizationRequest |= ImGui::Checkbox("Conservative Depth Range", &mVoxelizer.mControl.mConservativeDepthRange);
576+
mVoxelizationRequest |= ImGui::Checkbox("Average Samples in Voxel", &mVoxelizer.mControl.mAverageSamples);
577+
mVoxelizationRequest |= ImGui::Checkbox("Average Normals by axis", &mVoxelizer.mControl.mAverageNormalByAxis);
578+
mVoxelizationRequest |= ImGui::Checkbox("Trace linear filtering", &mVoxelizer.mControl.mLinearFiltering);
579+
mVoxelizationRequest |= ImGui::Checkbox("Compute Shader Irradiance Filtering", &mVoxelizer.mControl.mComputeIrradianceMipmapping);
580+
ImGui::Checkbox("Voxel POV", &mSceneControl.mVoxelPov);
581+
}
580582

581583
DearImguiWitness witness;
582584

src/apps/ch11_voxel/ch11_voxel/ShaderConstants.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ namespace ad {
4747
result.emplace_back(
4848
"CLIENT_TONEMAPPING_ACESAPPROX "
4949
+ std::to_string((GLuint)FrameGraph::FrameControl::ToneMapping::AcesApprox));
50+
result.emplace_back(
51+
"CLIENT_SHADOW_SHADOWMAP "
52+
+ std::to_string((GLuint)FrameGraph::FrameControl::ShadowMethod::ShadowMap));
53+
result.emplace_back(
54+
"CLIENT_SHADOW_CONETRACING "
55+
+ std::to_string((GLuint)FrameGraph::FrameControl::ShadowMethod::ConeTracing));
5056
return result;
5157
}
5258

0 commit comments

Comments
 (0)