Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
orennayar.hpp
Go to the documentation of this file.
1 
23 #ifndef __ORENNAYAR__
24 #define __ORENNAYAR__
25 
26 #include <tucano/effect.hpp>
27 #include <tucano/camera.hpp>
28 
29 namespace Tucano
30 {
31 
32 namespace Effects
33 {
34 
38 class OrenNayar : public Tucano::Effect
39 {
40 
41 private:
42 
45 
47  float roughness = 1.0;
48 
49 public:
50 
54  OrenNayar (void) {}
55 
59  virtual void initialize (void)
60  {
61  loadShader(orennayar_shader, "orennayar") ;
62  }
63 
68  float getRoughnessCoeff (void)
69  {
70  return roughness;
71  }
72 
73 
78  void setRoughnessCoeff (float value)
79  {
80  roughness = value;
81  }
82 
88  void render (Tucano::Mesh& mesh, const Tucano::Camera& camera, const Tucano::Camera& light)
89  {
90 
91  Eigen::Vector4f viewport = camera.getViewport();
92  glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
93 
94  orennayar_shader.bind();
95 
96  // sets all uniform variables for the Oren-Nayar shader
97  orennayar_shader.setUniform("projectionMatrix", camera.getProjectionMatrix());
98  orennayar_shader.setUniform("modelMatrix", mesh.getModelMatrix());
99  orennayar_shader.setUniform("viewMatrix", camera.getViewMatrix());
100  orennayar_shader.setUniform("lightViewMatrix", light.getViewMatrix());
101  orennayar_shader.setUniform("has_color", mesh.hasAttribute("in_Color"));
102  orennayar_shader.setUniform("default_color", mesh.getColor());
103  orennayar_shader.setUniform("sigma", roughness);
104 
105  mesh.setAttributeLocation(orennayar_shader);
106 
107  mesh.render();
108 
109  orennayar_shader.unbind();
110  }
111 
112 };
113 }
114 
115 }
116 
117 #endif
Renders a mesh using a Oren-Nayar BRDF shader.
Definition: orennayar.hpp:38
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
void getProjectionMatrix(GLdouble *matrix)
Return the projection matrix as a GLdouble array.
Definition: camera.hpp:142
Definition: bufferobject.hpp:34
virtual void initialize(void)
Load and initialize shaders.
Definition: orennayar.hpp:59
A Shader object represents one GLSL program.
Definition: shader.hpp:45
float getRoughnessCoeff(void)
Get roughness coefficient.
Definition: orennayar.hpp:68
void setRoughnessCoeff(float value)
Set roughness coefficient.
Definition: orennayar.hpp:78
bool hasAttribute(const string &name) const
Returns wether an attribute exists or not.
Definition: mesh.hpp:503
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
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
Tucano::Shader orennayar_shader
Phong Shader.
Definition: orennayar.hpp:44
float roughness
Roughness coefficient, can be in range [0, inf)
Definition: orennayar.hpp:47
OrenNayar(void)
Default constructor.
Definition: orennayar.hpp:54
Eigen::Affine3f getModelMatrix(void) const
Returns the model matrix.
Definition: model.hpp:103
void render(Tucano::Mesh &mesh, const Tucano::Camera &camera, const Tucano::Camera &light)
Render the mesh given a camera and light, using a Oren Nayar brdf shader.
Definition: orennayar.hpp:88
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
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 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