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
c5d97851
Commit
c5d97851
authored
May 28, 2013
by
Thomas Jund
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shader for mexicans
parent
339ca17b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
444 additions
and
2 deletions
+444
-2
Debug/CMakeLists.txt
Debug/CMakeLists.txt
+1
-0
Release/CMakeLists.txt
Release/CMakeLists.txt
+1
-0
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
+3
-1
src/shaderPhongTexCust.cpp
src/shaderPhongTexCust.cpp
+221
-0
src/viewer.cpp
src/viewer.cpp
+7
-1
No files found.
Debug/CMakeLists.txt
View file @
c5d97851
...
...
@@ -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 @
c5d97851
...
...
@@ -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/shaderPhongTexCust.frag
0 → 100644
View file @
c5d97851
// 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 @
c5d97851
/*******************************************************************************
* 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 @
c5d97851
// 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 @
c5d97851
...
...
@@ -54,6 +54,7 @@
#include "Utils/pointSprite.h"
#include "shaderCustom.h"
#include "shaderPhongTexCust.h"
//#define EXPORTING
//#define ONERING
...
...
@@ -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
...
...
src/shaderPhongTexCust.cpp
0 → 100644
View file @
c5d97851
/*******************************************************************************
* 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
);
glBindTexture
(
GL_TEXTURE_2D
,
*
texId
);
}
void
ShaderPhongTexCust
::
setAmbient
(
float
ambient
)
{
bind
();
glUniform1f
(
*
m_unif_ambient
,
ambient
);
m_ambient
=
ambient
;
unbind
();
}
void
ShaderPhongTexCust
::
setSpecular
(
const
Geom
::
Vec4f
&
specular
)
{
bind
();
glUniform4fv
(
*
m_unif_specular
,
1
,
specular
.
data
());
m_specular
=
specular
;
unbind
();
}
void
ShaderPhongTexCust
::
setShininess
(
float
shininess
)
{
bind
();
glUniform1f
(
*
m_unif_shininess
,
shininess
);
m_shininess
=
shininess
;
unbind
();
}
void
ShaderPhongTexCust
::
setLightPosition
(
const
Geom
::
Vec3f
&
lightPos
)
{
bind
();
glUniform3fv
(
*
m_unif_lightPos
,
1
,
lightPos
.
data
());
m_lightPos
=
lightPos
;
unbind
();
}
void
ShaderPhongTexCust
::
setEyePosition
(
const
Geom
::
Vec3f
&
eyePos
)
{
if
(
m_with_eyepos
)
{
bind
();
glUniform3fv
(
*
m_unif_eyePos
,
1
,
eyePos
.
data
());
m_eyePos
=
eyePos
;
unbind
();
}
}
void
ShaderPhongTexCust
::
setParams
(
float
ambient
,
const
Geom
::
Vec4f
&
specular
,
float
shininess
,
const
Geom
::
Vec3f
&
lightPos
)
{
m_ambient
=
ambient
;
m_specular
=
specular
;
m_shininess
=
shininess
;
m_lightPos
=
lightPos
;
sendParams
();
}
void
ShaderPhongTexCust
::
restoreUniformsAttribs
()
{
getLocations
();
sendParams
();
bind
();
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexNormal"
,
m_vboNormal
);
bindVA_VBO
(
"VertexTexCoord"
,
m_vboTexCoord
);
unbind
();
}
unsigned
int
ShaderPhongTexCust
::
setAttributePosition
(
Utils
::
VBO
*
vbo
)
{
m_vboPos
=
vbo
;
bind
();
unsigned
int
id
=
bindVA_VBO
(
"VertexPosition"
,
vbo
);
unbind
();
return
id
;
}
unsigned
int
ShaderPhongTexCust
::
setAttributeNormal
(
Utils
::
VBO
*
vbo
)
{
m_vboNormal
=
vbo
;
bind
();
unsigned
int
id
=
bindVA_VBO
(
"VertexNormal"
,
vbo
);
unbind
();
return
id
;
}
unsigned
int
ShaderPhongTexCust
::
setAttributeTexCoord
(
Utils
::
VBO
*
vbo
)
{
m_vboTexCoord
=
vbo
;
bind
();
unsigned
int
id
=
bindVA_VBO
(
"VertexTexCoord"
,
vbo
);
unbind
();
return
id
;
}
void
ShaderPhongTexCust
::
setTransformation
(
Geom
::
Matrix44f
t
)
{
bind
();
CGoGNGLuint
m_transf
;
*
m_transf
=
glGetUniformLocation
(
program_handler
(),
"TransformationMatrix"
);
glUniformMatrix4fv
(
*
m_transf
,
1
,
false
,
&
t
(
0
,
0
));
unbind
();
}
\ No newline at end of file
src/viewer.cpp
View file @
c5d97851
...
...
@@ -396,11 +396,17 @@ void SocialAgents::initRendering()
m_textureAgent->setWrapping(GL_CLAMP_TO_EDGE);
m_shaderTexAgent = new ShaderCustomTex();
// m_shaderTexAgent = new ShaderCustomTex();
m_shaderTexAgent = new ShaderPhongTexCust();
m_shaderTexAgent->setAttributePosition(m_positionVBOAgent);
m_shaderTexAgent->setAttributeTexCoord(m_texcoordVBOAgent);
m_shaderTexAgent->setTextureUnit(GL_TEXTURE0);
m_shaderTexAgent->setTexture(m_textureAgent);
m_shaderTexAgent->setAttributeNormal(m_normalVBOAgent);
m_shaderTexAgent->setShininess(0.1f);
m_shaderTexAgent->setAmbient(0.5f);
m_shaderTexAgent->setSpecular(Geom::Vec4f(0.05));
glEnable(GL_TEXTURE_2D);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment