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
51ad10fa
Commit
51ad10fa
authored
Jun 20, 2011
by
Maire Nicolas
Browse files
Rajout d'une option d'éclairage double face pour le shader de phong.
parent
3d9eddf0
Changes
9
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/CMakeLists.txt
View file @
51ad10fa
...
...
@@ -72,6 +72,12 @@ add_executable( stage_shader stage_shader.cpp ${stage_shader_ui} ${stage_shader_
target_link_libraries
(
stage_shader
${
CGoGN_LIBS_D
}
${
COMMON_LIBS
}
${
QT_LIBRARIES
}
)
QT4_WRAP_UI
(
stage_shader_number_two_ui stage_shader_number_two.ui
)
QT4_WRAP_CPP
(
stage_shader_number_two_moc stage_shader_number_two.h
)
add_executable
(
stage_shader_number_two stage_shader_number_two.cpp
${
stage_shader_number_two_moc
}
${
stage_shader_number_two_ui
}
)
target_link_libraries
(
stage_shader_number_two
${
CGoGN_LIBS_D
}
${
NUMERICAL_LIBS
}
${
COMMON_LIBS
}
${
QT_LIBRARIES
}
)
#add_executable( tuto_subdivision tuto_subdivision.cpp)
#target_link_libraries( tuto_subdivision
...
...
include/Utils/Shaders/shaderPhong.h
View file @
51ad10fa
...
...
@@ -26,6 +26,7 @@
#define __CGOGN_SHADER_PHONG__
#include
"Utils/GLSLShader.h"
#include
"Utils/clippingShader.h"
#include
"Geometry/vector_gen.h"
#include
<string>
...
...
@@ -36,7 +37,7 @@ namespace CGoGN
namespace
Utils
{
class
ShaderPhong
:
public
GLSL
Shader
class
ShaderPhong
:
public
Clipping
Shader
{
protected:
// flag color per vertex or not
...
...
@@ -71,7 +72,7 @@ protected:
void
restoreUniformsAttribs
();
public:
ShaderPhong
();
ShaderPhong
(
bool
doubleSided
=
false
);
// inviduals parameter setting functions
void
setAmbiant
(
const
Geom
::
Vec4f
&
ambiant
);
...
...
include/Utils/Shaders/shaderSimpleColor.h
View file @
51ad10fa
...
...
@@ -39,10 +39,10 @@ class ShaderSimpleColor : public ClippingShader
{
protected:
// shader sources
static
std
::
string
vertexShaderText
;
static
std
::
string
fragmentShaderText
;
static
std
::
string
vertexShaderText
;
static
std
::
string
fragmentShaderText
;
// uniform locations
// uniform locations
GLuint
m_unif_color
;
Geom
::
Vec4f
m_color
;
...
...
src/Utils/Shaders/shaderColorPerVertex.cpp
View file @
51ad10fa
...
...
@@ -80,8 +80,10 @@ unsigned int ShaderColorPerVertex::setAttributeColor(VBO* vbo)
void
ShaderColorPerVertex
::
restoreUniformsAttribs
()
{
bind
();
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexColor"
,
m_vboCol
);
unbind
();
}
}
// namespace Utils
...
...
src/Utils/Shaders/shaderPhong.cpp
View file @
51ad10fa
...
...
@@ -76,7 +76,15 @@ std::string ShaderPhong::fragmentShaderText =
" float lambertTerm = dot(N,L);
\n
"
" vec4 finalColor = materialAmbient;
\n
"
" if(lambertTerm > 0.0)
\n
"
" #ifdef DOUBLE_SIDED
\n
"
" if (lambertTerm < 0.0)
\n
"
" {
\n
"
" N = -1.0*N;
\n
"
" lambertTerm = -1.0*lambertTerm;
\n
"
" }
\n
"
" #else
\n
"
" if (lambertTerm > 0.0)
\n
"
" #endif
\n
"
" {
\n
"
" #ifndef WITH_COLOR
\n
"
" finalColor += materialDiffuse * lambertTerm;
\n
"
...
...
@@ -92,19 +100,25 @@ std::string ShaderPhong::fragmentShaderText =
"}"
;
ShaderPhong
::
ShaderPhong
()
:
ShaderPhong
::
ShaderPhong
(
bool
doubleSided
)
:
m_with_color
(
false
),
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_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_lightPos
(
Geom
::
Vec3f
(
10.0
f
,
10.0
f
,
1000.0
f
)),
m_vboPos
(
NULL
),
m_vboNormal
(
NULL
),
m_vboColor
(
NULL
)
{
// get choose GL defines (2 or 3)
// ans compile shaders
std
::
string
glxvert
(
*
GLSLShader
::
DEFINES_GL
);
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
());
...
...
@@ -227,12 +241,15 @@ void ShaderPhong::unsetAttributeColor()
void
ShaderPhong
::
restoreUniformsAttribs
()
{
getLocations
();
bind
();
sendParams
();
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexNormal"
,
m_vboNormal
);
if
(
m_vboColor
)
bindVA_VBO
(
"VertexColor"
,
m_vboColor
);
unbind
();
}
unsigned
int
ShaderPhong
::
setAttributePosition
(
VBO
*
vbo
)
...
...
src/Utils/Shaders/shaderSimpleColor.cpp
View file @
51ad10fa
...
...
@@ -93,6 +93,7 @@ void ShaderSimpleColor::restoreUniformsAttribs()
bind
();
glUniform4fv
(
m_unif_color
,
1
,
m_color
.
data
());
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
unbind
();
}
}
// namespace Utils
...
...
src/Utils/Shaders/shaderVectorPerVertex.cpp
View file @
51ad10fa
...
...
@@ -130,9 +130,10 @@ void ShaderVectorPerVertex::restoreUniformsAttribs()
{
getLocations
();
sendParams
();
bind
();
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexVector"
,
m_vboVec
);
unbind
();
}
}
// namespace Utils
...
...
src/Utils/clippingShader.cpp
View file @
51ad10fa
...
...
@@ -32,9 +32,11 @@ namespace Utils
ClippingShader
::
ClippingShader
()
{
// Default values for plane clipping
m_clipPlane
=
Geom
::
Vec4f
(
0.5
,
0.5
,
0.5
,
0.0
);
m_unif_clipPlane
=
0
;
// Default values for color attenuation
m_colorAttenuationFactor
=
0.0
;
m_unif_colorAttenuationFactor
=
0
;
}
...
...
@@ -55,6 +57,9 @@ void ClippingShader::setClippingColorAttenuationFactor(float colorAttenuationFac
void
ClippingShader
::
addPlaneClippingToShaderSource
()
{
// Shader name
std
::
string
shaderName
=
m_nameVS
+
"/"
+
m_nameFS
+
"/"
+
m_nameGS
;
// Verify that the shader has been well created
if
(
!
isCreated
())
{
...
...
@@ -62,10 +67,9 @@ void ClippingShader::addPlaneClippingToShaderSource()
<<
"ERROR - "
<<
"ClippingShader::addPlaneClippingToShaderSource"
<<
" - Could not process shader "
<<
m_n
ame
VS
<<
shaderN
ame
<<
" source code : shader has not been created or has failed to compile"
<<
CGoGNendl
;
// TODO : add real shader name - add m_name attribute to GLSLShader Class
return
;
}
...
...
@@ -76,10 +80,9 @@ void ClippingShader::addPlaneClippingToShaderSource()
<<
"ERROR - "
<<
"ClippingShader::addPlaneClippingToShaderSource"
<<
" - Could not process shader "
<<
m_n
ame
VS
<<
shaderN
ame
<<
" source code : unable to add clipping to a shader which uses a geometry shader"
<<
CGoGNendl
;
// TODO : add real shader name - add m_name attribute to GLSLShader Class
return
;
}
...
...
@@ -128,7 +131,7 @@ void ClippingShader::addPlaneClippingToShaderSource()
// Use a shader mutator
ShaderMutator
SM
(
"S
hader
"
,
getVertexShaderSrc
(),
getFragmentShaderSrc
(),
""
);
// TODO : send the real shader name
ShaderMutator
SM
(
s
hader
Name
,
getVertexShaderSrc
(),
getFragmentShaderSrc
(),
""
);
// First check if the vertex shader contains the VertexPosition attribute
if
(
!
SM
.
VS_containsVariableDeclaration
(
"VertexPosition"
))
...
...
@@ -162,6 +165,9 @@ void ClippingShader::addPlaneClippingToShaderSource()
void
ClippingShader
::
updateClippingUniforms
()
{
// Shader name
std
::
string
shaderName
=
m_nameVS
+
"/"
+
m_nameFS
+
"/"
+
m_nameGS
;
// Get uniforms locations
m_unif_clipPlane
=
glGetUniformLocation
(
program_handler
(),
"clip_ClipPlane"
);
if
(
m_unif_clipPlane
==
-
1
)
...
...
@@ -170,10 +176,9 @@ void ClippingShader::updateClippingUniforms()
<<
"ERROR - "
<<
"ClippingShader::addPlaneClippingToShaderSource"
<<
" - uniform 'clip_ClipPlane' not found in shader "
<<
m_n
ame
VS
<<
shaderN
ame
<<
CGoGNendl
;
}
// TODO : add real shader name - add m_name attribute to GLSLShader Class
m_unif_colorAttenuationFactor
=
glGetUniformLocation
(
program_handler
(),
"clip_ColorAttenuationFactor"
);
if
(
m_unif_colorAttenuationFactor
==
-
1
)
{
...
...
@@ -181,10 +186,9 @@ void ClippingShader::updateClippingUniforms()
<<
"ERROR - "
<<
"ClippingShader::addPlaneClippingToShaderSource"
<<
" - uniform 'clip_ColorAttenuationFactor' not found in shader "
<<
m_n
ame
VS
<<
shaderN
ame
<<
CGoGNendl
;
}
// TODO : add real shader name - add m_name attribute to GLSLShader Class
// Set uniforms values
setPlaneClippingParams
(
m_clipPlane
);
...
...
src/Utils/shaderMutator.cpp
View file @
51ad10fa
...
...
@@ -150,7 +150,7 @@ void ShaderMutator::VS_insertCodeAtMainFunctionEnd(const std::string& insertedCo
<<
"Unable to insert source code in vertex shader of "
<<
m_shaderName
<<
". You should check if the shader has a main function declaration "
<<
"and as many '{' as '}'"
<<
"and as many '{' as '}'
in main
"
<<
CGoGNendl
;
}
}
...
...
@@ -165,7 +165,7 @@ void ShaderMutator::FS_insertCodeAtMainFunctionEnd(const std::string& insertedCo
<<
"Unable to insert source code in fragment shader of "
<<
m_shaderName
<<
". You should check if the shader has a main function declaration "
<<
"and as many '{' as '}'"
<<
"and as many '{' as '}'
in main
"
<<
CGoGNendl
;
}
}
...
...
@@ -180,7 +180,7 @@ void ShaderMutator::GS_insertCodeAtMainFunctionEnd(const std::string& insertedCo
<<
"Unable to insert source code in geometry shader of "
<<
m_shaderName
<<
". You should check if the shader has a main function declaration "
<<
"and as many '{' as '}'"
<<
"and as many '{' as '}'
in main
"
<<
CGoGNendl
;
}
}
...
...
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