TTK
Loading...
Searching...
No Matches
ttkCinemaDarkroomIBS.cpp
Go to the documentation of this file.
2
3#include <vtkImageData.h>
4#include <vtkInformation.h>
5#include <vtkObjectFactory.h>
6
8
12
14
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
19
20// #extension GL_OES_standard_derivatives : enable
21
22varying vec4 vPos;
23
24uniform sampler2D tex0; // color
25uniform sampler2D tex1; // depth
26uniform sampler2D tex2; // ao
27
28float readDepth( const in vec2 coord ){
29 return texture2D( tex1, coord ).r;
30}
31
32void main() {
33 vec3 color = texture2D( tex0, vPos.xy ).rgb;
34 float ao = texture2D( tex2, vPos.xy ).r;
35 float depth = readDepth(vPos.xy);
36
37 // Compute Luminance
38 vec3 lumcoeff = vec3( 0.299, 0.587, 0.114 );
39 vec3 luminance = vec3( dot( color, lumcoeff ) );
40
41 // Silhouette Effect
42 vec2 pixelSize = 1./cResolution;
43 vec3 eps = 2.0*vec3( pixelSize.x, pixelSize.y, 0 );
44 float depthN = readDepth(vPos.xy + eps.zy);
45 float depthE = readDepth(vPos.xy + eps.xz);
46 float depthS = readDepth(vPos.xy - eps.zy);
47 float depthW = readDepth(vPos.xy - eps.xz);
48
49 float dxdz = abs(depthE-depthW);
50 float dydz = abs(depthN-depthS);
51 // float dxdz = dFdx(depth);
52 // float dydz = dFdy(depth);
53
54 vec3 n = normalize( vec3(dxdz, dydz, 1./cStrength) );
55 vec3 lightPos = vec3(0,0,1);
56 float lightInt = 1.0*dot(n,normalize(lightPos));
57
58 vec3 outputColor = vec3( color * mix( vec3(ao), vec3(1.0), luminance * cLuminance ) );
59
60 outputColor = outputColor*cAmbient + outputColor*lightInt;
61
62 gl_FragColor = vec4(outputColor, depth>0.99 ? 0.0 : 1.0);
63}
64 )");
65}
66
67int ttkCinemaDarkroomIBS::RequestData(vtkInformation *ttkNotUsed(request),
68 vtkInformationVector **inputVector,
69 vtkInformationVector *outputVector) {
70
71 auto inputImage = vtkImageData::GetData(inputVector[0]);
72 auto outputImage = vtkImageData::GetData(outputVector);
73 outputImage->ShallowCopy(inputImage);
74
75 this->InitRenderer(outputImage);
76
77 this->AddReplacement("cStrength", {this->Strength});
78 this->AddReplacement("cLuminance", {this->Luminance});
79 this->AddReplacement("cAmbient", {this->Ambient});
80
81 if(!this->AddTexture(outputImage, 0, 0))
82 return 0;
83 if(!this->AddTexture(outputImage, 1, 1))
84 return 0;
85 if(!this->AddTexture(outputImage, 2, 2))
86 return 0;
87
88 this->Render(outputImage, "IBS");
89
90 return 1;
91}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
Image Based Shading.
std::string GetFragmentShaderCode() override
~ttkCinemaDarkroomIBS() 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)
int AddReplacement(const std::string &name, const std::vector< double > &values, const bool &isInt=false)
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
vtkStandardNewMacro(ttkCinemaDarkroomIBS)