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
Thomas Pitiot
CGoGN
Commits
c1c330dd
Commit
c1c330dd
authored
Sep 12, 2014
by
Sylvain Thery
Browse files
bug shader
parent
26dd6409
Changes
7
Hide whitespace changes
Inline
Side-by-side
Apps/Examples/viewer.cpp
View file @
c1c330dd
...
...
@@ -78,7 +78,7 @@ void Viewer::initGUI()
void
Viewer
::
cb_initGL
()
{
Utils
::
GLSLShader
::
setCurrentOGLVersion
(
3
)
;
Utils
::
GLSLShader
::
setCurrentOGLVersion
(
2
)
;
CGoGNout
<<
"GL VERSION = "
<<
glGetString
(
GL_VERSION
)
<<
CGoGNendl
;
Utils
::
GLSLShader
::
areShadersSupported
();
...
...
@@ -102,6 +102,7 @@ void Viewer::cb_initGL()
m_flatShader
->
setAttributePosition
(
m_positionVBO
)
;
m_flatShader
->
setAmbiant
(
colClear
)
;
m_flatShader
->
setDiffuse
(
colDif
)
;
m_flatShader
->
setDiffuseBack
(
Geom
::
Vec4f
(
0
,
0
,
0
,
0
))
;
m_flatShader
->
setExplode
(
faceShrinkage
)
;
m_vectorShader
=
new
Utils
::
ShaderVectorPerVertex
()
;
...
...
include/Utils/Shaders/shaderFlat.frag
View file @
c1c330dd
// ShaderFlat::fragmentShaderText
VARYING_FRAG
vec4
ColorFS
;
uniform
vec4
diffuse
;
uniform
vec4
diffuseBack
;
uniform
vec4
ambient
;
VARYING_FRAG
float
lambertTerm
;
FRAG_OUT_DEF
;
void
main
()
{
gl_FragColor
=
ColorFS
;
if
(
gl_FrontFacing
)
gl_FragColor
=
ambient
+
lambertTerm
*
diffuse
;
else
gl_FragColor
=
ambient
+
lambertTerm
*
diffuseBack
;
}
include/Utils/Shaders/shaderFlat.geom
View file @
c1c330dd
...
...
@@ -5,24 +5,20 @@ uniform mat4 ModelViewProjectionMatrix;
uniform
mat4
NormalMatrix
;
uniform
mat4
ModelViewMatrix
;
uniform
vec3
lightPosition
;
uniform
vec4
diffuse
;
uniform
vec4
ambient
;
VARYING_OUT
vec4
ColorFS
;
VARYING_OUT
float
lambertTerm
;
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
)));
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
,
1
.
0
);
vec3
L
=
normalize
(
lightPosition
-
newPos
.
xyz
);
float
lambertTerm
=
dot
(
N
,
L
);
ColorFS
=
ambient
;
if
(
lambertTerm
>
0
.
0
)
ColorFS
+=
diffuse
*
lambertTerm
;
lambertTerm
=
clamp
(
dot
(
N
,
L
),
0
.
0
,
1
.
0
);
int
i
;
for
(
i
=
0
;
i
<
NBVERTS_IN
;
i
++
)
...
...
include/Utils/Shaders/shaderFlat.h
View file @
c1c330dd
...
...
@@ -45,12 +45,14 @@ protected:
// uniform locations
CGoGNGLuint
m_unif_ambiant
;
CGoGNGLuint
m_unif_diffuse
;
CGoGNGLuint
m_unif_diffuseback
;
CGoGNGLuint
m_unif_lightPos
;
CGoGNGLuint
m_unif_explode
;
float
m_explode
;
Geom
::
Vec4f
m_ambiant
;
Geom
::
Vec4f
m_diffuse
;
Geom
::
Vec4f
m_diffuseBack
;
Geom
::
Vec3f
m_light_pos
;
VBO
*
m_vboPos
;
...
...
@@ -68,9 +70,11 @@ public:
void
setDiffuse
(
const
Geom
::
Vec4f
&
diffuse
);
void
setDiffuseBack
(
const
Geom
::
Vec4f
&
diffuseb
);
void
setLightPosition
(
const
Geom
::
Vec3f
&
lp
);
void
setParams
(
float
explode
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec4f
&
diffuse
,
const
Geom
::
Vec3f
&
lightPos
);
void
setParams
(
float
explode
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec4f
&
diffuse
,
const
Geom
::
Vec4f
&
diffuseBack
,
const
Geom
::
Vec3f
&
lightPos
);
unsigned
int
setAttributePosition
(
VBO
*
vbo
);
};
...
...
include/Utils/Shaders/shaderPhong.frag
View file @
c1c330dd
...
...
@@ -14,28 +14,43 @@ void main()
{
vec3
N
=
normalize
(
Normal
);
vec3
L
=
normalize
(
LightDir
);
float
lambertTerm
=
dot
(
N
,
L
);
//
float lambertTerm =
clamp(
dot(N,L)
,0.0,1.0)
;
vec4
finalColor
=
materialAmbient
;
#ifdef DOUBLE_SIDED
if
(
lambertTerm
<
0
.
0
)
#ifdef DOUBLE_SIDED
float
lambertTerm
;
vec4
diffuseColor
=
materialDiffuse
;
if
(
!
gl_FrontFacing
)
{
N
=
-
1
.
0
*
N
;
lambertTerm
=
-
1
.
0
*
lambertTerm
;
#else
if
(
lambertTerm
>
0
.
0
)
N
*=
-
1
.
0
;
lambertTerm
=
clamp
(
dot
(
N
,
L
),
0
.
0
,
1
.
0
);
}
else
lambertTerm
=
clamp
(
dot
(
N
,
L
),
0
.
0
,
1
.
0
);
#ifndef WITH_COLOR
finalColor
+=
materialDiffuse
*
lambertTerm
;
#else
finalColor
+=
vec4
((
Color
*
lambertTerm
),
0
.
0
)
;
#endif
vec3
E
=
normalize
(
EyeVector
);
vec3
R
=
reflect
(
-
L
,
N
);
float
specular
=
pow
(
max
(
dot
(
R
,
E
),
0
.
0
),
shininess
);
finalColor
+=
materialSpecular
*
specular
;
#else
float
lambertTerm
=
clamp
(
dot
(
N
,
L
),
0
.
0
,
1
.
0
);
if
(
gl_FrontFacing
)
{
#endif
#ifndef WITH_COLOR
#ifndef WITH_COLOR
finalColor
+=
materialDiffuse
*
lambertTerm
;
#else
#else
finalColor
+=
vec4
((
Color
*
lambertTerm
),
0
.
0
)
;
#endif
#endif
vec3
E
=
normalize
(
EyeVector
);
vec3
R
=
reflect
(
-
L
,
N
);
float
specular
=
pow
(
max
(
dot
(
R
,
E
),
0
.
0
),
shininess
);
finalColor
+=
materialSpecular
*
specular
;
}
#endif
gl_FragColor
=
finalColor
;
}
src/Utils/Shaders/shaderFlat.cpp
View file @
c1c330dd
...
...
@@ -61,9 +61,10 @@ ShaderFlat::ShaderFlat()
m_explode
=
1.0
f
;
m_ambiant
=
Geom
::
Vec4f
(
0.05
f
,
0.05
f
,
0.1
f
,
0.0
f
);
m_diffuse
=
Geom
::
Vec4f
(
0.1
f
,
1.0
f
,
0.1
f
,
0.0
f
);
m_diffuseBack
=
m_diffuse
;
m_light_pos
=
Geom
::
Vec3f
(
10.0
f
,
10.0
f
,
1000.0
f
);
setParams
(
m_explode
,
m_ambiant
,
m_diffuse
,
m_light_pos
);
setParams
(
m_explode
,
m_ambiant
,
m_diffuse
,
m_diffuseBack
,
m_light_pos
);
}
void
ShaderFlat
::
getLocations
()
...
...
@@ -71,6 +72,7 @@ void ShaderFlat::getLocations()
*
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
*
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
*
m_unif_diffuse
=
glGetUniformLocation
(
program_handler
(),
"diffuse"
);
*
m_unif_diffuseback
=
glGetUniformLocation
(
program_handler
(),
"diffuseBack"
);
*
m_unif_lightPos
=
glGetUniformLocation
(
program_handler
(),
"lightPosition"
);
}
...
...
@@ -83,7 +85,7 @@ unsigned int ShaderFlat::setAttributePosition(VBO* vbo)
return
id
;
}
void
ShaderFlat
::
setParams
(
float
expl
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec4f
&
diffuse
,
const
Geom
::
Vec3f
&
lightPos
)
void
ShaderFlat
::
setParams
(
float
expl
,
const
Geom
::
Vec4f
&
ambiant
,
const
Geom
::
Vec4f
&
diffuse
,
const
Geom
::
Vec4f
&
diffuseBack
,
const
Geom
::
Vec3f
&
lightPos
)
{
m_explode
=
expl
;
m_ambiant
=
ambiant
;
...
...
@@ -95,6 +97,7 @@ void ShaderFlat::setParams(float expl, const Geom::Vec4f& ambiant, const Geom::V
glUniform1f
(
*
m_unif_explode
,
expl
);
glUniform4fv
(
*
m_unif_ambiant
,
1
,
ambiant
.
data
());
glUniform4fv
(
*
m_unif_diffuse
,
1
,
diffuse
.
data
());
glUniform4fv
(
*
m_unif_diffuseback
,
1
,
diffuseBack
.
data
());
glUniform3fv
(
*
m_unif_lightPos
,
1
,
lightPos
.
data
());
unbind
();
...
...
@@ -124,6 +127,14 @@ void ShaderFlat::setDiffuse(const Geom::Vec4f& diffuse)
unbind
();
}
void
ShaderFlat
::
setDiffuseBack
(
const
Geom
::
Vec4f
&
diffuseb
)
{
m_diffuseBack
=
diffuseb
;
bind
();
glUniform4fv
(
*
m_unif_diffuseback
,
1
,
diffuseb
.
data
());
unbind
();
}
void
ShaderFlat
::
setLightPosition
(
const
Geom
::
Vec3f
&
lp
)
{
m_light_pos
=
lp
;
...
...
@@ -134,16 +145,18 @@ void ShaderFlat::setLightPosition(const Geom::Vec3f& lp)
void
ShaderFlat
::
restoreUniformsAttribs
()
{
*
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
*
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
*
m_unif_diffuse
=
glGetUniformLocation
(
program_handler
(),
"diffuse"
);
*
m_unif_lightPos
=
glGetUniformLocation
(
program_handler
(),
"lightPosition"
);
*
m_unif_explode
=
glGetUniformLocation
(
program_handler
(),
"explode"
);
*
m_unif_ambiant
=
glGetUniformLocation
(
program_handler
(),
"ambient"
);
*
m_unif_diffuse
=
glGetUniformLocation
(
program_handler
(),
"diffuse"
);
*
m_unif_diffuseback
=
glGetUniformLocation
(
program_handler
(),
"diffuseBack"
);
*
m_unif_lightPos
=
glGetUniformLocation
(
program_handler
(),
"lightPosition"
);
bind
();
glUniform1f
(
*
m_unif_explode
,
m_explode
);
glUniform4fv
(
*
m_unif_ambiant
,
1
,
m_ambiant
.
data
());
glUniform4fv
(
*
m_unif_diffuse
,
1
,
m_diffuse
.
data
());
glUniform4fv
(
*
m_unif_diffuseback
,
1
,
m_diffuseBack
.
data
());
glUniform3fv
(
*
m_unif_lightPos
,
1
,
m_light_pos
.
data
());
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
...
...
src/Utils/Shaders/shaderPhong.cpp
View file @
c1c330dd
...
...
@@ -49,7 +49,7 @@ ShaderPhong::ShaderPhong(bool doubleSided, bool withEyePosition):
{
m_nameVS
=
"ShaderPhong_vs"
;
m_nameFS
=
"ShaderPhong_fs"
;
m_nameGS
=
"ShaderPhong_gs"
;
//
m_nameGS = "ShaderPhong_gs";
// get choose GL defines (2 or 3)
// ans compile shaders
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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