Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PostFX.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_POST_EFFECTS_H_
34#define DVD_POST_EFFECTS_H_
35
36#include "PreRenderBatch.h"
38
39namespace Divide {
40
41class Quad3D;
42class Camera;
43class GFXDevice;
44class ShaderProgram;
45class Texture;
46
47class PostFX final : public PlatformContextComponent {
48private:
49 enum class FXDisplayFunction : U8 {
50 Vignette = 0,
51 Noise,
53 Normal,
55 COUNT
56 };
57
58 enum class FXRoutines : U8 {
59 Vignette = 0,
60 Noise,
61 Screen,
62 COUNT
63 };
64
65public:
67 ~PostFX() override;
68
69 void prePass(PlayerIndex idx, const CameraSnapshot& cameraSnapshot,GFX::CommandBuffer& bufferInOut);
70 void apply(PlayerIndex idx, const CameraSnapshot& cameraSnapshot, GFX::CommandBuffer& bufferInOut);
71
72 void idle(const Configuration& config, U64 deltaTimeUSGame);
73 void update(U64 deltaTimeUSFixed, U64 deltaTimeUSApp);
74
75 void updateResolution(U16 newWidth, U16 newHeight);
76
77 void pushFilter(const FilterType filter, const bool overrideScene = false)
78 {
79 if (!getFilterState(filter))
80 {
81 if (overrideScene)
82 {
83 _overrideFilterStack |= 1u << to_U32(filter);
84 }
85 else
86 {
87 _filterStack |= 1u << to_U32(filter);
88 }
89 _filtersDirty = true;
90 getFilterBatch().onFilterToggle(filter, true);
91 }
92 }
93
94 void popFilter(const FilterType filter, const bool overrideScene = false)
95 {
96 if (getFilterState(filter))
97 {
98 if (overrideScene)
99 {
100 _overrideFilterStack &= ~(1u << to_U32(filter));
101 }
102 else
103 {
104 _filterStack &= ~(1u << to_U32(filter));
105 }
106 _filtersDirty = true;
107 getFilterBatch().onFilterToggle(filter, false);
108 }
109 }
110
111 [[nodiscard]] bool getFilterState(const FilterType filter) const noexcept
112 {
113 const U32 filterMask = 1u << to_U32(filter);
114
115 return (_filterStack & filterMask) ||
116 (_overrideFilterStack & filterMask);
117 }
118
119 [[nodiscard]] PreRenderBatch& getFilterBatch() noexcept
120 {
121 return _preRenderBatch;
122 }
123
124 // fade the screen to the specified colour lerping over the specified time interval
125 // set durationMS to instantly set fade colour
126 // optionally, set a callback when fade out completes
127 // waitDurationMS = how much time to wait before calling the completion callback after fade out completes
128 void setFadeOut(const UColour3& targetColour, D64 durationMS, D64 waitDurationMS, DELEGATE<void> onComplete = DELEGATE<void>());
129 // clear any fading effect currently active over the specified time interval
130 // set durationMS to instantly clear the fade effect
131 // optionally, set a callback when fade in completes
132 void setFadeIn(D64 durationMS, DELEGATE<void> onComplete = DELEGATE<void>());
133 // fade out to specified colour and back again within the given time slice
134 // if duration is 0.0, nothing happens
135 // waitDurationMS is the amount of time to wait before fading back in
136 void setFadeOutIn(const UColour3& targetColour, D64 durationFadeOutMS, D64 waitDurationMS);
137 void setFadeOutIn(const UColour3& targetColour, D64 durationFadeOutMS, D64 durationFadeInMS, D64 waitDurationMS);
138
139 [[nodiscard]] static const char* FilterName(FilterType filter) noexcept;
140
141 // Use this to change various PostFX settings that depend on the time of day (e.g. exterior cube reflections, LUT correction, etc)
142 PROPERTY_RW(bool, isDayTime, true);
143private:
145
146 Handle<Texture> _screenBorder = INVALID_HANDLE<Texture>;
147 Handle<Texture> _noise = INVALID_HANDLE<Texture>;
148 Handle<Texture> _underwaterTexture = INVALID_HANDLE<Texture>;
149
152
153 Handle<ShaderProgram> _postProcessingShader = INVALID_HANDLE<ShaderProgram>;
155
157
158 //fade settings
162 bool _fadeOut = false;
163 bool _fadeActive = false;
166
169
170 bool _filtersDirty = true;
171
175};
176
178
179} // namespace Divide
180
181#endif //DVD_POST_EFFECTS_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
PlatformContext & context() noexcept
Definition: PostFX.h:47
void setFadeOutIn(const UColour3 &targetColour, D64 durationFadeOutMS, D64 waitDurationMS)
Definition: PostFX.cpp:322
D64 _fadeWaitDurationMS
Definition: PostFX.h:161
void popFilter(const FilterType filter, const bool overrideScene=false)
Definition: PostFX.h:94
F32 _randomNoiseCoefficient
Definition: PostFX.h:150
GFX::SetCameraCommand _setCameraCmd
Definition: PostFX.h:174
void update(U64 deltaTimeUSFixed, U64 deltaTimeUSApp)
Definition: PostFX.cpp:252
D64 _noiseTimer
Definition: PostFX.h:151
bool getFilterState(const FilterType filter) const noexcept
Definition: PostFX.h:111
vec2< U16 > _resolutionCache
Definition: PostFX.h:154
void idle(const Configuration &config, U64 deltaTimeUSGame)
Definition: PostFX.cpp:232
void setFadeOut(const UColour3 &targetColour, D64 durationMS, D64 waitDurationMS, DELEGATE< void > onComplete=DELEGATE< void >())
Definition: PostFX.cpp:298
DELEGATE< void > _fadeOutComplete
Definition: PostFX.h:164
U32 _overrideFilterStack
Definition: PostFX.h:168
~PostFX() override
Definition: PostFX.cpp:119
void prePass(PlayerIndex idx, const CameraSnapshot &cameraSnapshot, GFX::CommandBuffer &bufferInOut)
Definition: PostFX.cpp:143
PreRenderBatch & getFilterBatch() noexcept
Definition: PostFX.h:119
void setFadeIn(D64 durationMS, DELEGATE< void > onComplete=DELEGATE< void >())
Definition: PostFX.cpp:312
PreRenderBatch _preRenderBatch
Definition: PostFX.h:144
D64 _targetFadeTimeMS
Definition: PostFX.h:160
Handle< Texture > _screenBorder
Definition: PostFX.h:146
U32 _filterStack
Definition: PostFX.h:167
D64 _tickInterval
Definition: PostFX.h:151
FXDisplayFunction
Definition: PostFX.h:49
@ Underwater
@ COUNT
@ Normal
@ Noise
@ Vignette
@ PassThrough
bool _fadeOut
Definition: PostFX.h:162
bool _fadeActive
Definition: PostFX.h:163
Pipeline * _drawPipeline
Definition: PostFX.h:172
D64 _currentFadeTimeMS
Definition: PostFX.h:159
PROPERTY_RW(bool, isDayTime, true)
UniformData _uniformData
Definition: PostFX.h:173
void apply(PlayerIndex idx, const CameraSnapshot &cameraSnapshot, GFX::CommandBuffer &bufferInOut)
Definition: PostFX.cpp:154
F32 _randomFlashCoefficient
Definition: PostFX.h:150
Handle< Texture > _underwaterTexture
Definition: PostFX.h:148
Handle< ShaderProgram > _postProcessingShader
Definition: PostFX.h:153
Handle< Texture > _noise
Definition: PostFX.h:147
RTDrawDescriptor _postFXTarget
Definition: PostFX.h:156
void pushFilter(const FilterType filter, const bool overrideScene=false)
Definition: PostFX.h:77
static const char * FilterName(FilterType filter) noexcept
Definition: PostFX.cpp:27
FXRoutines
Definition: PostFX.h:58
@ Screen
DELEGATE< void > _fadeInComplete
Definition: PostFX.h:165
bool _filtersDirty
Definition: PostFX.h:170
void updateResolution(U16 newWidth, U16 newHeight)
Definition: PostFX.cpp:129
void onFilterToggle(FilterType filter, bool state)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
DELEGATE_STD< Ret, Args... > DELEGATE
constexpr U32 to_U32(const T value)
uint8_t U8
uint16_t U16
double D64
uint32_t U32
uint64_t U64