3#include <vtkImageData.h>
4#include <vtkInformation.h>
5#include <vtkObjectFactory.h>
16 return std::string(R
"(
17//VTK::System::Dec // always start with these lines in your FS
19attribute vec4 vertexMC;
29 vPos = vertexMC/2. + vec4(0.5,0.5,0.5,0);
31 vec2 fragCoord = vPos.xy * cResolution;
32 vec2 inverseVP = 1.0 / cResolution.xy;
33 v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;
34 v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;
35 v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;
36 v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;
37 v_rgbM = vec2(fragCoord * inverseVP);
39 gl_Position = vertexMC;
46 return std::string(R
"(
47//VTK::System::Dec // always start with these lines in your FS
48//VTK::Output::Dec // always start with these lines in your FS
58uniform sampler2D tex0;
60#ifndef FXAA_REDUCE_MIN
61 #define FXAA_REDUCE_MIN (1.0/ 128.0)
64#ifndef FXAA_REDUCE_MUL
65 #define FXAA_REDUCE_MUL (1.0 / 8.0)
69 #define FXAA_SPAN_MAX 8.0
72vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,
73 vec2 v_rgbNW, vec2 v_rgbNE,
74 vec2 v_rgbSW, vec2 v_rgbSE,
77 mediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);
78 vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;
79 vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;
80 vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;
81 vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;
82 vec4 texColor = texture2D(tex, v_rgbM);
83 vec3 rgbM = texColor.xyz;
84 vec3 luma = vec3(0.299, 0.587, 0.114);
85 float lumaNW = dot(rgbNW, luma);
86 float lumaNE = dot(rgbNE, luma);
87 float lumaSW = dot(rgbSW, luma);
88 float lumaSE = dot(rgbSE, luma);
89 float lumaM = dot(rgbM, luma);
90 float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
91 float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
94 dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
95 dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
97 float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
98 (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
100 float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
101 dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
102 max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
103 dir * rcpDirMin)) * inverseVP;
106 texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
107 texture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
109 vec3 rgbB = rgbA * 0.5 + 0.25 * (
110 texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz +
111 texture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);
113 float lumaB = dot(rgbB, luma);
114 if ((lumaB < lumaMin) || (lumaB > lumaMax))
115 color = vec4(rgbA, texColor.a);
117 color = vec4(rgbB, texColor.a);
123 vec2 fragCoord = vPos.xy * cResolution;
124 gl_FragColor = fxaa(tex0, fragCoord, cResolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
130 vtkInformationVector **inputVector,
131 vtkInformationVector *outputVector) {
133 auto inputImage = vtkImageData::GetData(inputVector[0]);
134 auto outputImage = vtkImageData::GetData(outputVector);
135 outputImage->ShallowCopy(inputImage);
142 this->
Render(outputImage,
"FXAA");
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Fast Approximate Anti-Aliasing.
~ttkCinemaDarkroomFXAA() override
std::string GetFragmentShaderCode() override
std::string GetVertexShaderCode() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Base Class for all CinemaDarkroom Shaders.
virtual int Render(vtkImageData *image, const std::string &name)
int InitRenderer(vtkImageData *outputImage)
int AddTexture(vtkImageData *image, int arrayIdx, int textureIdx)
void setDebugMsgPrefix(const std::string &prefix)
vtkStandardNewMacro(ttkCinemaDarkroomFXAA)