Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vairdraw-src
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pirvi-public
vairdraw
vairdraw-src
Commits
41928ffa
Commit
41928ffa
authored
6 months ago
by
sdegrande
Browse files
Options
Downloads
Patches
Plain Diff
Add the ability to create a Material with a shader program config.
parent
27d36a45
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Renderer/Program.cpp
+1
-1
1 addition, 1 deletion
src/Renderer/Program.cpp
src/SceneGraph/3DObjects/Material.cpp
+21
-15
21 additions, 15 deletions
src/SceneGraph/3DObjects/Material.cpp
src/SceneGraph/3DObjects/Material.hpp
+8
-8
8 additions, 8 deletions
src/SceneGraph/3DObjects/Material.hpp
with
30 additions
and
24 deletions
src/Renderer/Program.cpp
+
1
−
1
View file @
41928ffa
...
...
@@ -88,7 +88,7 @@ bool Program::preprocessShader(std::string& shaderSource, const Json::Value& sha
for
(
const
auto
&
name
:
shaderConf
[
"defines"
].
getMemberNames
())
{
defineContent
.
append
(
fmt
::
format
(
"#define {} {}
\n
"
,
name
,
shaderConf
[
"defines"
].
get
(
name
,
""
).
asString
()));
}
std
::
regex
pattern
(
"
^
// @define placeholder@
$
"
);
std
::
regex
pattern
(
"// @define placeholder@"
);
try
{
shaderSource
=
(
std
::
string
)
std
::
regex_replace
(
shaderSource
,
pattern
,
defineContent
);
}
catch
(
const
std
::
regex_error
&
e
)
{
...
...
This diff is collapsed.
Click to expand it.
src/SceneGraph/3DObjects/Material.cpp
+
21
−
15
View file @
41928ffa
...
...
@@ -13,14 +13,13 @@
#include
"Material.hpp"
#include
<filesystem>
#include
<glm/glm.hpp>
#include
"Renderer/Vertex.hpp"
#include
"Utils/logstream.hpp"
// TODO: should we use a MaterialFactory, so that we even do not
// duplicated Material instances (currently, only the shader program
// is not duplicated) ?
Material
::
Material
(
const
std
::
string
&
mn
)
:
materialName
(
mn
)
{}
Material
::
Material
(
const
std
::
string
&
mn
)
:
material
Unique
Name
(
mn
)
{}
Material
::~
Material
()
{
...
...
@@ -30,9 +29,10 @@ Material::~Material()
//=====================================================================
ColoredMaterial
::
ColoredMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
)
:
Material
(
name
)
ColoredMaterial
::
ColoredMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
)
:
Material
(
name
)
{
setShaderProgram
(
"ColoredMaterial"
);
setShaderProgram
(
"ColoredMaterial"
,
programConf
);
ColoredMaterialProgram
::
ProgramData
*
pd
=
static_cast
<
ColoredMaterialProgram
::
ProgramData
*>
(
shaderProgramData
);
pd
->
ambient
=
glm
::
vec3
{
matImporter
->
ambientColor
.
r
/
255.0f
,
matImporter
->
ambientColor
.
g
/
255.0f
,
...
...
@@ -46,9 +46,11 @@ ColoredMaterial::ColoredMaterial(const std::string& name, MaterialImporter* matI
pd
->
opacity
=
matImporter
->
opacity
;
}
TexturedMaterial
::
TexturedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
)
:
Material
(
name
)
TexturedMaterial
::
TexturedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
)
:
Material
(
name
)
{
setShaderProgram
(
"TexturedMaterial"
);
setShaderProgram
(
"TexturedMaterial"
,
programConf
);
diffuseM
=
matImporter
->
textureMaps
[
MaterialImporter
::
MAT_DIFFUSE_TEX
].
tex
;
...
...
@@ -66,9 +68,10 @@ TexturedMaterial::TexturedMaterial(const std::string& name, MaterialImporter* ma
pd
->
opacity
=
matImporter
->
opacity
;
}
MappedMaterial
::
MappedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
)
:
Material
(
name
)
MappedMaterial
::
MappedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
)
:
Material
(
name
)
{
setShaderProgram
(
"MappedMaterial"
);
setShaderProgram
(
"MappedMaterial"
,
programConf
);
// Note: replace missing maps with the diffuse map (always defined if MappedMaterial is used)
ambientM
=
matImporter
->
textureMaps
[
MaterialImporter
::
MAT_AMBIENT_TEX
].
tex
;
...
...
@@ -85,9 +88,10 @@ MappedMaterial::MappedMaterial(const std::string& name, MaterialImporter* matImp
pd
->
opacity
=
matImporter
->
opacity
;
}
FullMaterial
::
FullMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
)
:
Material
(
name
)
FullMaterial
::
FullMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
)
:
Material
(
name
)
{
setShaderProgram
(
"FullMaterial"
);
setShaderProgram
(
"FullMaterial"
,
programConf
);
ambientM
=
matImporter
->
textureMaps
[
MaterialImporter
::
MAT_AMBIENT_TEX
].
tex
;
diffuseM
=
matImporter
->
textureMaps
[
MaterialImporter
::
MAT_DIFFUSE_TEX
].
tex
;
...
...
@@ -375,26 +379,28 @@ void MaterialImporter::selectMaterial(const std::string& requestedMaterial)
transparencyMode
=
Node
::
transparencyNodeType_t
::
SEMI_TRANSPARENT_NODE
;
}
std
::
shared_ptr
<
Material
>
MaterialImporter
::
getMaterial
(
const
aiScene
*
scene
)
std
::
shared_ptr
<
Material
>
MaterialImporter
::
getMaterial
(
const
aiScene
*
scene
,
const
std
::
string
&
programConf
)
{
if
(
material
)
return
material
;
// Note: If no UV coords are available, fallback to a 'color-material'
if
(
attributedMaterial
==
"ColoredMaterial"
)
{
material
=
std
::
shared_ptr
<
Material
>
(
new
ColoredMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
));
material
=
std
::
shared_ptr
<
Material
>
(
new
ColoredMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
,
programConf
));
return
material
;
}
else
if
(
attributedMaterial
==
"TexturedMaterial"
)
{
resolveTextures
(
scene
);
material
=
std
::
shared_ptr
<
Material
>
(
new
TexturedMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
));
material
=
std
::
shared_ptr
<
Material
>
(
new
TexturedMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
,
programConf
));
return
material
;
}
else
if
(
attributedMaterial
==
"MappedMaterial"
)
{
resolveTextures
(
scene
);
material
=
std
::
shared_ptr
<
Material
>
(
new
MappedMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
));
material
=
std
::
shared_ptr
<
Material
>
(
new
MappedMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
,
programConf
));
return
material
;
}
else
if
(
attributedMaterial
==
"FullMaterial"
)
{
resolveTextures
(
scene
);
material
=
std
::
shared_ptr
<
Material
>
(
new
FullMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
));
material
=
std
::
shared_ptr
<
Material
>
(
new
FullMaterial
(
modelFilePath
+
"#"
+
materialName
,
this
,
programConf
));
return
material
;
}
...
...
This diff is collapsed.
Click to expand it.
src/SceneGraph/3DObjects/Material.hpp
+
8
−
8
View file @
41928ffa
...
...
@@ -31,10 +31,10 @@ public:
explicit
Material
(
const
std
::
string
&
mn
);
virtual
~
Material
();
void
setShaderProgram
(
const
std
::
string
&
sn
)
void
setShaderProgram
(
const
std
::
string
&
sn
,
const
std
::
string
&
programConf
=
{}
)
{
shaderName
=
sn
;
shaderProgram
=
ProgramFactory
::
getInstance
()
->
create
(
shaderName
);
shaderProgram
=
ProgramFactory
::
getInstance
()
->
create
(
shaderName
,
programConf
);
shaderProgramData
=
shaderProgram
->
createProgramData
();
}
...
...
@@ -48,7 +48,7 @@ public:
}
protected
:
std
::
string
materialName
{
"_none_"
};
std
::
string
material
Unique
Name
{
"_none_"
};
std
::
string
shaderName
{
"_none_"
};
std
::
shared_ptr
<
Program
>
shaderProgram
{};
Program
::
ProgramData
*
shaderProgramData
{
nullptr
};
...
...
@@ -65,14 +65,14 @@ protected:
class
ColoredMaterial
:
public
Material
{
public:
ColoredMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
);
ColoredMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
=
{}
);
~
ColoredMaterial
()
override
{}
};
class
TexturedMaterial
:
public
Material
{
public:
TexturedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
);
TexturedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
=
{}
);
~
TexturedMaterial
()
override
{}
private
:
...
...
@@ -84,7 +84,7 @@ private:
class
MappedMaterial
:
public
Material
{
public:
MappedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
);
MappedMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
=
{}
);
~
MappedMaterial
()
override
{}
private
:
...
...
@@ -98,7 +98,7 @@ private:
class
FullMaterial
:
public
Material
{
public:
FullMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
);
FullMaterial
(
const
std
::
string
&
name
,
MaterialImporter
*
matImporter
,
const
std
::
string
&
programConf
=
{}
);
~
FullMaterial
()
override
{}
private
:
...
...
@@ -123,7 +123,7 @@ public:
virtual
~
MaterialImporter
()
{}
void
import
(
Model3DImport
&
modelImporter
,
const
aiMaterial
*
importedMat
,
const
aiScene
*
scene
);
std
::
shared_ptr
<
Material
>
getMaterial
(
const
aiScene
*
scene
);
std
::
shared_ptr
<
Material
>
getMaterial
(
const
aiScene
*
scene
,
const
std
::
string
&
programConf
=
{}
);
public
:
// All the texture maps and shading parameters that we handle
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
sign in
to comment