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 "VelocityBufferPass.h"
24 class JitterSampleConfig :
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(
int state READ getState WRITE setState NOTIFY dirty)
32 JitterSampleConfig() : render::Job::Config(true) {}
38 void setIndex(
int current);
39 void setState(
int state);
42 int cycleStopPauseRun();
49 int getIndex()
const {
return _index; }
50 int getState()
const {
return _state; }
68 using Config = JitterSampleConfig;
69 using Output = glm::vec2;
70 using JobModel = render::Job::ModelO<JitterSample, Output, Config>;
72 void configure(
const Config& config);
73 void run(
const render::RenderContextPointer& renderContext, Output& jitter);
77 struct SampleSequence {
80 glm::vec2 offsets[SEQUENCE_LENGTH + 1];
81 int sequenceLength{ SEQUENCE_LENGTH };
82 int currentIndex{ 0 };
85 SampleSequence _sampleSequence;
87 bool _freeze{
false };
91 class AntialiasingConfig :
public render::Job::Config {
93 Q_PROPERTY(
int mode READ getAAMode WRITE setAAMode NOTIFY dirty)
94 Q_PROPERTY(
float blend MEMBER blend NOTIFY dirty)
95 Q_PROPERTY(
float sharpen MEMBER sharpen NOTIFY dirty)
96 Q_PROPERTY(
float covarianceGamma MEMBER covarianceGamma NOTIFY dirty)
98 Q_PROPERTY(
bool constrainColor MEMBER constrainColor NOTIFY dirty)
99 Q_PROPERTY(
bool feedbackColor MEMBER feedbackColor NOTIFY dirty)
101 Q_PROPERTY(
bool debug MEMBER debug NOTIFY dirty)
102 Q_PROPERTY(
float debugX MEMBER debugX NOTIFY dirty)
103 Q_PROPERTY(
bool fxaaOnOff READ debugFXAA WRITE setDebugFXAA NOTIFY dirty)
104 Q_PROPERTY(
float debugShowVelocityThreshold MEMBER debugShowVelocityThreshold NOTIFY dirty)
105 Q_PROPERTY(
bool showCursorPixel MEMBER showCursorPixel NOTIFY dirty)
106 Q_PROPERTY(glm::vec2 debugCursorTexcoord MEMBER debugCursorTexcoord NOTIFY dirty)
107 Q_PROPERTY(
float debugOrbZoom MEMBER debugOrbZoom NOTIFY dirty)
109 Q_PROPERTY(
bool showClosestFragment MEMBER showClosestFragment NOTIFY dirty)
112 AntialiasingConfig() : render::Job::Config(true) {}
136 void setAAMode(
int mode);
137 int getAAMode()
const {
return _mode; }
139 void setDebugFXAA(
bool debug) { debugFXAAX = (debug ? 0.0f : 1.0f); emit dirty();}
140 bool debugFXAA()
const {
return (debugFXAAX == 0.0f ?
true :
false); }
144 float blend{ 0.25f };
145 float sharpen{ 0.05f };
147 bool constrainColor{
true };
148 float covarianceGamma{ 0.65f };
149 bool feedbackColor{
false };
151 float debugX{ 0.0f };
152 float debugFXAAX{ 1.0f };
153 float debugShowVelocityThreshold{ 1.0f };
154 glm::vec2 debugCursorTexcoord{ 0.5f, 0.5f };
155 float debugOrbZoom{ 2.0f };
157 bool debug {
false };
158 bool showCursorPixel {
false };
159 bool showClosestFragment{
false };
165 #define SET_BIT(bitfield, bitIndex, value) bitfield = ((bitfield) & ~(1 << (bitIndex))) | ((value) << (bitIndex))
166 #define GET_BIT(bitfield, bitIndex) ((bitfield) & (1 << (bitIndex)))
168 #define ANTIALIASING_USE_TAA 1
170 #if ANTIALIASING_USE_TAA
174 float blend{ 0.15f };
175 float covarianceGamma{ 1.0f };
176 float debugShowVelocityThreshold{ 1.0f };
178 glm::ivec4 flags{ 0 };
179 glm::vec4 pixelInfo{ 0.5f, 0.5f, 2.0f, 0.0f };
180 glm::vec4 regionInfo{ 0.0f, 0.0f, 1.0f, 0.0f };
182 void setConstrainColor(
bool enabled) { SET_BIT(flags.y, 1, enabled); }
183 bool isConstrainColor()
const {
return (
bool)GET_BIT(flags.y, 1); }
185 void setFeedbackColor(
bool enabled) { SET_BIT(flags.y, 4, enabled); }
186 bool isFeedbackColor()
const {
return (
bool)GET_BIT(flags.y, 4); }
188 void setDebug(
bool enabled) { SET_BIT(flags.x, 0, enabled); }
189 bool isDebug()
const {
return (
bool) GET_BIT(flags.x, 0); }
191 void setShowDebugCursor(
bool enabled) { SET_BIT(flags.x, 1, enabled); }
192 bool showDebugCursor()
const {
return (
bool)GET_BIT(flags.x, 1); }
194 void setDebugCursor(glm::vec2 debugCursor) { pixelInfo.x = debugCursor.x; pixelInfo.y = debugCursor.y; }
195 glm::vec2 getDebugCursor()
const {
return glm::vec2(pixelInfo.x, pixelInfo.y); }
197 void setDebugOrbZoom(
float orbZoom) { pixelInfo.z = orbZoom; }
198 float getDebugOrbZoom()
const {
return pixelInfo.z; }
200 void setShowClosestFragment(
bool enabled) { SET_BIT(flags.x, 3, enabled); }
203 using TAAParamsBuffer = gpu::StructBuffer<TAAParams>;
207 using Inputs = render::VaryingSet4 < DeferredFrameTransformPointer, gpu::FramebufferPointer, LinearDepthFramebufferPointer, VelocityFramebufferPointer > ;
208 using Config = AntialiasingConfig;
209 using JobModel = render::Job::ModelI<Antialiasing, Inputs, Config>;
211 Antialiasing(
bool isSharpenEnabled =
true);
213 void configure(
const Config& config);
214 void run(
const render::RenderContextPointer& renderContext,
const Inputs& inputs);
216 const gpu::PipelinePointer& getAntialiasingPipeline(
const render::RenderContextPointer& renderContext);
217 const gpu::PipelinePointer& getBlendPipeline();
218 const gpu::PipelinePointer& getDebugBlendPipeline();
222 gpu::FramebufferSwapChainPointer _antialiasingBuffers;
223 gpu::TexturePointer _antialiasingTextures[2];
224 gpu::BufferPointer _blendParamsBuffer;
225 gpu::PipelinePointer _antialiasingPipeline;
226 gpu::PipelinePointer _blendPipeline;
227 gpu::PipelinePointer _debugBlendPipeline;
229 TAAParamsBuffer _params;
230 AntialiasingConfig::Mode _mode{ AntialiasingConfig::TAA };
231 float _sharpen{ 0.15f };
232 bool _isSharpenEnabled{
true };
237 class AntiAliasingConfig :
public render::Job::Config {
239 Q_PROPERTY(
bool enabled MEMBER enabled)
241 AntiAliasingConfig() : render::Job::Config(true) {}
246 using Config = AntiAliasingConfig;
247 using JobModel = render::Job::ModelI<Antialiasing, gpu::FramebufferPointer, Config>;
251 void configure(
const Config& config) {}
252 void run(
const render::RenderContextPointer& renderContext,
const gpu::FramebufferPointer& sourceBuffer);
254 const gpu::PipelinePointer& getAntialiasingPipeline();
255 const gpu::PipelinePointer& getBlendPipeline();
258 gpu::FramebufferPointer _antialiasingBuffer;
260 gpu::TexturePointer _antialiasingTexture;
261 gpu::BufferPointer _paramsBuffer;
263 gpu::PipelinePointer _antialiasingPipeline;
264 gpu::PipelinePointer _blendPipeline;
265 int _geometryId { 0 };