Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenFlipper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
2887d21a
Commit
2887d21a
authored
May 08, 2018
by
Jan Möbius
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'TwoSidedLighting_ShaderGen' into 'master'
Two sided lighting shader gen See merge request
!93
parents
2d95847e
e00cd322
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
10 deletions
+44
-10
SG_LIGHTING.GLSL
Shaders/ShaderGen/SG_LIGHTING.GLSL
+29
-7
ShaderGenerator.cc
libs_required/ACG/GL/ShaderGenerator.cc
+4
-2
ShaderGenerator.hh
libs_required/ACG/GL/ShaderGenerator.hh
+7
-0
MeshNode2T.cc
libs_required/ACG/Scenegraph/MeshNode2T.cc
+3
-0
renderObjectHighLighter.cc
widgets/rendererWidget/renderObjectHighLighter.cc
+1
-1
No files found.
Shaders/ShaderGen/SG_LIGHTING.GLSL
View file @
2887d21a
...
...
@@ -28,12 +28,20 @@ vec3 LitPointLight(vec3 vPosition,
vec3
cLight
=
cLightAmbient
*
g_cAmbient
;
// diffuse
float
ldotn
=
clamp
(
dot
(
vLightDir
,
vNormal
),
0
.
0
,
1
.
0
);
#ifdef TWO_SIDED_LIGHTING
float
ldotn
=
abs
(
clamp
(
dot
(
vLightDir
,
vNormal
),
-
1
.
0
,
1
.
0
));
#else
float
ldotn
=
clamp
(
dot
(
vLightDir
,
vNormal
),
0
.
0
,
1
.
0
);
#endif
cLight
+=
ldotn
*
cLightDiffuse
*
g_cDiffuse
;
// specular
vec3
h
=
normalize
(
vLightDir
-
vec3
(
0
,
0
,
-
1
));
// half vector between light and view direction
#ifdef TWO_SIDED_LIGHTING
float
hdotn
=
max
(
abs
(
dot
(
h
,
vNormal
)),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#else
float
hdotn
=
max
(
dot
(
h
,
vNormal
),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#endif
cLight
+=
(
pow
(
hdotn
,
SHININESS
)
*
cLightSpecular
)
*
g_cSpecular
;
...
...
@@ -55,12 +63,20 @@ vec3 LitDirLight(vec3 vPosition,
vec3
cLight
=
cLightAmbient
*
g_cAmbient
;
// diffuse
float
ldotn
=
clamp
(
dot
(
vLightDir
,
vNormal
),
0
.
0
,
1
.
0
);
#ifdef TWO_SIDED_LIGHTING
float
ldotn
=
abs
(
clamp
(
dot
(
vLightDir
,
vNormal
),
-
1
.
0
,
1
.
0
));
#else
float
ldotn
=
clamp
(
dot
(
vLightDir
,
vNormal
),
0
.
0
,
1
.
0
);
#endif
cLight
+=
ldotn
*
cLightDiffuse
*
g_cDiffuse
;
// specular
vec3
h
=
normalize
(
vLightDir
-
vec3
(
0
,
0
,
-
1
));
// half vector between light and view direction
float
hdotn
=
max
(
dot
(
h
,
vNormal
),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#ifdef TWO_SIDED_LIGHTING
float
hdotn
=
max
(
abs
(
dot
(
h
,
vNormal
)),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#else
float
hdotn
=
max
(
dot
(
h
,
vNormal
),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#endif
cLight
+=
(
pow
(
hdotn
,
SHININESS
)
*
cLightSpecular
)
*
g_cSpecular
;
return
cLight
;
...
...
@@ -88,15 +104,21 @@ vec3 LitSpotLight(vec3 vPosition,
vec3
cLight
=
cLightAmbient
*
g_cAmbient
;
// diffuse
float
ldotn
=
clamp
(
dot
(
vLightDir
,
vNormal
),
0
.
0
,
1
.
0
);
#ifdef TWO_SIDED_LIGHTING
float
ldotn
=
abs
(
clamp
(
dot
(
vLightDir
,
vNormal
),
-
1
.
0
,
1
.
0
));
#else
float
ldotn
=
clamp
(
dot
(
vLightDir
,
vNormal
),
0
.
0
,
1
.
0
);
#endif
cLight
+=
ldotn
*
cLightDiffuse
*
g_cDiffuse
;
// specular
vec3
h
=
normalize
(
vLightDir
-
vec3
(
0
,
0
,
-
1
));
// half vector between light and view direction
float
hdotn
=
max
(
dot
(
h
,
vNormal
),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#ifdef TWO_SIDED_LIGHTING
float
hdotn
=
max
(
abs
(
dot
(
h
,
vNormal
)),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#else
float
hdotn
=
max
(
dot
(
h
,
vNormal
),
0
.
001
);
// small epsilon to avoid undefined pow(0, 0) if shininess is also 0
#endif
cLight
+=
(
pow
(
hdotn
,
SHININESS
)
*
cLightSpecular
)
*
g_cSpecular
;
// attenuate
float
fAtten
=
vLightAtten
.
x
+
vLightAtten
.
y
*
fLen
+
vLightAtten
.
z
*
fLen2
;
...
...
libs_required/ACG/GL/ShaderGenerator.cc
View file @
2887d21a
...
...
@@ -1039,6 +1039,9 @@ void ShaderProgGenerator::initGenDefines(ShaderGenerator* _gen)
std
::
cout
<<
__FUNCTION__
<<
" -> unknown shade mode: "
<<
desc_
.
shadeMode
<<
std
::
endl
;
}
if
(
desc_
.
twoSidedLighting
)
_gen
->
addDefine
(
"TWO_SIDED_LIGHTING 1"
);
if
(
desc_
.
textured
())
_gen
->
addDefine
(
"SG_TEXTURED 1"
);
...
...
@@ -2761,9 +2764,8 @@ QString ShaderGenDesc::toString() const
resStrm
<<
"}"
;
}
}
resStrm
<<
"
\n
shaderDesc.shadeMode: "
<<
shadeModeString
[
shadeMode
];
resStrm
<<
"
\n
shaderDesc.twoSidedLighting: "
<<
(
twoSidedLighting
?
"Yes"
:
"No"
);
resStrm
<<
"
\n
shaderDesc.vertexColors: "
<<
vertexColors
;
resStrm
<<
"
\n
shaderDesc.textured(): "
<<
textured
();
for
(
std
::
map
<
size_t
,
TextureType
>::
const_iterator
iter
=
textureTypes_
.
begin
();
iter
!=
textureTypes_
.
end
();
++
iter
)
...
...
libs_required/ACG/GL/ShaderGenerator.hh
View file @
2887d21a
...
...
@@ -93,6 +93,7 @@ public:
ShaderGenDesc
()
:
version
(
150
),
numLights
(
0
),
twoSidedLighting
(
false
),
shadeMode
(
SG_SHADE_UNLIT
),
vertexColors
(
false
),
vertexTemplateFile
(
""
),
...
...
@@ -131,6 +132,7 @@ public:
// version = _rhs.version;
//
// numLights = _rhs.numLights;
// twoSidedLighting = _rhs.twoSidedLighting;
//
// std::copy(_rhs.lightTypes,_rhs.lightTypes+SG_MAX_SHADER_LIGHTS,lightTypes);
// textureTypes_ = _rhs.textureTypes_;
...
...
@@ -157,6 +159,8 @@ public:
int
numLights
;
ShaderGenLightType
lightTypes
[
SG_MAX_SHADER_LIGHTS
];
bool
twoSidedLighting
;
ShaderGenShadeMode
shadeMode
;
bool
vertexColors
;
...
...
@@ -280,6 +284,9 @@ public:
if
(
numLights
!=
_rhs
.
numLights
)
return
false
;
if
(
twoSidedLighting
!=
_rhs
.
twoSidedLighting
)
return
false
;
if
(
shadeMode
!=
_rhs
.
shadeMode
)
return
false
;
...
...
libs_required/ACG/Scenegraph/MeshNode2T.cc
View file @
2887d21a
...
...
@@ -754,6 +754,9 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
// enable / disable lighting
ro
.
shaderDesc
.
numLights
=
props
->
lighting
()
?
0
:
-
1
;
// Enable/Disable twoSided Lighting
ro
.
shaderDesc
.
twoSidedLighting
=
_state
.
twosided_lighting
();
// TODO: better handling of attribute sources in shader gen
switch
(
props
->
lightStage
())
{
...
...
widgets/rendererWidget/renderObjectHighLighter.cc
View file @
2887d21a
...
...
@@ -116,7 +116,7 @@ void RenderObjectHighlighter::update() {
HighlightingRule
rule
;
// Define rule
rule
.
pattern
=
QRegExp
(
"
#define
.*"
);
rule
.
pattern
=
QRegExp
(
"
(#define|#ifdef|#else|#endif|#ifndef)
.*"
);
rule
.
format
=
defineFormat_
;
highlightingRules_
.
append
(
rule
);
...
...
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