shaderPhong.h 4.47 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
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

Sylvain Thery's avatar
Sylvain Thery committed
34 35
#include "Utils/dll.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
36 37
namespace CGoGN
{
Pierre Kraemer's avatar
Pierre Kraemer committed
38

Sylvain Thery's avatar
Sylvain Thery committed
39
namespace Utils
Pierre Kraemer's avatar
Pierre Kraemer committed
40 41
{

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

Sylvain Thery's avatar
Sylvain Thery committed
51
	// shader sources OGL3
Sylvain Thery's avatar
Sylvain Thery committed
52 53 54 55
	static std::string vertexShaderText;
	static std::string fragmentShaderText;
	static std::string vertexShaderClipText;
	static std::string fragmentShaderClipText;
Pierre Kraemer's avatar
Pierre Kraemer committed
56

Sylvain Thery's avatar
Sylvain Thery committed
57
    // uniform locations
58 59 60 61 62
	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
63
	CGoGNGLuint m_unif_eyePos;
Sylvain Thery's avatar
Sylvain Thery committed
64
	CGoGNGLuint m_unif_backColor;
Pierre Kraemer's avatar
Pierre Kraemer committed
65

Sylvain Thery's avatar
Sylvain Thery committed
66 67 68 69 70 71
	//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
72
	Geom::Vec3f m_eyePos;
Sylvain Thery's avatar
Sylvain Thery committed
73
	Geom::Vec4f m_backColor;
Pierre Kraemer's avatar
Pierre Kraemer committed
74

75 76 77 78
	VBO* m_vboPos;
	VBO* m_vboNormal;
	VBO* m_vboColor;

Sylvain Thery's avatar
Sylvain Thery committed
79 80 81 82
	/// clipping
	CGoGNGLuint m_unif_planeClip;
	Geom::Vec4f m_planeClip;

Sylvain Thery's avatar
Sylvain Thery committed
83 84 85
	void getLocations();

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

87 88
	void restoreUniformsAttribs();

Pierre Kraemer's avatar
Pierre Kraemer committed
89
public:
Sylvain Thery's avatar
Sylvain Thery committed
90
	ShaderPhong(bool withClipping = false ,bool doubleSided = false, bool withEyePosition=false);
Pierre Kraemer's avatar
Pierre Kraemer committed
91

92 93
	void setDoubleSided(bool doubleSided);

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

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

Sylvain Thery's avatar
Sylvain Thery committed
99 100 101 102
	void setSpecular(const Geom::Vec4f& specular);

	void setShininess(float shininess);

103
	void setLightPosition(const Geom::Vec3f& lp);
Sylvain Thery's avatar
Sylvain Thery committed
104 105

	void setBackColor(const Geom::Vec4f& back);
Sylvain's avatar
Sylvain committed
106 107
	
	/// set eye position for VR environement
108
	void setEyePosition(const Geom::Vec3f& ep);
Sylvain Thery's avatar
Sylvain Thery committed
109

Pierre Kraemer's avatar
Pierre Kraemer committed
110
	const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
Pierre Kraemer's avatar
Pierre Kraemer committed
111

Pierre Kraemer's avatar
Pierre Kraemer committed
112
	const Geom::Vec4f& getDiffuse() const { return m_diffuse; }
Pierre Kraemer's avatar
Pierre Kraemer committed
113

Pierre Kraemer's avatar
Pierre Kraemer committed
114
	const Geom::Vec4f& getSpecular() const { return m_specular; }
Pierre Kraemer's avatar
Pierre Kraemer committed
115

Pierre Kraemer's avatar
Pierre Kraemer committed
116
	float getShininess() const { return m_shininess; }
Pierre Kraemer's avatar
Pierre Kraemer committed
117

Pierre Kraemer's avatar
Pierre Kraemer committed
118
	const Geom::Vec3f& getLightPosition() const { return m_lightPos; }
Pierre Kraemer's avatar
Pierre Kraemer committed
119

Sylvain Thery's avatar
Sylvain Thery committed
120 121 122 123 124 125
	/**
	 * 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
Pierre Kraemer committed
126
	unsigned int setAttributePosition(VBO* vbo);
127

Pierre Kraemer's avatar
Pierre Kraemer committed
128
	unsigned int setAttributeNormal(VBO* vbo);
Sylvain Thery's avatar
Sylvain Thery committed
129

Pierre Kraemer's avatar
Pierre Kraemer committed
130 131
	// optional attributes
	unsigned int setAttributeColor(VBO* vbo);
Sylvain Thery's avatar
Sylvain Thery committed
132
	void unsetAttributeColor();
Sylvain Thery's avatar
Sylvain Thery committed
133 134 135 136

	void setClippingPlane(const Geom::Vec4f& plane);

	inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
Sylvain Thery's avatar
Sylvain Thery committed
137
};
Pierre Kraemer's avatar
Pierre Kraemer committed
138

Pierre Kraemer's avatar
Pierre Kraemer committed
139 140 141 142
} // namespace Utils

} // namespace CGoGN

Pierre Kraemer's avatar
Pierre Kraemer committed
143
#endif