-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathdofrendermodule.h
115 lines (96 loc) · 3.95 KB
/
dofrendermodule.h
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
104
105
106
107
108
109
110
111
112
113
114
115
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "render/rendermodule.h"
#include "core/uimanager.h"
#include <FidelityFX/host/ffx_dof.h>
#include <vector>
namespace cauldron
{
class RootSignature;
class RasterView;
class ParameterSet;
class PipelineObject;
class Texture;
class Buffer;
} // namespace cauldron
/// @defgroup FfxDofSample FidelityFX Depth of Field sample
/// Sample documentation for FidelityFX Depth of Field
///
/// @ingroup SDKEffects
/// @defgroup DofRM DoFRenderModule
/// DoFRenderModule Reference Documentation
///
/// @ingroup FfxDofSample
/// @{
/**
* @class DoFRenderModule
* DOFRenderModule handles a number of tasks related to DOF.
*
* DoFRenderModule takes care of:
* - creating UI section that enable users to select DoF quality and lens model options
* - applying depth of field to the color target
*/
class DoFRenderModule : public cauldron::RenderModule
{
public:
/// Constructor with default behavior. Initializes parameters to sensible defaults for metric unit systems.
DoFRenderModule()
: RenderModule(L"DoFRenderModule")
{
}
/// Destructs the FFX API context and releases resources
virtual ~DoFRenderModule();
/// Initialize FFX API context and set up UI.
/// @param initData Not used.
void Init(const json& initData) override;
/// Update the DOF UI.
/// @param deltaTime Not used.
virtual void UpdateUI(double deltaTime) override;
/// Dispatch the DOF effect using FFX API and update the Focus Distance slider range according to the scene bounds.
/// @param deltaTime Not used.
/// @param pCmdList Command list on which to dispatch.
void Execute(double deltaTime, cauldron::CommandList* pCmdList) override;
/// Recreate the FFX API context to resize internal resources. Called by the framework when the resolution changes.
/// @param resInfo New resolution info.
void OnResize(const cauldron::ResolutionInfo& resInfo) override;
private:
void SetupFidelityFxInterface();
/// Destroy or create the FFX API context using the currently set parameters.
void UpdateDofContext(bool enabled);
void DestroyDofContext();
// Lens and quality parameters
float m_Aperture = 0.01f;
float m_FocusDist = 2.0f;
float m_SensorSize = 0.02f;
float m_CocLimit = 0.01f; // ~10px radius at 1080p
int m_Quality = 10;
bool m_EnableRingMerge = false;
cauldron::UISection* m_UISection = nullptr; // weak ptr
cauldron::UISlider<float>* m_UIFocusDist = nullptr; // weak ptr
// Effect resources
const cauldron::Texture* m_pColorTarget = nullptr;
const cauldron::Texture* m_pDepthTarget = nullptr;
// FidelityFX DoF information
FfxDofContextDescription m_InitializationParameters = {0};
FfxDofContext m_DofContext;
};