Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
blurrednormalmap.hpp
Go to the documentation of this file.
1 
23 #ifndef __NORMALMAP__
24 #define __NORMALMAP__
25 
26 #include <tucano/tucano.hpp>
27 
28 namespace Tucano
29 {
30 namespace Effects
31 {
32 
37 {
38 
39 public:
40 
45 
49  virtual void initialize (void)
50  {
51  // searches in default shader directory (/shaders) for shader files normalmap.(vert,frag,geom,comp)
52  loadShader(normalmap_shader, "normalmap");
53  loadShader(blur_shader, "meanfilter");
54  quad.createQuad();
55  }
56 
62  virtual void render (Tucano::Mesh& mesh, const Tucano::Trackball& cameraTrackball)
63  {
64  Eigen::Vector4f viewport = cameraTrackball.getViewport();
65  glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
66 
67 
68  if (fbo.getWidth() != (viewport[2]-viewport[1]) || fbo.getHeight() != (viewport[3]-viewport[1]))
69  {
70  fbo.create(viewport[2]-viewport[1], viewport[3]-viewport[1], 1);
71  }
72 
73  // sets the FBO first (and only) attachment as output
76 
78 
79  // sets all uniform variables for the phong shader
80  normalmap_shader.setUniform("projectionMatrix", cameraTrackball.getProjectionMatrix());
81  normalmap_shader.setUniform("modelMatrix", mesh.getModelMatrix());
82  normalmap_shader.setUniform("viewMatrix", cameraTrackball.getViewMatrix());
83 
85 
86  glEnable(GL_DEPTH_TEST);
87  mesh.render();
88  glDisable(GL_DEPTH_TEST);
89 
91 
92 
93  // *** unbind the buffer as output buffer, and applies the blur filter ****
94  fbo.unbind(); // automatically returns the draw buffer to GL_BACK
95 
96  blur_shader.bind();
97  blur_shader.setUniform("imageTexture", fbo.bindAttachment(0));
98  blur_shader.setUniform("kernelsize", 5);
99  quad.render();
102  }
103 
104 private:
105 
111 };
112 }
113 }
114 
115 
116 
117 #endif
Tucano::Shader normalmap_shader
NormalMap Shader.
Definition: blurrednormalmap.hpp:107
void createQuad(void)
Sets the mesh as Unit Quad.
Definition: mesh.hpp:841
int getHeight(void)
Returns the height of the FBO.
Definition: framebuffer.hpp:893
void getViewMatrix(GLdouble *matrix)
Return the modelview matrix as a GLdouble array.
Definition: camera.hpp:126
void getProjectionMatrix(GLdouble *matrix)
Return the projection matrix as a GLdouble array.
Definition: camera.hpp:142
Tucano::Shader blur_shader
Definition: blurrednormalmap.hpp:108
Definition: bufferobject.hpp:34
Trackball class for manipulating a camera.
Definition: trackball.hpp:79
void clearAttachments(Eigen::Vector4f clear_color=Eigen::Vector4f::Zero())
Clears all attachments with a given color.
Definition: framebuffer.hpp:448
A Shader object represents one GLSL program.
Definition: shader.hpp:45
BlurredNormalMap(void)
Default constructor.
Definition: blurrednormalmap.hpp:44
virtual void render(Tucano::Mesh &mesh, const Tucano::Trackball &cameraTrackball)
Render the mesh given a camera trackball.
Definition: blurrednormalmap.hpp:62
virtual void bindRenderBuffer(GLuint attachID)
Bind framebuffer object and set render buffer to given attachment.
Definition: framebuffer.hpp:258
Tucano::Framebuffer fbo
Definition: blurrednormalmap.hpp:110
void unbind(void)
Unbinds fbo and all texture units in use.
Definition: framebuffer.hpp:408
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
A wrapper class for creating and using FBOs.
Definition: framebuffer.hpp:44
virtual Shader * loadShader(string shader_name)
Loads a shader by filename, initializes it, and inserts in shaders list.
Definition: effect.hpp:73
void create(int w, int h, int num_attachs=1, int nsamples=1)
Creates the framebuffer with specified parameters.
Definition: framebuffer.hpp:146
virtual void render(void)
Render the mesh triangles. The method binds the buffers, calls the method to render triangles...
Definition: mesh.hpp:756
void unbindAttachments(void)
Unbinds all texture attachments.
Definition: framebuffer.hpp:528
Eigen::Affine3f getModelMatrix(void) const
Returns the model matrix.
Definition: model.hpp:103
int getWidth(void)
Returns the width of the FBO.
Definition: framebuffer.hpp:884
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
virtual void initialize(void)
Load and initialize shaders.
Definition: blurrednormalmap.hpp:49
Tucano::Mesh quad
Definition: blurrednormalmap.hpp:109
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194
void setAttributeLocation(Shader *shader)
Automatically sets the attribute locations for a given Shader.
Definition: mesh.hpp:541
Renders a mesh using a normal map as colors.
Definition: blurrednormalmap.hpp:36
Eigen::Vector4f getViewport(void) const
Returns the viewport coordinates.
Definition: camera.hpp:246
The Effect class is a holder for Shaders. It is completely optional, but is contains a few methods fo...
Definition: effect.hpp:43
void bindAttachment(int attachment, int texture_unit)
Binds a texture attachment to a given texture unit.
Definition: framebuffer.hpp:510
void setUniform(GLint location, GLint a, GLint b, GLint c, GLint d)
Sets an uniform integer 4D vector (ivec4) given a location and the vector values. ...
Definition: shader.hpp:1258