14 #ifndef hifi_AntialiasingEffect_h
15 #define hifi_AntialiasingEffect_h
17 #include <DependencyManager.h>
19 #include "render/DrawTask.h"
20 #include "DeferredFrameTransform.h"
21 #include "DeferredFramebuffer.h"
22 #include "SurfaceGeometryPass.h"
24 class AntialiasingSetupConfig :
public render::Job::Config {
26 Q_PROPERTY(
float scale MEMBER scale NOTIFY dirty)
27 Q_PROPERTY(
bool freeze MEMBER freeze NOTIFY dirty)
28 Q_PROPERTY(
bool stop MEMBER stop NOTIFY dirty)
29 Q_PROPERTY(
int index READ getIndex NOTIFY dirty)
30 Q_PROPERTY(State state READ getState WRITE setState NOTIFY dirty)
31 Q_PROPERTY(Mode mode READ getAAMode WRITE setAAMode NOTIFY dirty)
34 AntialiasingSetupConfig() : render::Job::Config(true) {}
81 float scale { 0.75f };
83 bool freeze {
false };
84 Mode mode { Mode::TAA };
93 int getIndex()
const {
return _index; }
94 void setIndex(
int current);
96 State getState()
const {
return _state; }
97 void setState(State state);
99 Mode getAAMode()
const {
return mode; }
100 void setAAMode(Mode mode);
106 State _state { State::PLAY };
111 class AntialiasingSetup {
114 using Config = AntialiasingSetupConfig;
115 using Output = AntialiasingSetupConfig::Mode;
116 using JobModel = render::Job::ModelO<AntialiasingSetup, Output, Config>;
120 void configure(
const Config& config);
121 void run(
const render::RenderContextPointer& renderContext, Output& output);
125 std::vector<glm::vec2> _sampleSequence;
126 float _scale { 1.0f };
127 int _freezedSampleIndex { 0 };
128 bool _isStopped {
false };
129 bool _isFrozen {
false };
130 AntialiasingSetupConfig::Mode _mode{ AntialiasingSetupConfig::Mode::TAA };
134 class AntialiasingConfig :
public render::Job::Config {
136 Q_PROPERTY(
float blend MEMBER blend NOTIFY dirty)
137 Q_PROPERTY(
float sharpen MEMBER sharpen NOTIFY dirty)
138 Q_PROPERTY(
float covarianceGamma MEMBER covarianceGamma NOTIFY dirty)
140 Q_PROPERTY(
bool constrainColor MEMBER constrainColor NOTIFY dirty)
141 Q_PROPERTY(
bool feedbackColor MEMBER feedbackColor NOTIFY dirty)
142 Q_PROPERTY(
bool bicubicHistoryFetch MEMBER bicubicHistoryFetch NOTIFY dirty)
144 Q_PROPERTY(
bool debug MEMBER debug NOTIFY dirty)
145 Q_PROPERTY(
float debugX MEMBER debugX NOTIFY dirty)
146 Q_PROPERTY(
bool fxaaOnOff READ debugFXAA WRITE setDebugFXAA NOTIFY dirty)
147 Q_PROPERTY(
float debugShowVelocityThreshold MEMBER debugShowVelocityThreshold NOTIFY dirty)
148 Q_PROPERTY(
bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty)
149 Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty)
150 Q_PROPERTY(
float debugOrbZoom MEMBER debugOrbZoom NOTIFY dirty)
152 Q_PROPERTY(
bool showClosestFragment MEMBER showClosestFragment NOTIFY dirty)
155 AntialiasingConfig() : render::Job::Config(true) {}
157 void setDebugFXAA(
bool debug) { debugFXAAX = (debug ? 0.0f : 1.0f); emit dirty();}
158 bool debugFXAA()
const {
return (debugFXAAX == 0.0f ?
true :
false); }
160 float blend { 0.2f };
161 float sharpen { 0.05f };
163 bool constrainColor {
true };
164 float covarianceGamma { 1.15f };
165 bool feedbackColor {
false };
166 bool bicubicHistoryFetch {
true };
168 float debugX { 0.0f };
169 float debugFXAAX { 1.0f };
170 float debugShowVelocityThreshold { 1.0f };
171 glm::vec2 debugCursorTexcoord { 0.5f, 0.5f };
172 float debugOrbZoom { 2.0f };
174 bool debug {
false };
175 bool showCursorPixel {
false };
176 bool showClosestFragment {
false };
182 #define SET_BIT(bitfield, bitIndex, value) bitfield = ((bitfield) & ~(1 << (bitIndex))) | ((value) << (bitIndex))
183 #define GET_BIT(bitfield, bitIndex) ((bitfield) & (1 << (bitIndex)))
187 float blend { 0.15f };
188 float covarianceGamma { 0.9f };
189 float debugShowVelocityThreshold { 1.0f };
191 glm::ivec4 flags { 0 };
192 glm::vec4 pixelInfo { 0.5f, 0.5f, 2.0f, 0.0f };
193 glm::vec4 regionInfo { 0.0f, 0.0f, 1.0f, 0.0f };
195 void setConstrainColor(
bool enabled) { SET_BIT(flags.y, 1, enabled); }
196 bool isConstrainColor()
const {
return (
bool)GET_BIT(flags.y, 1); }
198 void setFeedbackColor(
bool enabled) { SET_BIT(flags.y, 4, enabled); }
199 bool isFeedbackColor()
const {
return (
bool)GET_BIT(flags.y, 4); }
201 void setBicubicHistoryFetch(
bool enabled) { SET_BIT(flags.y, 0, enabled); }
202 bool isBicubicHistoryFetch()
const {
return (
bool)GET_BIT(flags.y, 0); }
204 void setSharpenedOutput(
bool enabled) { SET_BIT(flags.y, 2, enabled); }
205 bool isSharpenedOutput()
const {
return (
bool)GET_BIT(flags.y, 2); }
207 void setDebug(
bool enabled) { SET_BIT(flags.x, 0, enabled); }
208 bool isDebug()
const {
return (
bool) GET_BIT(flags.x, 0); }
210 void setShowDebugCursor(
bool enabled) { SET_BIT(flags.x, 1, enabled); }
211 bool showDebugCursor()
const {
return (
bool)GET_BIT(flags.x, 1); }
213 void setDebugCursor(glm::vec2 debugCursor) { pixelInfo.x = debugCursor.x; pixelInfo.y = debugCursor.y; }
214 glm::vec2 getDebugCursor()
const {
return glm::vec2(pixelInfo.x, pixelInfo.y); }
216 void setDebugOrbZoom(
float orbZoom) { pixelInfo.z = orbZoom; }
217 float getDebugOrbZoom()
const {
return pixelInfo.z; }
219 void setShowClosestFragment(
bool enabled) { SET_BIT(flags.x, 3, enabled); }
221 bool isFXAAEnabled()
const {
return regionInfo.z == 0.0f; }
223 using TAAParamsBuffer = gpu::StructBuffer<TAAParams>;
227 using Inputs = render::VaryingSet4<DeferredFrameTransformPointer, DeferredFramebufferPointer, LinearDepthFramebufferPointer, AntialiasingSetupConfig::Mode>;
228 using Outputs = gpu::TexturePointer;
229 using Config = AntialiasingConfig;
230 using JobModel = render::Job::ModelIO<Antialiasing, Inputs, Outputs, Config>;
232 Antialiasing(
bool isSharpenEnabled =
true);
234 void configure(
const Config& config);
235 void run(
const render::RenderContextPointer& renderContext,
const Inputs& inputs, Outputs& outputs);
237 static const gpu::PipelinePointer& getAntialiasingPipeline();
238 static const gpu::PipelinePointer& getIntensityPipeline();
239 static const gpu::PipelinePointer& getBlendPipeline();
240 static const gpu::PipelinePointer& getDebugBlendPipeline();
243 struct AntialiasingBuffer {
244 gpu::FramebufferSwapChainPointer _swapChain;
245 gpu::TexturePointer _textures[2];
249 _textures[0].reset();
250 _textures[1].reset();
253 AntialiasingBuffer _antialiasingBuffers;
254 gpu::FramebufferPointer _intensityFramebuffer;
255 gpu::TexturePointer _intensityTexture;
256 gpu::BufferPointer _blendParamsBuffer;
258 static gpu::PipelinePointer _antialiasingPipeline;
259 static gpu::PipelinePointer _intensityPipeline;
260 static gpu::PipelinePointer _blendPipeline;
261 static gpu::PipelinePointer _debugBlendPipeline;
263 TAAParamsBuffer _params;
264 float _sharpen { 0.15f };
265 bool _isSharpenEnabled {
true };
266 float _debugFXAAX { 0.0f };