shaderPhong.h 3.96 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
25
26
#ifndef __CGOGN_SHADER_PHONG__
#define __CGOGN_SHADER_PHONG__
Pierre Kraemer's avatar
Pierre Kraemer committed
27

Sylvain Thery's avatar
Sylvain Thery committed
28
#include "Utils/GLSLShader.h"
29
#include "Utils/clippingShader.h"
Sylvain Thery's avatar
Sylvain Thery committed
30
#include "Geometry/vector_gen.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
31

Sylvain Thery's avatar
Sylvain Thery committed
32
#include <string>
Pierre Kraemer's avatar
Pierre Kraemer committed
33
34
35

namespace CGoGN
{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
36

Sylvain Thery's avatar
Sylvain Thery committed
37
namespace Utils
Pierre Kraemer's avatar
Pierre Kraemer committed
38
39
{

40
class ShaderPhong : public ClippingShader
Pierre Kraemer's avatar
Pierre Kraemer committed
41
{
Sylvain Thery's avatar
Sylvain Thery committed
42
43
44
protected:
	// flag color per vertex or not
	bool m_with_color;
Sylvain's avatar
Sylvain committed
45
46
	// flag color per vertex or not
	bool m_with_eyepos;	
Pierre Kraemer's avatar
Pierre Kraemer committed
47

Sylvain Thery's avatar
Sylvain Thery committed
48
49
50
	// shader sources OGL3
    static std::string vertexShaderText;
    static std::string fragmentShaderText;
Pierre Kraemer's avatar
Pierre Kraemer committed
51

Sylvain Thery's avatar
Sylvain Thery committed
52
    // uniform locations
53
54
55
56
57
	CGoGNGLuint m_unif_ambiant;
	CGoGNGLuint m_unif_diffuse;
	CGoGNGLuint m_unif_specular;
	CGoGNGLuint m_unif_shininess;
	CGoGNGLuint m_unif_lightPos;
Sylvain's avatar
Sylvain committed
58
	CGoGNGLuint m_unif_eyePos;
Pierre Kraemer's avatar
Pierre Kraemer committed
59

Sylvain Thery's avatar
Sylvain Thery committed
60
61
62
63
64
65
	//values
	Geom::Vec4f m_ambiant;
	Geom::Vec4f m_diffuse;
	Geom::Vec4f m_specular;
	float m_shininess;
	Geom::Vec3f m_lightPos;
Sylvain's avatar
Sylvain committed
66
	Geom::Vec3f m_eyePos;
Pierre Kraemer's avatar
Pierre Kraemer committed
67

68
69
70
71
	VBO* m_vboPos;
	VBO* m_vboNormal;
	VBO* m_vboColor;

Sylvain Thery's avatar
Sylvain Thery committed
72
73
74
	void getLocations();

	void sendParams();
Pierre Kraemer's avatar
Pierre Kraemer committed
75

76
77
	void restoreUniformsAttribs();

Pierre Kraemer's avatar
Pierre Kraemer committed
78
public:
Sylvain's avatar
Sylvain committed
79
	ShaderPhong(bool doubleSided = false, bool withEyePosition=false);
Pierre Kraemer's avatar
Pierre Kraemer committed
80

Sylvain Thery's avatar
Sylvain Thery committed
81
82
	// inviduals parameter setting functions
	void setAmbiant(const Geom::Vec4f& ambiant);
Pierre Kraemer's avatar
Pierre Kraemer committed
83

Sylvain Thery's avatar
Sylvain Thery committed
84
	void setDiffuse(const Geom::Vec4f& diffuse);
Pierre Kraemer's avatar
Pierre Kraemer committed
85

Sylvain Thery's avatar
Sylvain Thery committed
86
87
88
89
	void setSpecular(const Geom::Vec4f& specular);

	void setShininess(float shininess);

90
	void setLightPosition(const Geom::Vec3f& lp);
Sylvain's avatar
Sylvain committed
91
92
	
	/// set eye position for VR environement
93
	void setEyePosition(const Geom::Vec3f& ep);
Sylvain Thery's avatar
Sylvain Thery committed
94

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
95
	const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
Pierre Kraemer's avatar
Pierre Kraemer committed
96

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
97
	const Geom::Vec4f& getDiffuse() const { return m_diffuse; }
Pierre Kraemer's avatar
Pierre Kraemer committed
98

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
99
	const Geom::Vec4f& getSpecular() const { return m_specular; }
Pierre Kraemer's avatar
Pierre Kraemer committed
100

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
101
	float getShininess() const { return m_shininess; }
Pierre Kraemer's avatar
Pierre Kraemer committed
102

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
103
	const Geom::Vec3f& getLightPosition() const { return m_lightPos; }
Pierre Kraemer's avatar
Pierre Kraemer committed
104

Sylvain Thery's avatar
Sylvain Thery committed
105
106
107
108
109
110
	/**
	 * set all parameter in on call (one bind also)
	 */
	void setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos);

	// attributes
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
111
	unsigned int setAttributePosition(VBO* vbo);
112

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
113
	unsigned int setAttributeNormal(VBO* vbo);
Sylvain Thery's avatar
Sylvain Thery committed
114

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
115
116
	// optional attributes
	unsigned int setAttributeColor(VBO* vbo);
Sylvain Thery's avatar
Sylvain Thery committed
117
118
	void unsetAttributeColor();
};
Pierre Kraemer's avatar
Pierre Kraemer committed
119

Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
120
121
122
123
} // namespace Utils

} // namespace CGoGN

Pierre Kraemer's avatar
Pierre Kraemer committed
124
#endif