Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PreRenderBatch.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_PRE_RENDER_BATCH_H_
34#define DVD_PRE_RENDER_BATCH_H_
35
36#include "PreRenderOperator.h"
38
39namespace Divide {
40
41FWD_DECLARE_MANAGED_CLASS(ShaderBuffer);
42
43class PostFX;
44class ShaderProgram;
45
47{
48 enum class MapFunctions : U8
49 {
52 GT,
53 ACES,
58 COUNT
59 };
60
61 U16 _width{ 1u };
62 U16 _height{ 1u };
65 F32 _tau{ 1.1f };
66
68
70};
71
72namespace Names {
73 static const char* toneMapFunctions[] = {
74 "REINHARD", "REINHARD_MODIFIED", "GT", "ACES", "UNREAL_ACES", "AMD_ACES", "GT_DIFF_PARAMETERS", "UNCHARTED_2", "NONE"
75 };
76}
77
78namespace TypeUtil {
79 [[nodiscard]] const char* ToneMapFunctionsToString(ToneMapParams::MapFunctions stop) noexcept;
80 [[nodiscard]] ToneMapParams::MapFunctions StringToToneMapFunctions(const string& name);
81};
82
84 private:
85 struct HDRTargets {
88 };
89
90 struct LDRTargets {
92 };
93
97 bool _swappedHDR{ false };
98 bool _swappedLDR{ false };
99 };
100
102
103 public:
104 // Ordered by cost
105 enum class EdgeDetectionMethod : U8 {
106 Depth = 0,
107 Luma,
108 Colour,
109 COUNT
110 };
111
112 public:
115
116 [[nodiscard]] PostFX& parent() const noexcept { return _parent; }
117
118 void update(U64 deltaTimeUS) noexcept;
119
120 void prePass(PlayerIndex idx, const CameraSnapshot& cameraSnapshot, U32 filterStack, GFX::CommandBuffer& bufferInOut);
121 void execute(PlayerIndex idx, const CameraSnapshot& cameraSnapshot, U32 filterStack, GFX::CommandBuffer& bufferInOut);
122 void reshape(U16 width, U16 height);
123
124 void onFilterToggle(FilterType filter, bool state);
125
126 [[nodiscard]] RenderTargetHandle getInput(bool hdr) const;
127 [[nodiscard]] RenderTargetHandle getOutput(bool hdr) const;
128
129 [[nodiscard]] RenderTargetHandle screenRT() const noexcept;
130 [[nodiscard]] RenderTargetHandle edgesRT() const noexcept;
131 [[nodiscard]] Handle<Texture> luminanceTex() const noexcept;
132
133 [[nodiscard]] PreRenderOperator* getOperator(FilterType type) const;
134
135 void toneMapParams(ToneMapParams params) noexcept;
136
137 void adaptiveExposureControl(bool state) noexcept;
138
139 [[nodiscard]] F32 adaptiveExposureValue() const noexcept;
140 [[nodiscard]] RenderTargetHandle getLinearDepthRT() const noexcept;
141
144 PROPERTY_RW(F32, edgeDetectionThreshold, 0.1f);
147
148 private:
149
150 [[nodiscard]] inline static FilterSpace GetOperatorSpace(const FilterType type) noexcept {
151 // ToDo: Always keep this up-to-date with every filter we add
152 switch(type) {
163 case FilterType::FILTER_VIGNETTE: break;
164 }
165
166 return FilterSpace::COUNT;
167 }
168
169 [[nodiscard]] bool operatorsReady() const noexcept;
170
171 [[nodiscard]] RenderTargetHandle getTarget(bool hdr, bool swapped) const noexcept;
172
173 private:
176
180
182 ShaderBuffer_uptr _histogramBuffer{ nullptr };
183 Handle<Texture> _currentLuminance{ INVALID_HANDLE<Texture> };
184 Handle<ShaderProgram> _toneMap{ INVALID_HANDLE<ShaderProgram> };
185 Handle<ShaderProgram> _toneMapAdaptive{ INVALID_HANDLE<ShaderProgram> };
186 Handle<ShaderProgram> _createHistogram{ INVALID_HANDLE<ShaderProgram> };
187 Handle<ShaderProgram> _averageHistogram{ INVALID_HANDLE<ShaderProgram> };
188 Handle<ShaderProgram> _lineariseDepthBuffer{ INVALID_HANDLE<ShaderProgram> };
189
195
198
201};
202
203} // namespace Divide
204#endif //DVD_PRE_RENDER_BATCH_H_
205
206#include "PreRenderBatch.inl"
#define PROPERTY_RW(...)
Convenience method to add a class member with public read access and write access.
#define PROPERTY_R(...)
Convenience method to add a class member with public read access but protected write access.
#define FWD_DECLARE_MANAGED_CLASS(T)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
Definition: PostFX.h:47
RenderTargetHandle _sceneEdges
bool operatorsReady() const noexcept
RenderTargetHandle screenRT() const noexcept
PreRenderOperator * getOperator(FilterType type) const
ScreenTargets _screenRTs
void toneMapParams(ToneMapParams params) noexcept
RenderTargetHandle edgesRT() const noexcept
Handle< Texture > _currentLuminance
static FilterSpace GetOperatorSpace(const FilterType type) noexcept
void execute(PlayerIndex idx, const CameraSnapshot &cameraSnapshot, U32 filterStack, GFX::CommandBuffer &bufferInOut)
Handle< ShaderProgram > _lineariseDepthBuffer
std::array< OperatorBatch, to_base(FilterSpace::COUNT)> _operators
Handle< ShaderProgram > _createHistogram
void prePass(PlayerIndex idx, const CameraSnapshot &cameraSnapshot, U32 filterStack, GFX::CommandBuffer &bufferInOut)
vector< PreRenderOperator_uptr > OperatorBatch
PostFX & parent() const noexcept
Pipeline * _pipelineToneMapAdaptive
Handle< Texture > luminanceTex() const noexcept
RenderTargetHandle _linearDepthRT
RenderTargetHandle getInput(bool hdr) const
Handle< ShaderProgram > _toneMap
void update(U64 deltaTimeUS) noexcept
std::array< Handle< ShaderProgram >, to_base(EdgeDetectionMethod::COUNT)> _edgeDetection
RenderTargetHandle getTarget(bool hdr, bool swapped) const noexcept
Handle< ShaderProgram > _toneMapAdaptive
void adaptiveExposureControl(bool state) noexcept
F32 adaptiveExposureValue() const noexcept
ShaderBuffer_uptr _histogramBuffer
void onFilterToggle(FilterType filter, bool state)
Handle< ShaderProgram > _averageHistogram
std::array< Pipeline *, to_base(EdgeDetectionMethod::COUNT)> _edgeDetectionPipelines
RenderTargetHandle getLinearDepthRT() const noexcept
RenderTargetHandle getOutput(bool hdr) const
Pipeline * _pipelineLumCalcHistogram
Pipeline * _pipelineLumCalcAverage
void reshape(U16 width, U16 height)
An API-independent representation of a texture.
Definition: Texture.h:83
static const char * toneMapFunctions[]
const char * ToneMapFunctionsToString(ToneMapParams::MapFunctions stop) noexcept
ToneMapParams::MapFunctions StringToToneMapFunctions(const string &name)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
uint16_t U16
uint32_t U32
uint64_t U64
constexpr auto to_base(const Type value) -> Type
MapFunctions _function