Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
phongshadowmap.hpp
Go to the documentation of this file.
1 
23 #ifndef __PHONGSHADOWMAP__
24 #define __PHONGSHADOWMAP__
25 
26 #include <tucano/tucano.hpp>
27 
28 namespace Tucano
29 {
30 namespace Effects
31 {
32 
37 {
38 
39 private:
40 
43 
44 public:
45 
49  PhongShadowmap (void) {}
50 
54  virtual void initialize (void)
55  {
56  // searches in default shader directory (/shaders) for shader files phongShader.(vert,frag,geom,comp)
57  loadShader(phong_shader, "phongshadow") ;
58  }
59 
65  void render (Tucano::Mesh& mesh, const Tucano::Camera& camera, const Tucano::Camera& light, Tucano::Framebuffer *shadow_fbo)
66  {
67 
68  Eigen::Vector4f viewport = camera.getViewport();
69  glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
70 
71  phong_shader.bind();
72 
73  // sets all uniform variables for the phong shader
74  phong_shader.setUniform("projectionMatrix", camera.getProjectionMatrix());
75  phong_shader.setUniform("modelMatrix", mesh.getModelMatrix());
76  phong_shader.setUniform("viewMatrix", camera.getViewMatrix());
77  phong_shader.setUniform("lightViewMatrix", light.getViewMatrix());
78  phong_shader.setUniform("lightProjectionMatrix", light.getProjectionMatrix());
79  phong_shader.setUniform("shadowmap", shadow_fbo->bindAttachment(0) );
80  phong_shader.setUniform("has_color", mesh.hasAttribute("in_Color"));
81  phong_shader.setUniform("default_color", mesh.getColor());
82 
83  mesh.setAttributeLocation(phong_shader);
84 
85  glEnable(GL_DEPTH_TEST);
86  mesh.render();
87 
88  phong_shader.unbind();
89  shadow_fbo->unbindAttachments();
90  }
91 };
92 }
93 }
94 
95 
96 #endif
Renders a mesh using a Phong shader and a shadow map.
Definition: phongshadowmap.hpp:36
Eigen::Vector4f getColor(void)
Returns the default color of the model.
Definition: model.hpp:56
void getViewMatrix(GLdouble *matrix)
Return the modelview matrix as a GLdouble array.
Definition: camera.hpp:126
virtual void initialize(void)
Load and initialize shaders.
Definition: phongshadowmap.hpp:54
void getProjectionMatrix(GLdouble *matrix)
Return the projection matrix as a GLdouble array.
Definition: camera.hpp:142
Definition: bufferobject.hpp:34
A Shader object represents one GLSL program.
Definition: shader.hpp:45
bool hasAttribute(const string &name) const
Returns wether an attribute exists or not.
Definition: mesh.hpp:503
PhongShadowmap(void)
Default constructor.
Definition: phongshadowmap.hpp:49
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
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
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
void render(Tucano::Mesh &mesh, const Tucano::Camera &camera, const Tucano::Camera &light, Tucano::Framebuffer *shadow_fbo)
Render the mesh given a camera and light, using a Phong shader.
Definition: phongshadowmap.hpp:65
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194
Defines an abstract camera with a projection and view matrices.
Definition: camera.hpp:37
void setAttributeLocation(Shader *shader)
Automatically sets the attribute locations for a given Shader.
Definition: mesh.hpp:541
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
Tucano::Shader phong_shader
Phong Shader.
Definition: phongshadowmap.hpp:42
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