Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SocialAgents3D
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Pitiot
SocialAgents3D
Commits
8bd8a582
Commit
8bd8a582
authored
May 29, 2013
by
pitiot
Browse files
Options
Browse Files
Download
Plain Diff
merging
parents
c20f9b48
56ab7f86
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
505 additions
and
39 deletions
+505
-39
Debug/CMakeLists.txt
Debug/CMakeLists.txt
+1
-0
Release/CMakeLists.txt
Release/CMakeLists.txt
+1
-0
include/agent.h
include/agent.h
+7
-2
include/env_map.h
include/env_map.h
+2
-0
include/moving_mesh.h
include/moving_mesh.h
+3
-3
include/moving_obstacle.h
include/moving_obstacle.h
+1
-1
include/shaderPhongTexCust.frag
include/shaderPhongTexCust.frag
+39
-0
include/shaderPhongTexCust.h
include/shaderPhongTexCust.h
+138
-0
include/shaderPhongTexCust.vert
include/shaderPhongTexCust.vert
+34
-0
include/viewer.h
include/viewer.h
+6
-2
src/agent.cpp
src/agent.cpp
+20
-16
src/env_map.cpp
src/env_map.cpp
+3
-0
src/moving_mesh.cpp
src/moving_mesh.cpp
+7
-5
src/shaderPhongTexCust.cpp
src/shaderPhongTexCust.cpp
+221
-0
src/simulator.cpp
src/simulator.cpp
+3
-1
src/viewer.cpp
src/viewer.cpp
+19
-9
No files found.
Debug/CMakeLists.txt
View file @
8bd8a582
...
...
@@ -45,6 +45,7 @@ add_executable( socialAgentsD
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
../src/shaderPhongTexCust.cpp
${
socialAgents_moc
}
${
socialAgents_ui
}
)
...
...
Release/CMakeLists.txt
View file @
8bd8a582
...
...
@@ -46,6 +46,7 @@ add_executable( socialAgents
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
../src/shaderPhongTexCust.cpp
${
socialAgents_moc
}
${
socialAgents_ui
}
)
...
...
include/agent.h
View file @
8bd8a582
...
...
@@ -8,11 +8,16 @@
#include "spatialHashing.h"
//
#define SECURED
#define SECURED
//#define EXPORTING_AGENT
//#define EXPORTING_OBJ
#define ARASH
#define SMOOTHING_BUFFER_SIZE 200
#ifdef SECURED
#include "Algo/MovingObjects/particle_cell_2D_secured.h"
#else
...
...
@@ -156,7 +161,7 @@ public:
VEC3
velocity_
;
VEC3
newVelocity_
;
VEC3
prefVelocity_
;
VEC3
meanVelocity_
[
4
]
;
VEC3
meanVelocity_
[
SMOOTHING_BUFFER_SIZE
]
;
VEC3
meanDirection_
;
Simulator
*
sim_
;
...
...
include/env_map.h
View file @
8bd8a582
...
...
@@ -33,8 +33,10 @@ class ArticulatedObstacle;
#include "pfp.h"
#define EXPORTING3
#define TWO_AND_HALF_DIM
#ifdef EXPORTING3
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
...
...
include/moving_mesh.h
View file @
8bd8a582
...
...
@@ -18,7 +18,7 @@
using
namespace
std
;
//
#define EXPORTING2
#define EXPORTING2
float
get_angle3D
(
VEC3
v1
,
VEC3
v2
);
...
...
@@ -59,8 +59,8 @@ public:
Utils
::
VBO
*
m_texcoordVBO
;
ShaderCustomTex
*
m_shaderTex
;
//
Utils::ShaderPhongTexture* m_shaderTex;
//
ShaderCustomTex* m_shaderTex;
Utils
::
ShaderPhongTexture
*
m_shaderTex
;
// Utils::ShaderSimpleTexture* m_shaderTex;
Algo
::
Surface
::
Import
::
OBJModel
<
PFP2
>
m_obj
;
unsigned
int
m_nbIndices
;
...
...
include/moving_obstacle.h
View file @
8bd8a582
...
...
@@ -14,7 +14,7 @@
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#endif
#define EXPORTING_BOXES
//
#define EXPORTING_BOXES
#ifdef EXPORTING_BOXES
#include "Algo/Render/GL2/mapRender.h"
...
...
include/shaderPhongTexCust.frag
0 → 100644
View file @
8bd8a582
// ShaderPhongTexCust::fragmentShaderText
PRECISON
;
VARYING_FRAG
vec3
EyeVector
,
Normal
,
LightDir
;
VARYING_FRAG
vec2
texCoord
;
uniform
vec4
materialDiffuse
;
uniform
vec4
materialSpecular
;
uniform
float
ambientCoef
;
uniform
float
shininess
;
uniform
sampler2D
textureUnit
;
FRAG_OUT_DEF
;
void
main
()
{
vec3
N
=
normalize
(
Normal
);
vec3
L
=
normalize
(
LightDir
);
float
lambertTerm
=
dot
(
N
,
L
);
vec4
finalColor
=
ambientCoef
*
texture2D
(
textureUnit
,
texCoord
);
#ifdef DOUBLE_SIDED
if
(
lambertTerm
<
0
.
0
)
{
N
=
-
1
.
0
*
N
;
lambertTerm
=
-
1
.
0
*
lambertTerm
;
#else
if
(
lambertTerm
>
0
.
0
)
{
#endif
vec3
E
=
normalize
(
EyeVector
);
vec3
R
=
reflect
(
-
L
,
N
);
float
specular
=
pow
(
max
(
dot
(
R
,
E
),
0
.
0
),
shininess
);
vec3
diffuse
=
(
1
.
0
-
ambientCoef
)
*
texture2D
(
textureUnit
,
texCoord
).
rgb
;
finalColor
+=
vec4
(
diffuse
*
lambertTerm
,
0
.
0
)
+
materialSpecular
*
specular
;
}
gl_FragColor
=
finalColor
;
}
include/shaderPhongTexCust.h
0 → 100644
View file @
8bd8a582
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* 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. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef SHADER_PHONG_TEXTURE__CUST
#define SHADER_PHONG_TEXTURE__CUST
#include "Geometry/vector_gen.h"
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/textures.h"
#include "Utils/gl_def.h"
#include "Geometry/matrix.h"
using
namespace
CGoGN
;
class
ShaderPhongTexCust
:
public
Utils
::
ClippingShader
{
protected:
// shader sources
static
std
::
string
vertexShaderText
;
static
std
::
string
fragmentShaderText
;
CGoGNGLuint
m_unif_unit
;
int
m_unit
;
Utils
::
GTexture
*
m_tex_ptr
;
// flag color per vertex or not
bool
m_with_eyepos
;
// uniform locations
CGoGNGLuint
m_unif_ambient
;
CGoGNGLuint
m_unif_specular
;
CGoGNGLuint
m_unif_shininess
;
CGoGNGLuint
m_unif_lightPos
;
CGoGNGLuint
m_unif_eyePos
;
//values
float
m_ambient
;
Geom
::
Vec4f
m_specular
;
float
m_shininess
;
Geom
::
Vec3f
m_lightPos
;
Geom
::
Vec3f
m_eyePos
;
Utils
::
VBO
*
m_vboPos
;
Utils
::
VBO
*
m_vboNormal
;
Utils
::
VBO
*
m_vboTexCoord
;
void
getLocations
();
void
sendParams
();
void
restoreUniformsAttribs
();
public:
ShaderPhongTexCust
(
bool
doubleSided
=
false
,
bool
withEyePosition
=
false
);
/**
* choose the texture unit engine to use for this texture
*/
void
setTextureUnit
(
GLenum
texture_unit
);
/**
* set the texture to use
*/
void
setTexture
(
Utils
::
GTexture
*
tex
);
/**
* activation of texture unit with set texture
*/
void
activeTexture
();
/**
* activation of texture unit with texture id
*/
void
activeTexture
(
CGoGNGLuint
texId
);
// inviduals parameter setting functions
void
setAmbient
(
float
ambient
);
void
setSpecular
(
const
Geom
::
Vec4f
&
specular
);
void
setShininess
(
float
shininess
);
void
setLightPosition
(
const
Geom
::
Vec3f
&
lp
);
/// set eye position for VR environement
void
setEyePosition
(
const
Geom
::
Vec3f
&
ep
);
float
getAmbiant
()
const
{
return
m_ambient
;
}
const
Geom
::
Vec4f
&
getSpecular
()
const
{
return
m_specular
;
}
float
getShininess
()
const
{
return
m_shininess
;
}
const
Geom
::
Vec3f
&
getLightPosition
()
const
{
return
m_lightPos
;
}
/**
* set all parameter in on call (one bind also)
*/
void
setParams
(
float
ambient
,
const
Geom
::
Vec4f
&
specular
,
float
shininess
,
const
Geom
::
Vec3f
&
lightPos
);
unsigned
int
setAttributePosition
(
Utils
::
VBO
*
vbo
);
unsigned
int
setAttributeNormal
(
Utils
::
VBO
*
vbo
);
unsigned
int
setAttributeTexCoord
(
Utils
::
VBO
*
vbo
);
void
setTransformation
(
Geom
::
Matrix44f
t
);
};
#endif
/* SHADER_PHONG_TEXTURE__CUST */
include/shaderPhongTexCust.vert
0 → 100644
View file @
8bd8a582
// ShaderPhongTexCust::vertexShaderText
ATTRIBUTE
vec3
VertexPosition
;
ATTRIBUTE
vec3
VertexNormal
;
ATTRIBUTE
vec2
VertexTexCoord
;
uniform
mat4
TransformationMatrix
;
uniform
mat4
ModelViewProjectionMatrix
;
uniform
mat4
ModelViewMatrix
;
uniform
mat4
NormalMatrix
;
uniform
vec3
lightPosition
;
VARYING_VERT
vec3
EyeVector
,
Normal
,
LightDir
;
VARYING_VERT
vec2
texCoord
;
#ifdef WITH_EYEPOSITION
uniform
vec3
eyePosition
;
#endif
INVARIANT_POS
;
void
main
()
{
Normal
=
vec3
(
NormalMatrix
*
vec4
(
VertexNormal
,
0
.
0
));
vec3
Position
=
vec3
(
ModelViewMatrix
*
TransformationMatrix
*
vec4
(
VertexPosition
,
1
.
0
));
LightDir
=
lightPosition
-
Position
;
#ifdef WITH_EYEPOSITION
EyeVector
=
eyePosition
-
Position
;
#else
EyeVector
=
-
Position
;
#endif
texCoord
=
VertexTexCoord
;
gl_Position
=
ModelViewProjectionMatrix
*
TransformationMatrix
*
vec4
(
VertexPosition
,
1
.
0
);
}
include/viewer.h
View file @
8bd8a582
...
...
@@ -54,10 +54,11 @@
#include "Utils/pointSprite.h"
#include "shaderCustom.h"
#include "shaderPhongTexCust.h"
//#define EXPORTING
//#define ONERING
#define SHADOWSHELL
//
#define SHADOWSHELL
using
namespace
CGoGN
;
...
...
@@ -133,7 +134,8 @@ public:
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>*
m_textureAgent
;
Utils
::
VBO
*
m_texcoordVBOAgent
;
ShaderCustomTex
*
m_shaderTexAgent
;
// ShaderCustomTex* m_shaderTexAgent;
ShaderPhongTexCust
*
m_shaderTexAgent
;
Algo
::
Surface
::
Import
::
OBJModel
<
PFP2
>
m_objAgent
;
unsigned
int
m_nbIndicesAgent
;
#endif
...
...
@@ -173,7 +175,9 @@ public:
// ARASH : camera input file
std
::
ifstream
cam_input_file
;
bool
cif_exists
;
unsigned
int
cif_begin
,
cif_end
;
VEC3
*
cif_lookfrom
;
VEC3
*
cif_lookat
;
VEC3
*
cif_upvector
;
...
...
src/agent.cpp
View file @
8bd8a582
...
...
@@ -21,12 +21,12 @@ float Agent::averageMaxSpeed_ = 2.0f ;
//float Agent::neighborDist_ = 20.0f ;
float
Agent
::
neighborDistSq_
=
neighborDist_
*
neighborDist_
;
//float Agent::radius_ = 8.0f ;
//
float Agent::radius_ = 3.0f ;
float Agent::radius_ = 1.5f ;
float
Agent
::
radius_
=
3.0
f
;
//
float Agent::radius_ = 1.5f ;
float
Agent
::
timeHorizon_
=
10.0
f
;
//float Agent::timeHorizon_ = 100.0f ;
float
Agent
::
timeHorizonObst_
=
10.0
f
;
float Agent::range_ =
2
*timeHorizonObst_ * averageMaxSpeed_ + radius_ ;
float
Agent
::
range_
=
4
*
timeHorizonObst_
*
averageMaxSpeed_
+
radius_
;
float
Agent
::
rangeSq_
=
range_
*
range_
;
unsigned
int
Agent
::
cptAgent
=
0
;
...
...
@@ -123,7 +123,7 @@ void Agent::init(const VEC3& start, const VEC3& goal)
// color1=0;
// color2 = 1.0f;
// }
for (unsigned int i=0 ; i<
4
; ++i)
for
(
unsigned
int
i
=
0
;
i
<
SMOOTHING_BUFFER_SIZE
;
++
i
)
meanVelocity_
[
i
].
set
(
0
)
;
agentNeighbors_
.
reserve
(
maxNeighbors_
*
2
)
;
...
...
@@ -506,11 +506,11 @@ void Agent::update()
#endif
meanDirection_
.
set
(
0
)
;
for (unsigned int i=0 ; i<
4
; ++i) {
for
(
unsigned
int
i
=
0
;
i
<
SMOOTHING_BUFFER_SIZE
;
++
i
)
{
meanDirection_
+=
meanVelocity_
[
i
]
;
meanVelocity_[i] = meanVelocity_[(i+1)%
4
] ;
meanVelocity_
[
i
]
=
meanVelocity_
[(
i
+
1
)
%
SMOOTHING_BUFFER_SIZE
]
;
}
meanVelocity_[
3
] = velocity_ ;
meanVelocity_
[
SMOOTHING_BUFFER_SIZE
-
1
]
=
velocity_
;
meanDirection_
.
normalize
()
;
}
...
...
@@ -751,7 +751,7 @@ void Agent::computeNewVelocity()
VEC3
normFace
=
VEC3
(
0
,
0
,
1
);
#endif
double
collision_softening_factor
;
float ag_ambient_damping =
1
0.0;
float
ag_ambient_damping
=
5
0.0
;
// double mass_var = 0.95;
// double average_mass = 1.0;
...
...
@@ -765,7 +765,7 @@ void Agent::computeNewVelocity()
double
rand
=
2.0
*
drand48
()
-
1.0
;
// compris entre -1 et 1
// double ag_mass = average_mass*(1 + rand*mass_var); // valeurs uniformement réparties entre min et max
double ag_mass =
5
0.0;
double
ag_mass
=
20
0.0
;
/*
rand = 2.0*drand48()-1.0; // compris entre -1 et 1
radius_ = average_radius + rand*radius_var; // valeurs uniformement réparties entre min et max
...
...
@@ -805,7 +805,7 @@ void Agent::computeNewVelocity()
obst_radius_infl
=
100.
;
// scenario 0
else
obst_radius_infl
=
40.
;
// scenario 1 et 3
float force_value;
float
force_value
=
0.0
;
int
nobst
=
0
;
...
...
@@ -881,13 +881,14 @@ void Agent::computeNewVelocity()
// double fixed_obst_stiffness = 50000.0; // agent-obstacle interaction stiffness
double
fixed_obst_stiffness
=
5000.0
;
// agent-obstacle interaction stiffness
// double fixed_obst_damping = 1.0; // agent-obstacle interaction damping
int fixed_obst_power =
1
; // the power to which elevate the agent-obstacle distance
int
fixed_obst_power
=
4.0
;
// the power to which elevate the agent-obstacle distance
Obstacle
*
fixed_obst
;
for
(
std
::
vector
<
std
::
pair
<
float
,
Obstacle
*>
>::
iterator
it
=
obstacleNeighbors_
.
begin
()
;
it
!=
obstacleNeighbors_
.
end
()
;
++
it
)
{
double
dist
=
it
->
first
;
// cerr << "nobst=" << nobst << "dist=" << dist << endl;
// double effective_range = 50*range_;
...
...
@@ -900,29 +901,33 @@ void Agent::computeNewVelocity()
}
fixed_obst
=
it
->
second
;
if(fixed_obst->mo!=NULL)
cerr << "Collision avec limace !!!" << endl;
VEC3
p1
=
fixed_obst
->
p1
;
VEC3
p2
=
fixed_obst
->
p2
;
vec
=
p2
-
p1
;
vec
.
normalize
();
norm
=
normFace
^
vec
;
forces
-=
force_value
*
norm
;
// cerr << "obstacles fixes : nobst=" << nobst << " dist=" << dist << " force=" << force_value*norm << endl;
nobst
++
;
}
//----- forces dues à la répulsion des autres agents -------
double
ag_stiffness
=
400.0
;
// agent-agent interaction stiffness
double
ag_damping
=
1.0
;
// agent-agent interaction damping
// double ag_power = 1
; // the power to which elevate the agent-agent distance
double
ag_power
=
4.0
;
// the power to which elevate the agent-agent distance
rand
=
2.0
*
drand48
()
-
1.0
;
// compris entre -1 et 1
double
radius_var
=
0.5
;
double
ag_phys_radius_coef
=
2.0
*
(
1
+
rand
*
radius_var
);
// valeurs uniformement réparties entre min et max
unsigned
int
nbA
=
0
;
for
(
std
::
vector
<
std
::
pair
<
float
,
Agent
*>
>::
iterator
it
=
agentNeighbors_
.
begin
()
;
...
...
@@ -950,8 +955,7 @@ void Agent::computeNewVelocity()
if
(
dist
<
combinedRadius
)
{
// collision_softening_factor = pow(1-dist/combinedRadius,ag_power);
collision_softening_factor = 1;
collision_softening_factor
=
pow
(
1
-
dist
/
combinedRadius
,
ag_power
);
float
force_value
=
-
ag_stiffness
*
collision_softening_factor
*
(
combinedRadius
-
dist
)
-
ag_damping
*
(
dist
-
previous_dist
)
/
sim_
->
timeStep_
;
...
...
src/env_map.cpp
View file @
8bd8a582
...
...
@@ -262,6 +262,7 @@ void EnvMap::initGL()
std::vector<std::string> texturenames;
std::string dir("./meshRessources/PlaneteRessource/");
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL)
...
...
@@ -314,6 +315,7 @@ void EnvMap::initGL()
position_nmap.push_back(position_Export);
TraversorV<PFP2::MAP> tV(*nmap);
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
//// {
//// position_Export[d] *= 100.0f;
...
...
@@ -321,6 +323,7 @@ void EnvMap::initGL()
//// }
Geom::BoundingBox<PFP::VEC3> bbTest2 = Algo::Geometry::computeBoundingBox<PFP>(*nmap, position_Export) ;
bbTest.addPoint(bbTest2.min());
bbTest.addPoint(bbTest2.max());
...
...
src/moving_mesh.cpp
View file @
8bd8a582
...
...
@@ -56,22 +56,24 @@ void MovingMesh::initGL()
m_texture
=
new
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>
(
GL_UNSIGNED_BYTE
);
if
(
m_texture
->
load
(
"./meshRessources/limace.png"
))
// if (m_texture->load("./meshRessources/scenario3/limace_occ.png"))
m_texture
->
update
();
else
std
::
cout
<<
"problem : loading texture"
<<
std
::
endl
;
m_texture
->
setWrapping
(
GL_CLAMP_TO_EDGE
);
m_shaderTex
=
new
ShaderCustomTex
();
// m_shaderTex = new ShaderCustomTex();
m_shaderTex
=
new
Utils
::
ShaderPhongTexture
();
// m_shaderTex = new Utils::ShaderSimpleTexture();
m_shaderTex
->
setAttributePosition
(
m_positionVBO
);
m_shaderTex
->
setAttributeTexCoord
(
m_texcoordVBO
);
//
m_shaderTex->setAttributeNormal(m_normalVBO);
m_shaderTex
->
setAttributeNormal
(
m_normalVBO
);
m_shaderTex
->
setTextureUnit
(
GL_TEXTURE0
);
m_shaderTex
->
setTexture
(
m_texture
);
// m_shaderTex->setShininess(10.0
f);
// m_shaderTex->setAmbient(0.1
f);
// m_shaderTex->setSpecular(Geom::Vec4f(0.
5));
m_shaderTex
->
setShininess
(
0.1
f
);
m_shaderTex
->
setAmbient
(
0.5
f
);
m_shaderTex
->
setSpecular
(
Geom
::
Vec4f
(
0.0
5
));
glEnable
(
GL_TEXTURE_2D
);
...
...
src/shaderPhongTexCust.cpp
0 → 100644
View file @
8bd8a582
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* 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. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <GL/glew.h>
#include "shaderPhongTexCust.h"
#include "shaderPhongTexCust.vert"
#include "shaderPhongTexCust.frag"
ShaderPhongTexCust
::
ShaderPhongTexCust
(
bool
doubleSided
,
bool
withEyePosition
)
:
m_with_eyepos
(
withEyePosition
),
m_ambient
(
0.1
f
),
m_specular
(
Geom
::
Vec4f
(
1.0
f
,
1.0
f
,
1.0
f
,
0.0
f
)),
m_shininess
(
100.0
f
),
m_lightPos
(
Geom
::
Vec3f
(
10.0
f
,
10.0
f
,
1000.0
f
)),
m_vboPos
(
NULL
),
m_vboNormal
(
NULL
),
m_vboTexCoord
(
NULL
)
{
m_nameVS
=
"ShaderPhongTexCust_vs"
;
m_nameFS
=
"ShaderPhongTexCust_fs"
;
// get choose GL defines (2 or 3)
// ans compile shaders
std
::
string
glxvert
(
*
GLSLShader
::
DEFINES_GL
);
if
(
m_with_eyepos
)
glxvert
.
append
(
"#define WITH_EYEPOSITION"
);
glxvert
.
append
(
vertexShaderText
);
std
::
string
glxfrag
(
*
GLSLShader
::
DEFINES_GL
);
// Use double sided lighting if set
if
(
doubleSided
)
glxfrag
.
append
(
"#define DOUBLE_SIDED
\n
"
);
glxfrag
.
append
(
fragmentShaderText
);
loadShadersFromMemory
(
glxvert
.
c_str
(),
glxfrag
.
c_str
());
// and get and fill uniforms
getLocations
();
sendParams
();
Geom
::
Matrix44f
id
;
id
.
identity
();
setTransformation
(
id
);
}
void
ShaderPhongTexCust
::
getLocations
()
{
bind
();
*
m_unif_unit
=
glGetUniformLocation
(
this
->
program_handler
(),
"textureUnit"
);
*
m_unif_ambient
=
glGetUniformLocation
(
this
->
program_handler
(),
"ambientCoef"
);
*
m_unif_specular
=
glGetUniformLocation
(
this
->
program_handler
(),
"materialSpecular"
);
*
m_unif_shininess
=
glGetUniformLocation
(
this
->
program_handler
(),
"shininess"
);
*
m_unif_lightPos
=
glGetUniformLocation
(
this
->
program_handler
(),
"lightPosition"
);
if
(
m_with_eyepos
)
*
m_unif_eyePos
=
glGetUniformLocation
(
this
->
program_handler
(),
"eyePosition"
);
unbind
();
}
void
ShaderPhongTexCust
::
sendParams
()
{
bind
();
glUniform1i
(
*
m_unif_unit
,
m_unit
);
glUniform1f
(
*
m_unif_ambient
,
m_ambient
);
glUniform4fv
(
*
m_unif_specular
,
1
,
m_specular
.
data
());
glUniform1f
(
*
m_unif_shininess
,
m_shininess
);
glUniform3fv
(
*
m_unif_lightPos
,
1
,
m_lightPos
.
data
());
if
(
m_with_eyepos
)
glUniform3fv
(
*
m_unif_eyePos
,
1
,
m_eyePos
.
data
());
unbind
();
}
void
ShaderPhongTexCust
::
setTextureUnit
(
GLenum
texture_unit
)
{
bind
();
int
unit
=
texture_unit
-
GL_TEXTURE0
;
glUniform1iARB
(
*
m_unif_unit
,
unit
);
m_unit
=
unit
;
unbind
();
}
void
ShaderPhongTexCust
::
setTexture
(
Utils
::
GTexture
*
tex
)
{
m_tex_ptr
=
tex
;
}
void
ShaderPhongTexCust
::
activeTexture
()
{
glActiveTexture
(
GL_TEXTURE0
+
m_unit
);
m_tex_ptr
->
bind
();
}
void
ShaderPhongTexCust
::
activeTexture
(
CGoGNGLuint
texId
)
{
glActiveTexture
(
GL_TEXTURE0
+
m_unit
);