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
20// -----------------------------------------------------------------------------
21// Custom SSAO implementation based on Blender's Viewport SSAO (https://github.com/blender/blender)
22// Roots can be traced back to Arkano22 (https://www.gamedev.net/forums/topic/550699-ssao-no-halo-artifacts/)
23// and Martins Upitis (martinsh) (http://devlog-martinsh.blogspot.com/search/label/SSAO)
24// -----------------------------------------------------------------------------
26uniform sampler2D tex0;
30#define DL 2.399963229728653 // PI * ( 3.0 - sqrt( 5.0 ) )
31#define EULER 2.718281828459045
33float readDepth( const in vec2 coord ){
34 return texture2D( tex0, coord ).r;
37const float gDisplace = 0.5; // gauss bell center
38float compareDepths( const in float depth1, const in float depth2, inout int far ) {
39 float garea = 16.0; // gauss bell width
40 float diff = ( depth1 - depth2 ) * 100.0; // depth difference (0-100)
42 // reduce left bell width to avoid self-shadowing
49 float dd = diff - gDisplace;
50 return pow( EULER, -2.0 * ( dd * dd ) / ( garea * garea ) );
53float calcAO( float depth, float dw, float dh, vec2 uv ) {
54 vec2 vv = vec2( dw, dh );
55 vec2 coord1 = uv + vv;
56 vec2 coord2 = uv - vv;
61 temp1 = compareDepths( depth, readDepth( coord1 ), far );
63 temp2 = compareDepths( readDepth( coord2 ), depth, far );
64 temp1 += ( 1.0 - temp1 ) * temp2;
70 float depth = readDepth( vPos.xy );
72 const float samplesF = cSamples;
73 float occlusion = 0.0;
75 float dz = 1.0 / samplesF;
77 float z = 1.0 - dz / 2.0;
79 float aspect = cResolution.y/cResolution.x;
81 for(int i=0; i<cSamples; i++){
82 float r = sqrt( 1.0 - z ) * cRadius;
83 float pw = cos( l ) * r;
84 float ph = sin( l ) * r;
85 occlusion += calcAO( depth, pw * aspect, ph, vPos.xy );
90 float ao = 1.-occlusion/samplesF;
91 gl_FragColor = vec4(ao,ao,ao, 1 );
97 vtkInformationVector **inputVector,
98 vtkInformationVector *outputVector) {
100 auto inputImage = vtkImageData::GetData(inputVector[0]);
101 auto outputImage = vtkImageData::GetData(outputVector);
102 outputImage->ShallowCopy(inputImage);
105 outputImage->GetDimensions(dim);
116 this->
Render(outputImage,
"SSSAO");
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Scalable Screen Space Ambient Occlusion.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
~ttkCinemaDarkroomSSSAO() 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(ttkCinemaDarkroomSSSAO)