Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CGoGN
CGoGN
Commits
f1a875bb
Commit
f1a875bb
authored
May 03, 2011
by
Kenneth Vanhoey
Browse files
shader for PTM and import/export for PTM of superior degrees
parent
c23c68f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/tuto_ogl3.cpp
View file @
f1a875bb
...
...
@@ -108,8 +108,6 @@ void MyQT::cb_initGL()
shader1
->
setAttributePosition
(
positionVBO
);
shader1
->
setAttributeNormal
(
normalVBO
);
registerShader
(
shader1
);
currentShader
=
shader1
;
}
...
...
include/Algo/Export/export.hpp
View file @
f1a875bb
...
...
@@ -247,6 +247,154 @@ bool exportCTM(typename PFP::MAP& the_map, const typename PFP::TVEC3& position,
return
true
;
}
template
<
typename
PFP
>
bool
exportPLYPTM
(
typename
PFP
::
MAP
&
map
,
const
char
*
filename
,
const
typename
PFP
::
TVEC3
&
position
,
const
typename
PFP
::
TVEC3
frame
[
3
],
const
typename
PFP
::
TVEC3
colorPTM
[
15
],
const
FunctorSelect
&
good
)
{
typedef
typename
PFP
::
MAP
MAP
;
typedef
typename
PFP
::
VEC3
VEC3
;
std
::
ofstream
out
(
filename
,
std
::
ios
::
out
)
;
if
(
!
out
.
good
())
{
std
::
cerr
<<
"Unable to open file "
<<
std
::
endl
;
return
false
;
}
AutoAttributeHandler
<
unsigned
int
>
tableVertLab
(
map
,
VERTEX_ORBIT
);
CellMarker
markV
(
map
,
VERTEX_CELL
);
unsigned
int
nbDarts
=
map
.
getNbDarts
()
;
std
::
vector
<
unsigned
int
>
vertices
;
std
::
vector
<
unsigned
int
>
faces
;
vertices
.
reserve
(
nbDarts
/
5
);
// TODO non optimal reservation
faces
.
reserve
(
nbDarts
/
3
);
DartMarker
markF
(
map
);
unsigned
int
lab
=
0
;
unsigned
int
nbf
=
0
;
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
{
if
(
good
(
d
)
&&
!
markF
.
isMarked
(
d
))
{
markF
.
markOrbit
(
FACE_ORBIT
,
d
)
;
Dart
e
=
d
;
std
::
vector
<
unsigned
int
>
face
;
do
{
if
(
!
markV
.
isMarked
(
e
))
{
vertices
.
push_back
(
map
.
getEmbedding
(
e
,
VERTEX_ORBIT
));
tableVertLab
[
e
]
=
lab
++
;
markV
.
mark
(
e
);
}
face
.
push_back
(
tableVertLab
[
e
]);
e
=
map
.
phi1
(
e
);
}
while
(
e
!=
d
)
;
faces
.
push_back
(
face
.
size
())
;
for
(
unsigned
int
i
=
0
;
i
<
face
.
size
()
;
++
i
)
faces
.
push_back
(
face
.
at
(
i
))
;
++
nbf
;
}
}
out
<<
"ply"
<<
std
::
endl
;
out
<<
"format ascii 1.0"
<<
std
::
endl
;
out
<<
"comment ply PTM"
<<
std
::
endl
;
out
<<
"element vertex "
<<
vertices
.
size
()
<<
std
::
endl
;
out
<<
"property float x"
<<
std
::
endl
;
out
<<
"property float y"
<<
std
::
endl
;
out
<<
"property float z"
<<
std
::
endl
;
out
<<
"property float tx"
<<
std
::
endl
;
out
<<
"property float ty"
<<
std
::
endl
;
out
<<
"property float tz"
<<
std
::
endl
;
out
<<
"property float bx"
<<
std
::
endl
;
out
<<
"property float by"
<<
std
::
endl
;
out
<<
"property float bz"
<<
std
::
endl
;
out
<<
"property float nx"
<<
std
::
endl
;
out
<<
"property float ny"
<<
std
::
endl
;
out
<<
"property float nz"
<<
std
::
endl
;
out
<<
"property float L1_a0"
<<
std
::
endl
;
out
<<
"property float L1_a1"
<<
std
::
endl
;
out
<<
"property float L1_a2"
<<
std
::
endl
;
out
<<
"property float L1_a3"
<<
std
::
endl
;
out
<<
"property float L1_a4"
<<
std
::
endl
;
out
<<
"property float L1_a5"
<<
std
::
endl
;
out
<<
"property float L1_a6"
<<
std
::
endl
;
out
<<
"property float L1_a7"
<<
std
::
endl
;
out
<<
"property float L1_a8"
<<
std
::
endl
;
out
<<
"property float L1_a9"
<<
std
::
endl
;
out
<<
"property float L1_a10"
<<
std
::
endl
;
out
<<
"property float L1_a11"
<<
std
::
endl
;
out
<<
"property float L1_a12"
<<
std
::
endl
;
out
<<
"property float L1_a13"
<<
std
::
endl
;
out
<<
"property float L1_a14"
<<
std
::
endl
;
out
<<
"property float L2_a0"
<<
std
::
endl
;
out
<<
"property float L2_a1"
<<
std
::
endl
;
out
<<
"property float L2_a2"
<<
std
::
endl
;
out
<<
"property float L2_a3"
<<
std
::
endl
;
out
<<
"property float L2_a4"
<<
std
::
endl
;
out
<<
"property float L2_a5"
<<
std
::
endl
;
out
<<
"property float L2_a6"
<<
std
::
endl
;
out
<<
"property float L2_a7"
<<
std
::
endl
;
out
<<
"property float L2_a8"
<<
std
::
endl
;
out
<<
"property float L2_a9"
<<
std
::
endl
;
out
<<
"property float L2_a10"
<<
std
::
endl
;
out
<<
"property float L2_a11"
<<
std
::
endl
;
out
<<
"property float L2_a12"
<<
std
::
endl
;
out
<<
"property float L2_a13"
<<
std
::
endl
;
out
<<
"property float L2_a14"
<<
std
::
endl
;
out
<<
"property float L3_a0"
<<
std
::
endl
;
out
<<
"property float L3_a1"
<<
std
::
endl
;
out
<<
"property float L3_a2"
<<
std
::
endl
;
out
<<
"property float L3_a3"
<<
std
::
endl
;
out
<<
"property float L3_a4"
<<
std
::
endl
;
out
<<
"property float L3_a5"
<<
std
::
endl
;
out
<<
"property float L3_a6"
<<
std
::
endl
;
out
<<
"property float L3_a7"
<<
std
::
endl
;
out
<<
"property float L3_a8"
<<
std
::
endl
;
out
<<
"property float L3_a9"
<<
std
::
endl
;
out
<<
"property float L3_a10"
<<
std
::
endl
;
out
<<
"property float L3_a11"
<<
std
::
endl
;
out
<<
"property float L3_a12"
<<
std
::
endl
;
out
<<
"property float L3_a13"
<<
std
::
endl
;
out
<<
"property float L3_a14"
<<
std
::
endl
;
out
<<
"element face "
<<
nbf
<<
std
::
endl
;
out
<<
"property list uchar int vertex_indices"
<<
std
::
endl
;
out
<<
"end_header"
<<
std
::
endl
;
for
(
unsigned
int
i
=
0
;
i
<
vertices
.
size
();
++
i
)
{
unsigned
int
vi
=
vertices
[
i
];
out
<<
position
[
vi
][
0
]
<<
" "
<<
position
[
vi
][
1
]
<<
" "
<<
position
[
vi
][
2
]
<<
" "
;
out
<<
frame
[
0
][
vi
][
0
]
<<
" "
<<
frame
[
0
][
vi
][
1
]
<<
" "
<<
frame
[
0
][
vi
][
2
]
<<
" "
;
out
<<
frame
[
1
][
vi
][
0
]
<<
" "
<<
frame
[
1
][
vi
][
1
]
<<
" "
<<
frame
[
1
][
vi
][
2
]
<<
" "
;
out
<<
frame
[
2
][
vi
][
0
]
<<
" "
<<
frame
[
2
][
vi
][
1
]
<<
" "
<<
frame
[
2
][
vi
][
2
]
<<
" "
;
out
<<
colorPTM
[
0
][
vi
][
0
]
<<
" "
<<
colorPTM
[
1
][
vi
][
0
]
<<
" "
<<
colorPTM
[
2
][
vi
][
0
]
<<
" "
<<
colorPTM
[
3
][
vi
][
0
]
<<
" "
<<
colorPTM
[
4
][
vi
][
0
]
<<
" "
<<
colorPTM
[
5
][
vi
][
0
]
<<
" "
<<
colorPTM
[
6
][
vi
][
0
]
<<
" "
<<
colorPTM
[
7
][
vi
][
0
]
<<
" "
<<
colorPTM
[
8
][
vi
][
0
]
<<
" "
<<
colorPTM
[
9
][
vi
][
0
]
<<
" "
<<
colorPTM
[
10
][
vi
][
0
]
<<
" "
<<
colorPTM
[
11
][
vi
][
0
]
<<
" "
<<
colorPTM
[
12
][
vi
][
0
]
<<
" "
<<
colorPTM
[
13
][
vi
][
0
]
<<
" "
<<
colorPTM
[
14
][
vi
][
0
]
<<
" "
;
out
<<
colorPTM
[
0
][
vi
][
1
]
<<
" "
<<
colorPTM
[
1
][
vi
][
1
]
<<
" "
<<
colorPTM
[
2
][
vi
][
1
]
<<
" "
<<
colorPTM
[
3
][
vi
][
1
]
<<
" "
<<
colorPTM
[
4
][
vi
][
1
]
<<
" "
<<
colorPTM
[
5
][
vi
][
1
]
<<
" "
<<
colorPTM
[
6
][
vi
][
1
]
<<
" "
<<
colorPTM
[
7
][
vi
][
1
]
<<
" "
<<
colorPTM
[
8
][
vi
][
1
]
<<
" "
<<
colorPTM
[
9
][
vi
][
1
]
<<
" "
<<
colorPTM
[
10
][
vi
][
1
]
<<
" "
<<
colorPTM
[
11
][
vi
][
1
]
<<
" "
<<
colorPTM
[
12
][
vi
][
1
]
<<
" "
<<
colorPTM
[
13
][
vi
][
1
]
<<
" "
<<
colorPTM
[
14
][
vi
][
1
]
<<
" "
;
out
<<
colorPTM
[
0
][
vi
][
2
]
<<
" "
<<
colorPTM
[
1
][
vi
][
2
]
<<
" "
<<
colorPTM
[
2
][
vi
][
2
]
<<
" "
<<
colorPTM
[
3
][
vi
][
2
]
<<
" "
<<
colorPTM
[
4
][
vi
][
2
]
<<
" "
<<
colorPTM
[
5
][
vi
][
2
]
<<
" "
<<
colorPTM
[
6
][
vi
][
2
]
<<
" "
<<
colorPTM
[
7
][
vi
][
2
]
<<
" "
<<
colorPTM
[
8
][
vi
][
2
]
<<
" "
<<
colorPTM
[
9
][
vi
][
2
]
<<
" "
<<
colorPTM
[
10
][
vi
][
2
]
<<
" "
<<
colorPTM
[
11
][
vi
][
2
]
<<
" "
<<
colorPTM
[
12
][
vi
][
2
]
<<
" "
<<
colorPTM
[
13
][
vi
][
2
]
<<
" "
<<
colorPTM
[
14
][
vi
][
2
]
<<
std
::
endl
;
}
std
::
vector
<
unsigned
int
>::
iterator
it
=
faces
.
begin
();
while
(
it
!=
faces
.
end
())
{
unsigned
int
nbe
=
*
it
++
;
out
<<
nbe
;
for
(
unsigned
int
j
=
0
;
j
<
nbe
;
++
j
)
out
<<
" "
<<
*
it
++
;
out
<<
std
::
endl
;
}
out
.
close
()
;
return
true
;
}
/*
template <typename PFP>
bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename PFP::TVEC3& position, const typename PFP::TVEC3 frame[3], const typename PFP::TVEC3 colorPTM[6], const FunctorSelect& good)
{
...
...
@@ -365,7 +513,7 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P
out.close() ;
return true ;
}
}
*/
}
// namespace Export
...
...
include/Algo/Import/import2tablesSurface.hpp
View file @
f1a875bb
...
...
@@ -529,6 +529,137 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
template
<
typename
PFP
>
bool
MeshTablesSurface
<
PFP
>::
importPlyPTM
(
const
std
::
string
&
filename
,
std
::
vector
<
std
::
string
>&
attrNames
)
{
AttributeHandler
<
typename
PFP
::
VEC3
>
positions
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"position"
)
;
attrNames
.
push_back
(
positions
.
name
())
;
AttributeHandler
<
typename
PFP
::
VEC3
>
frame
[
3
]
;
frame
[
0
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"frame_T"
)
;
// Tangent
frame
[
1
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"frame_B"
)
;
// Bitangent
frame
[
2
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"frame_N"
)
;
// Normal
for
(
unsigned
int
i
=
0
;
i
<
3
;
++
i
)
attrNames
.
push_back
(
frame
[
i
].
name
())
;
AttributeHandler
<
typename
PFP
::
VEC3
>
colorPTM
[
15
]
;
colorPTM
[
0
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a0"
)
;
colorPTM
[
1
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a1"
)
;
colorPTM
[
2
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a2"
)
;
colorPTM
[
3
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a3"
)
;
colorPTM
[
4
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a4"
)
;
colorPTM
[
5
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a5"
)
;
colorPTM
[
6
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a6"
)
;
colorPTM
[
7
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a7"
)
;
colorPTM
[
8
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a8"
)
;
colorPTM
[
9
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a9"
)
;
colorPTM
[
10
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a10"
)
;
colorPTM
[
11
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a11"
)
;
colorPTM
[
12
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a12"
)
;
colorPTM
[
13
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a13"
)
;
colorPTM
[
14
]
=
m_map
.
template
addAttribute
<
typename
PFP
::
VEC3
>(
VERTEX_ORBIT
,
"colorPTM_a14"
)
;
for
(
unsigned
int
i
=
0
;
i
<
15
;
++
i
)
attrNames
.
push_back
(
colorPTM
[
i
].
name
())
;
AttributeContainer
&
container
=
m_map
.
getAttributeContainer
(
VERTEX_CELL
)
;
std
::
ifstream
fp
(
filename
.
c_str
(),
std
::
ios
::
binary
);
if
(
!
fp
.
good
())
{
std
::
cerr
<<
"Unable to open file "
<<
filename
<<
std
::
endl
;
return
false
;
}
std
::
string
ligne
;
std
::
string
tag
;
fp
>>
tag
;
if
(
tag
!=
std
::
string
(
"ply"
))
{
std
::
cerr
<<
filename
<<
" is not a ply file !"
<<
std
::
endl
;
return
false
;
}
// va au nombre de sommets
do
{
fp
>>
tag
;
}
while
(
tag
!=
std
::
string
(
"vertex"
));
unsigned
int
nbp
;
fp
>>
nbp
;
// read points
std
::
vector
<
unsigned
int
>
verticesID
;
verticesID
.
reserve
(
nbp
);
// va au nombre de faces en comptant le nombre de "property"
unsigned
int
nb_props
=
0
;
do
{
fp
>>
tag
;
if
(
tag
==
std
::
string
(
"property"
))
nb_props
++
;
}
while
(
tag
!=
std
::
string
(
"face"
));
fp
>>
m_nbFaces
;
m_nbEdges
.
reserve
(
m_nbFaces
);
m_emb
.
reserve
(
3
*
m_nbFaces
);
// lecture des sommets
// saute à la fin du header
do
{
fp
>>
tag
;
}
while
(
tag
!=
std
::
string
(
"end_header"
));
float
*
properties
=
new
float
[
nb_props
];
for
(
unsigned
int
i
=
0
;
i
<
nbp
;
++
i
)
{
unsigned
int
id
=
container
.
insertLine
();
verticesID
.
push_back
(
id
);
for
(
unsigned
int
j
=
0
;
j
<
nb_props
;
++
j
)
{
fp
>>
properties
[
j
];
}
positions
[
id
]
=
VEC3
(
properties
[
0
],
properties
[
1
],
properties
[
2
]);
for
(
unsigned
int
k
=
0
;
k
<
3
;
++
k
)
for
(
unsigned
int
l
=
0
;
l
<
3
;
++
l
)
frame
[
k
][
id
][
l
]
=
properties
[
3
+
(
3
*
k
+
l
)]
;
for
(
unsigned
int
k
=
0
;
k
<
3
;
++
k
)
for
(
unsigned
int
l
=
0
;
l
<
15
;
++
l
)
colorPTM
[
l
][
id
][
k
]
=
properties
[
12
+
(
15
*
k
+
l
)];
}
m_nbVertices
=
verticesID
.
size
();
delete
[]
properties
;
// read indices of faces
for
(
unsigned
int
i
=
0
;
i
<
m_nbFaces
;
i
++
)
{
// read the indices vertices of face
int
nbe
;
fp
>>
nbe
;
m_nbEdges
.
push_back
(
nbe
);
int
pt
;
for
(
int
j
=
0
;
j
<
nbe
;
++
j
)
{
fp
>>
pt
;
m_emb
.
push_back
(
verticesID
[
pt
]);
}
}
fp
.
close
();
return
true
;
}
/*template <typename PFP>
bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames)
{
AttributeHandler<typename PFP::VEC3> positions = m_map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
...
...
@@ -651,7 +782,7 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect
fp.close();
return true;
}
}
*/
template
<
typename
PFP
>
bool
MeshTablesSurface
<
PFP
>::
importCTM
(
const
std
::
string
&
filename
,
std
::
vector
<
std
::
string
>&
attrNames
)
...
...
include/Utils/shaderPTM.h
0 → 100644
View file @
f1a875bb
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_PHONG__
#define __CGOGN_SHADER_PHONG__
#include
<GL/glew.h>
#include
"Utils/GLSLShader.h"
#include
"Geometry/vector_gen.h"
#include
<string>
namespace
CGoGN
{
namespace
Utils
{
class
ShaderPTM
:
public
GLSLShader
{
protected:
// shader sources OGL3
static
std
::
string
vertexShaderText
;
static
std
::
string
fragmentShaderText
;
// uniform locations
GLuint
m_unif_cameraPos
;
GLuint
m_unif_proj
;
//values
Geom
::
Vec3f
m_cameraPos
;
unsigned
int
m_proj
;
VBO
*
m_vboPos
;
VBO
*
m_vboFi
;
VBO
*
m_vboFn
;
VBO
*
m_vboA0
;
VBO
*
m_vboA3
;
VBO
*
m_vboA6
;
VBO
*
m_vboA9
;
VBO
*
m_vboA12
;
void
getLocations
();
void
sendParams
();
void
restoreUniformsAttribs
();
public:
ShaderPTM
();
// inviduals parameter setting functions
void
setCameraPos
(
const
Geom
::
Vec3f
&
camera
)
;
void
setProjectionType
(
const
unsigned
int
&
proj
)
;
const
Geom
::
Vec3f
&
getCameraPosition
()
const
{
return
m_cameraPos
;
}
const
unsigned
int
&
getProjectionType
()
const
{
return
m_proj
;
}
/**
* set all parameter in on call (one bind also)
*/
void
setParams
(
const
Geom
::
Vec3f
&
cameraPos
,
const
unsigned
int
&
proj
)
;
// attributes
unsigned
int
setAttributePosition
(
VBO
*
vbo
)
;
unsigned
int
setAttributeFi
(
VBO
*
vbo
)
;
unsigned
int
setAttributeFn
(
VBO
*
vbo
)
;
unsigned
int
setAttributeA0
(
VBO
*
vbo
)
;
unsigned
int
setAttributeA3
(
VBO
*
vbo
)
;
unsigned
int
setAttributeA6
(
VBO
*
vbo
)
;
unsigned
int
setAttributeA9
(
VBO
*
vbo
)
;
unsigned
int
setAttributeA12
(
VBO
*
vbo
)
;
}
;
}
// namespace Utils
}
// namespace CGoGN
#endif
src/Utils/shaderPTM.cpp
0 → 100644
View file @
f1a875bb
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
"Utils/shaderPTM.h"
namespace
CGoGN
{
namespace
Utils
{
std
::
string
ShaderPTM
::
vertexShaderText
=
"ATTRIBUTE vec3 VertexPosition;
\n
"
"ATTRIBUTE vec3 Fi,Fn;
\n
"
"ATTRIBUTE vec3 a0,a3,a6,a9,a12;
\n
"
"uniform mat4 ModelViewProjectionMatrix;
\n
"
"uniform mat4 ModelViewMatrix;
\n
"
//"uniform mat4 NormalMatrix;\n"
"uniform vec3 cameraPosition;
\n
"
"uniform int projectionType;
\n
"
"VARYING_VERT vec3 vcolour;
\n
"
"INVARIANT_POS;
\n
"
"void main ()
\n
"
"{
\n
"
" vec3 Fj = cross(Fn, Fi) ;
\n
"
"
\n
"
" vec3 eyeV = cameraPosition - VertexPosition;
\n
"
" eyeV = normalize(eyeV) ;
\n
"
"
\n
"
" if (dot(eyeV,Fn) < 0.0)
\n
"
" vcolour = vec3(0.0,0.0,0.0) ;
\n
"
" else {
\n
"
" float u = dot(eyeV,Fi) ;
\n
"
" float v = dot(eyeV,Fj) ;
\n
"
"
\n
"
" /** orthographic --> nothing to add **/
\n
"
" /** authalic **/
\n
"
" if (projectionType == 1) {
\n
"
" float k = sqrt(2.0 / (dot(eyeV,Fn) + 1.0) ) ;
\n
"
" u *= k ;
\n
"
" v *= k ;
\n
"
" }
\n
"
" /** conform **/
\n
"
" if (projectionType == 2) {
\n
"
" float k = dot(eyeV,Fn) + 1.0 ;
\n
"
" u /= k ;
\n
"
" v /= k ;
\n
"
" }
\n
"
"
\n
"
" /** Function evaluation **/
\n
"
" float t = a0.x + a0.y*v + a0.z*u + a3.x*u*v + a3.y*v*v + a3.z*u*u + a6.x*u*v*v + a6.y*u*u*v + a6.z*v*v*v + a9.x*u*u*u + a9.y*u*u*v*v + a9.z*u*v*v*v + a12.x*u*u*u*v + a12.y*v*v*v*v + a12.z*u*u*u*u ;
\n
"
" vcolour = vec3(t,t,t) ;
\n
"
"
\n
"
" /*vcolour = vec3 (
\n
"
" u*u*u*a9.x + v*v*v*a8.x + u*u*v*a7.x + u*v*v*a6.x + u*u*a5.x + v*v*a4.x + u*v*a3.x + u*a2.x + v*a1.x + a0.x,
\n
"
" u*u*u*a9.y + v*v*v*a8.y + u*u*v*a7.y + u*v*v*a6.y + u*u*a5.y + v*v*a4.y + u*v*a3.y + u*a2.y + v*a1.y + a0.y,
\n
"
" u*u*u*a9.z + v*v*v*a8.z + u*u*v*a7.z + u*v*v*a6.z + u*u*a5.z + v*v*a4.z + u*v*a3.z + u*a2.z + v*a1.z + a0.z) ;*/
\n
"
" }
\n
"
" vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));
\n
"
" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
\n
"
"}"
;
std
::
string
ShaderPTM
::
fragmentShaderText
=
"PRECISON;
\n
"
"VARYING_FRAG vec3 vcolour;
\n
"
"FRAG_OUT_DEF;
\n
"
"void main (void)
\n
"
"{
\n
"
" gl_FragColor = vec4(vcolour,1.0) ;
\n
"
"}"
;
ShaderPTM
::
ShaderPTM
()
:
m_cameraPos
(
Geom
::
Vec3f
(
10.0
f
,
10.0
f
,
1000.0
f
)),
m_proj
(
0
)
{
// get choose GL defines (2 or 3)
// and compile shaders
std
::
string
glxvert
(
*
GLSLShader
::
DEFINES_GL
);
glxvert
.
append
(
vertexShaderText
);
std
::
string
glxfrag
(
*
GLSLShader
::
DEFINES_GL
);
glxfrag
.
append
(
fragmentShaderText
);
loadShadersFromMemory
(
glxvert
.
c_str
(),
glxfrag
.
c_str
());
// and get and fill uniforms
bind
();
getLocations
();
sendParams
();
}
void
ShaderPTM
::
getLocations
()
{
m_unif_cameraPos
=
glGetUniformLocation
(
this
->
program_handler
(),
"cameraPosition"
);
m_unif_proj
=
glGetUniformLocation
(
this
->
program_handler
(),
"projectionType"
);
}
void
ShaderPTM
::
sendParams
()
{
glUniform3fv
(
m_unif_cameraPos
,
1
,
m_cameraPos
.
data
());
glUniform1i
(
m_unif_proj
,
m_proj
);
}
void
ShaderPTM
::
setCameraPos
(
const
Geom
::
Vec3f
&
camera
)
{
this
->
bind
();
glUniform3fv
(
m_unif_cameraPos
,
1
,
camera
.
data
());
m_cameraPos
=
camera
;
}
void
ShaderPTM
::
setProjectionType
(
const
unsigned
int
&
proj
)
{
this
->
bind
()
;
glUniform1i
(
m_unif_proj
,
proj
)
;
m_proj
=
proj
;
}
void
ShaderPTM
::
setParams
(
const
Geom
::
Vec3f
&
camera
,
const
unsigned
int
&
proj
)
{
m_cameraPos
=
camera
;
m_proj
=
proj
;
bind
();
sendParams
();
}
void
ShaderPTM
::
restoreUniformsAttribs
()
{
getLocations
();
sendParams
();
// TODO
// bindVA_VBO("cameraPosition", m_cameraPos);
// bindVA_VBO("projectionType", m_proj);
}
unsigned
int
ShaderPTM
::
setAttributePosition
(
VBO
*
vbo
)
{
m_vboPos
=
vbo
;
return
bindVA_VBO
(
"VertexPosition"
,
vbo
);
}
unsigned
int
ShaderPTM
::
setAttributeFi
(
VBO
*
vbo
)
{
m_vboPos
=
vbo
;
return
bindVA_VBO
(
"Fi"
,
vbo
);
}
unsigned
int
ShaderPTM
::
setAttributeFn
(
VBO
*
vbo
)
{