NAP
blurshader.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External Includes
8 #include <shader.h>
9 #include <renderservice.h>
10 #include <nap/core.h>
11 
12 namespace nap
13 {
17  enum class EBlurSamples : uint
18  {
19  X5 = 0,
20  X9 = 1,
21  X13 = 2
22  };
23 
27  namespace uniform
28  {
29  namespace blur
30  {
31  namespace sampler
32  {
33  inline constexpr const char* colorTexture = "colorTexture";
34  }
35 
36  inline constexpr const char* uboStruct = "UBO";
37  inline constexpr const char* textureSize = "textureSize";
38  inline constexpr const char* direction = "direction";
39  }
40  }
41 
61  template <EBlurSamples KERNEL>
62  class BlurShader : public Shader
63  {
64  RTTI_ENABLE(Shader)
65  public:
66  // Constructor
67  BlurShader(Core& core) : Shader(core), mRenderService(core.getService<RenderService>()) { }
68 
74  virtual bool init(utility::ErrorState& errorState) override;
75 
76  private:
77  RenderService* mRenderService = nullptr;
78  };
79 
80  // Blur Shader Definitions
84 
85 
87  // Template Definitions
89 
90  template <EBlurSamples KERNEL>
92  {
93  if (!Shader::init(errorState))
94  return false;
95 
96  std::string shader_name;
97  switch (KERNEL)
98  {
100  shader_name = "gaussianblur5";
101  break;
103  shader_name = "gaussianblur9";
104  break;
106  shader_name = "gaussianblur13";
107  break;
108  default:
109  errorState.fail("Unknown blur sample type.");
110  return false;
111  }
112  return loadDefault(shader_name, errorState);
113  }
114 }
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::rtti::Object::init
virtual bool init(utility::ErrorState &errorState)
Definition: object.h:46
nap::uniform::blur::uboStruct
constexpr const char * uboStruct
UBO that contains all the uniforms.
Definition: blurshader.h:36
nap::BlurShader::BlurShader
BlurShader(Core &core)
Definition: blurshader.h:67
nap::uniform::blur::textureSize
constexpr const char * textureSize
Size of the texture.
Definition: blurshader.h:37
nap::EBlurSamples::X13
@ X13
13x13 kernel, linear sampling
nap::utility::ErrorState
Definition: errorstate.h:19
nap::uniform::blur::direction
constexpr const char * direction
Direction of the blur e.g. {1.0, 0.0} for horizontal, {0.0, 1.0} for vertical.
Definition: blurshader.h:38
nap::Shader
Definition: shader.h:105
nap::utility::ErrorState::fail
void fail(T &&errorMessage)
Definition: errorstate.h:73
nap::RenderService
Definition: renderservice.h:275
nap::Core
Definition: core.h:82
nap::BlurShader::init
virtual bool init(utility::ErrorState &errorState) override
Definition: blurshader.h:91
nap::EBlurSamples
EBlurSamples
Definition: blurshader.h:17
nap
Definition: templateapp.h:17
nap::uniform::blur::sampler::colorTexture
constexpr const char * colorTexture
Name of the color texture sampler.
Definition: blurshader.h:33
nap::EBlurSamples::X5
@ X5
5x5 kernel, linear sampling
nap::BlurShader
Definition: blurshader.h:62
nap::EBlurSamples::X9
@ X9
9x9 kernel, linear sampling