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

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
merge..  
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;
65
	CGoGNGLuint m_unif_doubleSided;
Pierre Kraemer's avatar
Pierre Kraemer committed
66

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

77 78 79 80
	VBO* m_vboPos;
	VBO* m_vboNormal;
	VBO* m_vboColor;

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

Sylvain Thery's avatar
Sylvain Thery committed
85 86 87
	void getLocations();

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

89 90
	void restoreUniformsAttribs();

Pierre Kraemer's avatar
Pierre Kraemer committed
91
public:
92
	ShaderPhong(bool withClipping = false, bool withEyePosition=false);
Pierre Kraemer's avatar
Pierre Kraemer committed
93

94 95
	void setDoubleSided(bool doubleSided);

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

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

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

	void setShininess(float shininess);

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

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

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

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

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

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

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

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

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

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

	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
139
};
Pierre Kraemer's avatar
Pierre Kraemer committed
140

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
141 142 143 144
} // namespace Utils

} // namespace CGoGN

Pierre Kraemer's avatar
Pierre Kraemer committed
145
#endif