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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLFXAAFilter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkOpenGLFXAAFilter
* @brief Perform FXAA antialiasing on the current
* framebuffer.
*
*
* Call Execute() to run a FXAA antialiasing pass on the current OpenGL
* framebuffer. See method documentation for tunable parameters.
*
* Based on the following implementation and description:
*
* Whitepaper:
* http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
*
* Sample implementation:
* https://github.com/NVIDIAGameWorks/GraphicsSamples/blob/master/samples/es3-kepler/FXAA/FXAA3_11.h
*
* TODO there are currently some "banding" artifacts on some edges, particularly
* single pixel lines. These seem to be caused by using a linear RGB input,
* rather than a gamma-correct sRGB input. Future work should combine this pass
* with a gamma correction pass to correct this. Bonus points for precomputing
* luminosity into the sRGB's alpha channel to save cycles in the FXAA shader!
*/
#ifndef vtkOpenGLFXAAFilter_h
#define vtkOpenGLFXAAFilter_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkObject.h"
#include "vtkFXAAOptions.h" // For DebugOptions enum
#include <string> // For std::string
class vtkFXAAOptions;
class vtkOpenGLBufferObject;
class vtkOpenGLVertexArrayObject;
class vtkOpenGLRenderer;
class vtkOpenGLRenderTimer;
class vtkShaderProgram;
class vtkTextureObject;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLFXAAFilter: public vtkObject
{
public:
static vtkOpenGLFXAAFilter* New();
vtkTypeMacro(vtkOpenGLFXAAFilter, vtkObject)
virtual void PrintSelf(ostream &os, vtkIndent indent);
/**
* Perform FXAA on the current render buffer in @a ren.
*/
void Execute(vtkOpenGLRenderer *ren);
/**
* Release all OpenGL state.
*/
void ReleaseGraphicsResources();
/**
* Copy the configuration values from @a opts into this filter. Note that
* this copies the configuration values from opts -- it does not save the
* @a opts pointer.
*/
void UpdateConfiguration(vtkFXAAOptions *opts);
//@{
/**
* Parameter for tuning the FXAA implementation. See vtkFXAAOptions for
* details and suggested values.
*/
vtkSetClampMacro(RelativeContrastThreshold, float, 0.f, 1.f)
vtkGetMacro(RelativeContrastThreshold, float)
vtkSetClampMacro(HardContrastThreshold, float, 0.f, 1.f)
vtkGetMacro(HardContrastThreshold, float)
vtkSetClampMacro(SubpixelBlendLimit, float, 0.f, 1.f)
vtkGetMacro(SubpixelBlendLimit, float)
vtkSetClampMacro(SubpixelContrastThreshold, float, 0.f, 1.f)
vtkGetMacro(SubpixelContrastThreshold, float)
virtual void SetUseHighQualityEndpoints(bool val);
vtkGetMacro(UseHighQualityEndpoints, bool)
vtkBooleanMacro(UseHighQualityEndpoints, bool)
vtkSetClampMacro(EndpointSearchIterations, int, 0, VTK_INT_MAX)
vtkGetMacro(EndpointSearchIterations, int)
virtual void SetDebugOptionValue(vtkFXAAOptions::DebugOption opt);
vtkGetMacro(DebugOptionValue, vtkFXAAOptions::DebugOption)
//@}
protected:
vtkOpenGLFXAAFilter();
~vtkOpenGLFXAAFilter();
void Prepare();
void FreeGLObjects();
void CreateGLObjects();
void LoadInput();
void ApplyFilter();
void SubstituteFragmentShader(std::string &fragShader);
void Finalize();
void StartTimeQuery(vtkOpenGLRenderTimer *timer);
void EndTimeQuery(vtkOpenGLRenderTimer *timer);
void PrintBenchmark();
// Cache GL state that we modify
bool BlendState;
bool DepthTestState;
int Viewport[4]; // x, y, width, height
// Used to measure execution time:
vtkOpenGLRenderTimer *PreparationTimer;
vtkOpenGLRenderTimer *FXAATimer;
// Parameters:
float RelativeContrastThreshold;
float HardContrastThreshold;
float SubpixelBlendLimit;
float SubpixelContrastThreshold;
int EndpointSearchIterations;
bool UseHighQualityEndpoints;
vtkFXAAOptions::DebugOption DebugOptionValue;
// Set to true when the shader definitions change so we know when to rebuild.
bool NeedToRebuildShader;
vtkOpenGLRenderer *Renderer;
vtkTextureObject *Input;
vtkShaderProgram *Program;
vtkOpenGLVertexArrayObject *VAO;
vtkOpenGLBufferObject *VBO;
private:
vtkOpenGLFXAAFilter(const vtkOpenGLFXAAFilter&) VTK_DELETE_FUNCTION;
void operator=(const vtkOpenGLFXAAFilter&) VTK_DELETE_FUNCTION;
};
#endif // vtkOpenGLFXAAFilter_h
|