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
C
CGoGN
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
KennethVanhoey
CGoGN
Commits
38b7c311
Commit
38b7c311
authored
Jan 30, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add shader: FlatColorPerFace
parent
333c45d8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
299 additions
and
10 deletions
+299
-10
Debug/CMakeLists.txt
Debug/CMakeLists.txt
+7
-5
Release/CMakeLists.txt
Release/CMakeLists.txt
+7
-5
include/Utils/Shaders/shaderFlatColorPerFace.frag
include/Utils/Shaders/shaderFlatColorPerFace.frag
+6
-0
include/Utils/Shaders/shaderFlatColorPerFace.geom
include/Utils/Shaders/shaderFlatColorPerFace.geom
+47
-0
include/Utils/Shaders/shaderFlatColorPerFace.h
include/Utils/Shaders/shaderFlatColorPerFace.h
+81
-0
include/Utils/Shaders/shaderFlatColorPerFace.vert
include/Utils/Shaders/shaderFlatColorPerFace.vert
+10
-0
src/Utils/Shaders/shaderFlatColorPerFace.cpp
src/Utils/Shaders/shaderFlatColorPerFace.cpp
+141
-0
No files found.
Debug/CMakeLists.txt
View file @
38b7c311
...
...
@@ -47,14 +47,15 @@ file(
file
(
GLOB_RECURSE
# GLOB_RECURSE
GLOB
shaders_srcD
${
CGoGN_ROOT_DIR
}
/include/Utils/*.frag
${
CGoGN_ROOT_DIR
}
/include/Utils/*.vert
${
CGoGN_ROOT_DIR
}
/include/Utils/*.geom
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders*.frag
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders*.vert
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders*.geom
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders
/
*.frag
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders
/
*.vert
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders
/
*.geom
)
IF
(
WIN32
)
...
...
@@ -107,6 +108,7 @@ IF (ONELIB)
ELSE
(
WITH_QT
)
add_library
(
cgognD
${
files_topology
}
${
files_container
}
${
files_algo
}
${
files_utils
}
)
ENDIF
(
WITH_QT
)
add_dependencies
(
cgognD shader_targetD
)
ELSE
(
ONELIB
)
add_library
(
topologyD
${
files_topology
}
)
add_library
(
containerD
${
files_container
}
)
...
...
@@ -117,4 +119,4 @@ ELSE (ONELIB)
add_library
(
utilsD
${
files_utils
}
)
ENDIF
(
WITH_QT
)
add_dependencies
(
utilsD shader_targetD
)
ENDIF
(
ONELIB
)
\ No newline at end of file
ENDIF
(
ONELIB
)
Release/CMakeLists.txt
View file @
38b7c311
...
...
@@ -44,14 +44,15 @@ file(
file
(
GLOB_RECURSE
# GLOB_RECURSE
GLOB
shaders_src
${
CGoGN_ROOT_DIR
}
/include/Utils/*.frag
${
CGoGN_ROOT_DIR
}
/include/Utils/*.vert
${
CGoGN_ROOT_DIR
}
/include/Utils/*.geom
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders*.frag
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders*.vert
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders*.geom
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders
/
*.frag
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders
/
*.vert
${
CGoGN_ROOT_DIR
}
/include/Utils/Shaders
/
*.geom
)
...
...
@@ -103,6 +104,7 @@ IF (ONELIB)
ELSE
(
WITH_QT
)
add_library
(
cgogn
${
files_topology
}
${
files_container
}
${
files_algo
}
${
files_utils
}
)
ENDIF
(
WITH_QT
)
add_dependencies
(
cgogn shader_target
)
ELSE
(
ONELIB
)
add_library
(
container
${
files_container
}
)
add_library
(
topology
${
files_topology
}
)
...
...
@@ -113,4 +115,4 @@ ELSE (ONELIB)
add_library
(
utils
${
files_utils
}
)
ENDIF
(
WITH_QT
)
add_dependencies
(
utils shader_target
)
ENDIF
(
ONELIB
)
\ No newline at end of file
ENDIF
(
ONELIB
)
include/Utils/Shaders/shaderFlatColorPerFace.frag
0 → 100644
View file @
38b7c311
// ShaderFlatColorPerFace::fragmentShaderText
VARYING_FRAG
vec4
ColorFS
;
void
main
()
{
gl_FragColor
=
ColorFS
;
}
include/Utils/Shaders/shaderFlatColorPerFace.geom
0 → 100644
View file @
38b7c311
// ShaderFlatColorPerFace::geometryShaderText
uniform
float
explode
;
uniform
mat4
ModelViewProjectionMatrix
;
uniform
mat4
NormalMatrix
;
uniform
mat4
ModelViewMatrix
;
uniform
vec3
lightPosition
;
uniform
vec4
ambient
;
VARYING_IN
vec3
colorVertex
[];
VARYING_OUT
vec4
ColorFS
;
void
main
(
void
)
{
vec3
v1
=
POSITION_IN
(
1
).
xyz
-
POSITION_IN
(
0
).
xyz
;
vec3
v2
=
POSITION_IN
(
2
).
xyz
-
POSITION_IN
(
0
).
xyz
;
vec3
N
=
cross
(
v1
,
v2
);
N
=
normalize
(
vec3
(
NormalMatrix
*
vec4
(
N
,
0
.
0
)));
vec3
center
=
POSITION_IN
(
0
).
xyz
+
POSITION_IN
(
1
).
xyz
+
POSITION_IN
(
2
).
xyz
;
center
/=
3
.
0
;
vec4
newPos
=
ModelViewMatrix
*
vec4
(
center
,
0
.
0
);
vec3
L
=
normalize
(
lightPosition
-
newPos
.
xyz
);
float
lambertTerm
=
dot
(
N
,
L
);
int
i
;
vec
averageColor
(
0
.,
0
.,
0
.);
for
(
i
=
0
;
i
<
NBVERTS_IN
;
i
++
)
{
averageColor
+=
colorVertex
[
i
];
}
averageColor
/=
float
(
NBVERTS_IN
);
ColorFS
=
ambient
;
if
(
lambertTerm
>
0
.
0
)
ColorFS
+=
vec4
(
averageColor
,
1
.
0
)
*
lambertTerm
;
for
(
i
=
0
;
i
<
NBVERTS_IN
;
i
++
)
{
vec4
pos
=
explode
*
POSITION_IN
(
i
)
+
(
1
.
0
-
explode
)
*
vec4
(
center
,
1
.
0
);
gl_Position
=
ModelViewProjectionMatrix
*
pos
;
EmitVertex
();
}
EndPrimitive
();
}
include/Utils/Shaders/shaderFlatColorPerFace.h
0 → 100644
View file @
38b7c311
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_FLAT_COLOR_PER_FACE__
#define __CGOGN_SHADER_FLAT_COLOR_PER_FACE__
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
namespace
CGoGN
{
namespace
Utils
{
class
ShaderFlatColorPerFace
:
public
GLSLShader
{
protected:
// shader sources
static
std
::
string
vertexShaderText
;
static
std
::
string
fragmentShaderText
;
static
std
::
string
geometryShaderText
;
// uniform locations
GLuint
m_unif_ambiant
;
GLuint
m_unif_lightPos
;
GLuint
m_unif_explode
;
float
m_explode
;
Geom
::
Vec4f
m_ambiant
;
Geom
::
Vec3f
m_light_pos
;
VBO
*
m_vboPos
;
VBO
*
m_vboColor
;
void
getLocations
();
void
restoreUniformsAttribs
();
public:
ShaderFlatColorPerFace
();
void
setExplode
(
float
explode
);
void
setAmbiant
(
const
Geom
::
Vec4f
&
ambiant
);
void
setLightPosition
(
const
Geom
::
Vec3f
&
lp
);
void
setParams
(
float
explode
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec3f
&
lightPos
);
void
setAttributePosition
(
VBO
*
vbo
);
void
setAttributeColor
(
VBO
*
vbo
);
};
}
// namespace Utils
}
// namespace CGoGN
#endif
include/Utils/Shaders/shaderFlatColorPerFace.vert
0 → 100644
View file @
38b7c311
// ShaderFlatColorPerFace::vertexShaderText
ATTRIBUTE
vec3
VertexPosition
;
ATTRIBUTE
vec3
VertexColor
;
VARYING_VERT
vec3
colorVertex
;
void
main
()
{
gl_Position
=
vec4
(
VertexPosition
,
1
.
0
);
colorVertex
=
VertexColor
;
}
src/Utils/Shaders/shaderFlatColorPerFace.cpp
0 → 100644
View file @
38b7c311
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <string.h>
#include <GL/glew.h>
#include "Utils/Shaders/shaderFlatColorPerFace.h"
namespace
CGoGN
{
namespace
Utils
{
#include "shaderFlatColorPerFace.vert"
#include "shaderFlatColorPerFace.frag"
#include "shaderFlatColorPerFace.geom"
ShaderFlatColorPerFace
::
ShaderFlatColorPerFace
()
{
m_nameVS
=
"shaderFlatColorPerFace_vs"
;
m_nameFS
=
"shaderFlatColorPerFace_fs"
;
m_nameGS
=
"shaderFlatColorPerFace_gs"
;
std
::
string
glxvert
(
*
GLSLShader
::
DEFINES_GL
);
glxvert
.
append
(
vertexShaderText
);
std
::
string
glxgeom
=
GLSLShader
::
defines_Geom
(
"triangles"
,
"triangle_strip"
,
3
);
glxgeom
.
append
(
geometryShaderText
);
std
::
string
glxfrag
(
*
GLSLShader
::
DEFINES_GL
);
glxfrag
.
append
(
fragmentShaderText
);
loadShadersFromMemory
(
glxvert
.
c_str
(),
glxfrag
.
c_str
(),
glxgeom
.
c_str
(),
GL_TRIANGLES
,
GL_TRIANGLE_STRIP
,
3
);
getLocations
();
//Default values
m_explode
=
1.0
f
;
m_ambiant
=
Geom
::
Vec4f
(
0.05
f
,
0.05
f
,
0.1
f
,
0.0
f
);
m_light_pos
=
Geom
::
Vec3f
(
10.0
f
,
10.0
f
,
1000.0
f
);
setParams
(
m_explode
,
m_ambiant
,
m_light_pos
);
}
void
ShaderFlatColorPerFace
::
getLocations
()
{
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
m_unif_lightPos
=
glGetUniformLocation
(
program_handler
(),
"lightPosition"
);
}
void
ShaderFlatColorPerFace
::
setAttributePosition
(
VBO
*
vbo
)
{
m_vboPos
=
vbo
;
bindVA_VBO
(
"VertexPosition"
,
vbo
);
}
void
ShaderFlatColorPerFace
::
setAttributeColor
(
VBO
*
vbo
)
{
m_vboColor
=
vbo
;
bindVA_VBO
(
"VertexColor"
,
vbo
);
}
void
ShaderFlatColorPerFace
::
setParams
(
float
expl
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec3f
&
lightPos
)
{
m_explode
=
expl
;
m_ambiant
=
ambiant
;
m_light_pos
=
lightPos
;
bind
();
glUniform1f
(
m_unif_explode
,
expl
);
glUniform4fv
(
m_unif_ambiant
,
1
,
ambiant
.
data
());
glUniform3fv
(
m_unif_lightPos
,
1
,
lightPos
.
data
());
unbind
();
// ??
}
void
ShaderFlatColorPerFace
::
setExplode
(
float
explode
)
{
m_explode
=
explode
;
bind
();
glUniform1f
(
m_unif_explode
,
explode
);
}
void
ShaderFlatColorPerFace
::
setAmbiant
(
const
Geom
::
Vec4f
&
ambiant
)
{
m_ambiant
=
ambiant
;
bind
();
glUniform4fv
(
m_unif_ambiant
,
1
,
ambiant
.
data
());
}
void
ShaderFlatColorPerFace
::
setLightPosition
(
const
Geom
::
Vec3f
&
lp
)
{
m_light_pos
=
lp
;
bind
();
glUniform3fv
(
m_unif_lightPos
,
1
,
lp
.
data
());
}
void
ShaderFlatColorPerFace
::
restoreUniformsAttribs
()
{
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
m_unif_lightPos
=
glGetUniformLocation
(
program_handler
(),
"lightPosition"
);
bind
();
glUniform1f
(
m_unif_explode
,
m_explode
);
glUniform4fv
(
m_unif_ambiant
,
1
,
m_ambiant
.
data
());
glUniform3fv
(
m_unif_lightPos
,
1
,
m_light_pos
.
data
());
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexColor"
,
m_vboPos
);
unbind
();
}
}
// namespace Utils
}
// namespace CGoGN
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