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
18//VTK::Output::Dec // always start with these lines in your FS
22uniform sampler2D tex0;
23uniform sampler2D tex1;
25float readDepth( const in vec2 coord ){
26 return texture2D( tex1, coord ).r;
29float computeCircleOfConfusion(
32 float s2 = readDepth(coord);
33 float c = cAperture * abs(s2-cFocalDepth);
34 return clamp(c, 0.0, cMaxBlur);
37const vec2 poissonDisk[32] = vec2[](
38 vec2( -0.94201624, -0.39906216 ),
39 vec2( 0.94558609, -0.76890725 ),
40 vec2( -0.094184101, -0.92938870 ),
41 vec2( 0.34495938, 0.29387760 ),
42 vec2( -0.91588581, 0.45771432 ),
43 vec2( -0.81544232, -0.87912464 ),
44 vec2( -0.38277543, 0.27676845 ),
45 vec2( 0.97484398, 0.75648379 ),
46 vec2( 0.44323325, -0.97511554 ),
47 vec2( 0.53742981, -0.47373420 ),
48 vec2( -0.26496911, -0.41893023 ),
49 vec2( 0.79197514, 0.19090188 ),
50 vec2( -0.24188840, 0.99706507 ),
51 vec2( -0.81409955, 0.91437590 ),
52 vec2( 0.19984126, 0.78641367 ),
53 vec2( 0.14383161, -0.14100790 ),
54 vec2( -0.44201624, -0.29906216 ),
55 vec2( 0.94558609, -0.46890725 ),
56 vec2( -0.194184101, -0.42938870 ),
57 vec2( 0.24495938, 0.99387760 ),
58 vec2( -0.31588581, 0.45771432 ),
59 vec2( -0.81544232, -0.87912464 ),
60 vec2( -0.08277543, 0.87676845 ),
61 vec2( 0.57484398, 0.55648379 ),
62 vec2( 0.74323325, -0.27511554 ),
63 vec2( 0.44298431, -0.47373420 ),
64 vec2( -0.21196911, -0.22893023 ),
65 vec2( 0.79197514, 0.12020188 ),
66 vec2( -0.11184840, 0.99706507 ),
67 vec2( -0.4309955, 0.111437590 ),
68 vec2( 0.12344126, 0.78641367 ),
69 vec2( 0.2183161, -0.89100790 )
75 float bleedingBias = 0.02;
76 float bleedingMult = 30.0;
78 float centerDepth = readDepth(coord);
79 float centerCoC = computeCircleOfConfusion(coord);
82 float totalWeight = 0.0;
84 vec2 adjustedRadius = vec2(
85 cResolution[1]/cResolution[0],
89 for(int i=0; i<32; i++){
90 vec2 offset = poissonDisk[i] * adjustedRadius;
92 vec2 sampleCoords = coord + offset * centerCoC;
93 float sampleCoC = computeCircleOfConfusion(sampleCoords);
95 vec4 samplePixel = texture2D(tex0, sampleCoords);
96 float sampleDepth = readDepth(sampleCoords);
98 float weight = sampleDepth < centerDepth ? sampleCoC * bleedingMult : 1.0;
99 weight = (centerCoC > sampleCoC + bleedingBias) ? weight : 1.0;
100 weight = clamp(weight,0.0,1.0);
102 color += samplePixel*weight;
103 totalWeight += weight;
106 return color / totalWeight;
110 gl_FragColor = SSDoF(vPos.xy);
116 vtkInformationVector **inputVector,
117 vtkInformationVector *outputVector) {
119 auto inputImage = vtkImageData::GetData(inputVector[0]);
120 auto outputImage = vtkImageData::GetData(outputVector);
121 outputImage->ShallowCopy(inputImage);
135 this->
Render(outputImage,
"SSDoF");
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Screen Space Depth of Field.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
~ttkCinemaDarkroomSSDoF() override
std::string GetFragmentShaderCode() 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)
int AddReplacement(const std::string &name, const std::vector< double > &values, const bool &isInt=false)
void setDebugMsgPrefix(const std::string &prefix)
vtkStandardNewMacro(ttkCinemaDarkroomSSDoF)