Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johannes Braun
glare
Commits
26744d31
Commit
26744d31
authored
Aug 05, 2017
by
Johannes Braun
Browse files
Switched Material for PBR-like parameter format.
parent
5f0fe266
Changes
10
Hide whitespace changes
Inline
Side-by-side
assets/shaders/raytracer/basic_structs.glsl
View file @
26744d31
...
...
@@ -19,29 +19,59 @@ const uint MFLAG_HAS_DISPLACEMENT = 1 << 4;
const
uint
MFLAG_HAS_TRANSPARENT
=
1
<<
5
;
const
uint
MFLAG_HAS_EMISSIVE
=
1
<<
6
;
struct
ParameterColor
{
vec3
value
;
uint
texture_available
;
sampler2D
texture
;
uint
p
[
2
];
};
struct
ParameterFloat
{
float
value
;
uint
texture_available
;
sampler2D
texture
;
};
struct
Material
{
vec4
color_diffuse
;
vec4
color_ambient
;
vec4
color_emissive
;
vec4
color_specular
;
vec4
color_transparent
;
sampler2D
map_diffuse
;
sampler2D
map_ambient
;
sampler2D
map_specular
;
sampler2D
map_transparent
;
sampler2D
map_emissive
;
sampler2D
map_normal
;
sampler2D
map_displacement
;
float
specular_exponent
;
float
ior
;
ParameterColor
emission
;
ParameterColor
ambient
;
ParameterColor
base
;
uint
flags
;
ParameterFloat
roughness
;
ParameterFloat
metallic
;
ParameterFloat
transmissive
;
float
misc
[
3
];
};
float
ior
;
uint
p
[
3
];
};
// struct Material
// {
// vec4 color_diffuse;
// vec4 color_ambient;
// vec4 color_emissive;
// vec4 color_specular;
// vec4 color_transparent;
//
// sampler2D map_diffuse;
// sampler2D map_ambient;
// sampler2D map_specular;
// sampler2D map_transparent;
// sampler2D map_emissive;
// sampler2D map_normal;
// sampler2D map_displacement;
//
// float specular_exponent;
// float ior;
//
// uint flags;
//
// float misc[3];
// };
struct
BufferLight
{
...
...
assets/shaders/raytracer/pathtracer.comp
View file @
26744d31
...
...
@@ -100,7 +100,6 @@ bool shade(int id, inout vec3 radiance, uint bounce, out uint bsdf_id)
//Get Hit data
Material material;
Vertex vertex = hit.getVertex(material);
vec4 diffuse = material.getDiffuse(vertex.texcoord);
b_traces[id].properties.travelled_distance += b_traces[id].hit.valid() ? (distance(b_traces[id].ray.origin, vertex.position.xyz)) : FLT_MAX;
...
...
assets/shaders/raytracer/properties/bsdf.glsl
View file @
26744d31
...
...
@@ -36,15 +36,14 @@ struct BSDFResult
struct
SampledMaterial
{
vec4
diffuse
;
vec4
specular
;
vec4
transparent
;
vec4
emissive
;
vec4
ambient
;
float
roughness
;
// 0..1
float
metallic
;
// 0..1
float
ior
;
// 0..n
vec3
base
;
vec3
ambient
;
vec3
emission
;
float
roughness
;
float
metallic
;
float
transmission
;
float
ior
;
};
vec3
reflectedDirection
(
vec3
local_hemi_sample
,
vec3
normal
,
vec3
reflected
,
float
roughness
)
...
...
@@ -55,15 +54,15 @@ vec3 reflectedDirection(vec3 local_hemi_sample, vec3 normal, vec3 reflected, flo
SampledMaterial
getMaterialParameters
(
const
in
Material
material
,
const
in
Vertex
vertex
)
{
SampledMaterial
sampled_material
;
sampled_material
.
diffuse
=
material
.
getDiffuse
(
vertex
.
texcoord
);
sampled_material
.
specular
=
material
.
getSpecular
(
vertex
.
texcoord
);
sampled_material
.
transparent
=
material
.
getTransparent
(
vertex
.
texcoord
);
sampled_material
.
emissive
=
material
.
getEmissive
(
vertex
.
texcoord
);
sampled_material
.
base
=
material
.
getBase
(
vertex
.
texcoord
);
sampled_material
.
ambient
=
material
.
getAmbient
(
vertex
.
texcoord
);
sampled_material
.
emission
=
material
.
getEmission
(
vertex
.
texcoord
);
sampled_material
.
roughness
=
material
.
getRoughness
();
sampled_material
.
metallic
=
clamp
((
sampled_material
.
specular
.
r
+
sampled_material
.
specular
.
g
+
sampled_material
.
specular
.
b
)
/
3
,
0
,
1
);
sampled_material
.
ior
=
1
.
56
f
;
//material.ior;
sampled_material
.
roughness
=
material
.
getRoughness
(
vertex
.
texcoord
);
sampled_material
.
metallic
=
material
.
getMetallic
(
vertex
.
texcoord
);
sampled_material
.
transmission
=
material
.
getTransmission
(
vertex
.
texcoord
);
sampled_material
.
ior
=
material
.
ior
;
return
sampled_material
;
}
...
...
@@ -75,9 +74,9 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
//Use the pixel coordinates of the incoming ray.
result
.
generated_ray
=
ray_in
;
if
(
sampled_material
.
emissi
ve
.
rgb
!=
vec3
(
0
))
if
(
sampled_material
.
emissi
on
.
rgb
!=
vec3
(
0
))
{
result
.
radiance
=
sampled_material
.
emissi
ve
.
rgb
;
result
.
radiance
=
sampled_material
.
emissi
on
.
rgb
;
result
.
bsdf_id
=
eEmit
;
return
result
;
}
...
...
@@ -106,7 +105,7 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
float
k_s
=
fresnel
;
float
k_rest
=
1
-
k_s
;
float
k_t
=
k_rest
*
((
sampled_material
.
trans
parent
.
r
+
sampled_material
.
transparent
.
g
+
sampled_material
.
transparent
.
b
)
/
3
)
;
float
k_t
=
k_rest
*
sampled_material
.
trans
mission
;
float
k_d
=
1
-
k_s
-
k_t
;
float
roulette_border_specular
=
k_s
;
...
...
@@ -116,10 +115,10 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
if
(
roulette_border_transmit
<=
random
.
x
)
{
// Sample lambertian diffuse
result
.
evaluation
=
(
1
-
sampled_material
.
metallic
)
*
sampled_material
.
diffuse
.
rgb
*
ONE_OVER_PI
;
result
.
evaluation
=
(
1
-
sampled_material
.
metallic
)
*
sampled_material
.
base
*
ONE_OVER_PI
;
result
.
generated_ray
.
direction
=
normalize
(
toWorld
(
randCosineHemisphere
(
random
.
x
,
random
.
y
),
incoming
,
normal
));
result
.
probability_density
=
abs
(
dot
(
vec4
(
result
.
generated_ray
.
direction
,
0
),
vertex
.
normal
))
*
ONE_OVER_PI
;
result
.
radiance
=
(
1
-
sampled_material
.
metallic
)
*
sampled_material
.
diffuse
.
rgb
*
ONE_OVER_PI
;
result
.
radiance
=
(
1
-
sampled_material
.
metallic
)
*
sampled_material
.
base
*
ONE_OVER_PI
;
result
.
bsdf_id
=
eDiffuse
;
// offset by newly generated direction
result
.
generated_ray
.
origin
=
vertex
.
position
.
xyz
+
1e-5
f
*
result
.
generated_ray
.
direction
;
...
...
@@ -137,7 +136,7 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
float
geometry_refracted
=
ggxGeometry
(
incoming
,
outgoing_refracted
,
normal
,
micro_normal
,
sampled_material
.
roughness
);
// Reflections of metallic materials are tinted with the material base color.
vec3
fresnel_tint
=
fresnelTint
(
fresnel
,
sampled_material
.
metallic
,
sampled_material
.
diffuse
.
rgb
);
vec3
fresnel_tint
=
fresnelTint
(
fresnel
,
sampled_material
.
metallic
,
sampled_material
.
base
);
float
n_dot_in
=
clamp
(
dot
(
normal
,
incoming
),
0
,
1
);
float
n_dot_out
=
clamp
(
dot
(
normal
,
outgoing_reflected
),
0
,
1
);
...
...
@@ -171,9 +170,9 @@ BSDFResult computeBSDF(const in Material material, const in vec2 random, const i
float
btdf_denominator
=
jacobian_refract_denominator
;
// Finally, build the brdf. As we do russian roulette, we can just tint the brdf instead of multiplying with the fresnel value.
vec3
brdf
=
mix
(
vec3
(
1
),
sampled_material
.
diffuse
.
rgb
,
sampled_material
.
metallic
)
*
geometry
*
hemisphere_sample
.
distribution
/
brdf_denominator
;
vec3
brdf
=
mix
(
vec3
(
1
),
sampled_material
.
base
,
sampled_material
.
metallic
)
*
geometry
*
hemisphere_sample
.
distribution
/
brdf_denominator
;
// Same as above, we don't need the fresnel factor here either.
vec3
btdf
=
(
m_dot_in
*
m_dot_out_refract
/
(
n_dot_in
*
n_dot_out_refract
))
*
ior_out_2
*
sampled_material
.
diffuse
.
rgb
*
geometry_refracted
*
hemisphere_sample
.
distribution
/
btdf_denominator
;
vec3
btdf
=
(
m_dot_in
*
m_dot_out_refract
/
(
n_dot_in
*
n_dot_out_refract
))
*
ior_out_2
*
sampled_material
.
base
*
geometry_refracted
*
hemisphere_sample
.
distribution
/
btdf_denominator
;
// russian roulette Part 2
// Also check whether the refracted ray is valid, as we don't want to sample with NaN rays.
...
...
assets/shaders/raytracer/utilities_internal/materials.glsl
View file @
26744d31
...
...
@@ -7,34 +7,73 @@
#define mapOrColor(material, color, map, flag, texcoord) (material.color * (((material.flags & flag) == flag) ? texture(material.map, texcoord) : vec4(1)))
vec4
getDiffuse
(
const
in
Material
material
,
const
in
vec
2
texco
or
d
)
float
texCompMax
(
const
in
vec
3
vect
or
)
{
return
ma
terial
.
mapOrColor
(
color_diffuse
,
map_diffuse
,
MFLAG_HAS_DIFFUSE
,
texcoord
);
return
ma
x
(
vector
.
x
,
max
(
vector
.
y
,
vector
.
z
)
);
}
vec4
getSpecular
(
const
in
Material
material
,
const
in
vec2
texcoord
)
#define getParam3f(parameter, texcoord) (bool(parameter.texture_available) ? texture(parameter.texture, texcoord).rgb : parameter.value)
#define getParam1f(parameter, texcoord) (bool(parameter.texture_available) ? texCompMax(texture(parameter.texture, texcoord).rgb) : parameter.value)
vec3
getBase
(
const
in
Material
material
,
const
in
vec2
texcoord
)
{
return
material
.
mapOrColor
(
color_specular
,
map_specular
,
MFLAG_HAS_SPECULAR
,
texcoord
);
return
getParam3f
(
material
.
base
,
texcoord
);
}
vec
4
get
Ambient
(
const
in
Material
material
,
const
in
vec2
texcoord
)
vec
3
get
Emission
(
const
in
Material
material
,
const
in
vec2
texcoord
)
{
return
material
.
mapOrColor
(
color_ambient
,
map_ambient
,
MFLAG_HAS_AMBIENT
,
texcoord
);
return
getParam3f
(
material
.
emission
,
texcoord
);
}
vec
4
get
Transpar
ent
(
const
in
Material
material
,
const
in
vec2
texcoord
)
vec
3
get
Ambi
ent
(
const
in
Material
material
,
const
in
vec2
texcoord
)
{
return
material
.
mapOrColor
(
color_transparent
,
map_transparent
,
MFLAG_HAS_TRANSPARENT
,
texcoord
);
return
getParam3f
(
material
.
ambient
,
texcoord
);
}
vec4
getEmissive
(
const
in
Material
material
,
const
in
vec2
texcoord
)
float
getRoughness
(
const
in
Material
material
,
const
in
vec2
texcoord
)
{
return
ma
terial
.
mapOrColor
(
color_emissive
,
map_emissive
,
MFLAG_HAS_EMISSIVE
,
texcoord
);
return
ma
x
(
getParam1f
(
material
.
roughness
,
texcoord
)
,
0
.
001
f
)
;
}
float
get
Roughness
(
const
in
Material
material
)
float
get
Metallic
(
const
in
Material
material
,
const
in
vec2
texcoord
)
{
return
pow
(
1
.
f
-
((
material
.
specular_exponent
.
clamp
(
1
,
101
)
-
1
)
/
100
.
f
),
2
);
return
getParam1f
(
material
.
metallic
,
texcoord
);
}
float
getTransmission
(
const
in
Material
material
,
const
in
vec2
texcoord
)
{
return
getParam1f
(
material
.
transmissive
,
texcoord
);
}
//
// vec3 getDiffuse(const in Material material, const in vec2 texcoord)
// {
// return material.mapOrColor(color_diffuse, map_diffuse, MFLAG_HAS_DIFFUSE, texcoord);
// }
//
// vec4 getSpecular(const in Material material, const in vec2 texcoord)
// {
// return material.mapOrColor(color_specular, map_specular, MFLAG_HAS_SPECULAR, texcoord);
// }
//
// vec4 getAmbient(const in Material material, const in vec2 texcoord)
// {
// return material.mapOrColor(color_ambient, map_ambient, MFLAG_HAS_AMBIENT, texcoord);
// }
//
// vec4 getTransparent(const in Material material, const in vec2 texcoord)
// {
// return material.mapOrColor(color_transparent, map_transparent, MFLAG_HAS_TRANSPARENT, texcoord);
// }
//
// vec4 getEmissive(const in Material material, const in vec2 texcoord)
// {
// return material.mapOrColor(color_emissive, map_emissive, MFLAG_HAS_EMISSIVE, texcoord);
// }
//
// float getRoughness(const in Material material)
// {
// return pow(1.f - ((material.specular_exponent.clamp(1, 101)-1)/100.f), 2);
// }
#endif //__GL_UTILS_MATERIALS
src/libraries/core/objects/material.cpp
View file @
26744d31
...
...
@@ -30,64 +30,64 @@ namespace glare
void
Material
::
gui
()
{
//ImGui::Begin("Materials");
ImGui
::
PushID
(
m_name
.
c_str
());
const
static
auto
colorOption
=
[](
const
std
::
string
&
name
,
MaterialParameter3f
&
param
)
{
ImGui
::
ColorButton
(
*
reinterpret_cast
<
ImVec4
*>
(
&
glm
::
vec4
(
param
.
value
,
1
)));
ImGui
::
SameLine
();
return
ImGui
::
DragFloat3
(
name
.
c_str
(),
reinterpret_cast
<
float
*>
(
&
param
.
value
),
0.01
f
,
0.
f
,
1.
f
);
};
const
static
auto
floatOption
=
[](
const
std
::
string
&
name
,
MaterialParameter1f
&
param
)
{
return
ImGui
::
DragFloat
(
name
.
c_str
(),
&
param
.
value
,
0.001
f
,
0.
f
,
1.
f
);
};
bool
changed
=
false
;
ImGui
::
ColorButton
(
*
reinterpret_cast
<
ImVec4
*>
(
&
glm
::
vec4
(
color_diffuse
,
1
)));
ImGui
::
SameLine
();
changed
|=
ImGui
::
DragFloat3
(
"Diffuse Color"
,
reinterpret_cast
<
float
*>
(
&
color_diffuse
),
0.01
f
,
0
,
10000
);
ImGui
::
ColorButton
(
*
reinterpret_cast
<
ImVec4
*>
(
&
glm
::
vec4
(
color_specular
,
1
)));
ImGui
::
SameLine
();
changed
|=
ImGui
::
DragFloat3
(
"Specular Color"
,
reinterpret_cast
<
float
*>
(
&
color_specular
),
0.01
f
,
0
,
10000
);
ImGui
::
ColorButton
(
*
reinterpret_cast
<
ImVec4
*>
(
&
glm
::
vec4
(
color_transparent
,
1
)));
ImGui
::
SameLine
();
changed
|=
ImGui
::
DragFloat3
(
"Transparent Color"
,
reinterpret_cast
<
float
*>
(
&
color_transparent
),
0.01
f
,
0
,
10000
);
ImGui
::
ColorButton
(
*
reinterpret_cast
<
ImVec4
*>
(
&
glm
::
vec4
(
color_ambient
,
1
)));
ImGui
::
SameLine
();
changed
|=
ImGui
::
DragFloat3
(
"Ambient Color"
,
reinterpret_cast
<
float
*>
(
&
color_ambient
),
0.01
f
,
0
,
10000
);
ImGui
::
ColorButton
(
*
reinterpret_cast
<
ImVec4
*>
(
&
glm
::
vec4
(
color_emissive
,
1
)));
ImGui
::
SameLine
();
changed
|=
ImGui
::
DragFloat3
(
"Emissive Color"
,
reinterpret_cast
<
float
*>
(
&
color_emissive
),
0.01
f
,
0
,
10000
);
if
(
ImGui
::
DragFloat
(
"Specular Exponent"
,
&
specular_exponent
,
1.
f
,
1
,
100
)
||
changed
)
changed
|=
colorOption
(
"Base Color"
,
base
);
changed
|=
colorOption
(
"Ambient Color"
,
ambient
);
changed
|=
colorOption
(
"Emission Color"
,
emission
);
ImGui
::
Spacing
();
changed
|=
floatOption
(
"Roughness"
,
roughness
);
changed
|=
floatOption
(
"Metallic"
,
metallic
);
changed
|=
floatOption
(
"Transmissive"
,
transmissive
);
ImGui
::
Spacing
();
changed
|=
ImGui
::
DragFloat
(
"IOR"
,
&
index_of_refraction
,
0.001
f
,
0.1
f
,
10.
f
);
if
(
changed
)
messaging
::
Handler
::
getInstance
().
submit
(
tags
::
material
,
1
);
ImGui
::
PopID
();
//ImGui::End();
}
void
Material
::
activate
()
const
{
//TODO: make PBR, remove legacy stuff.
m_shader
->
use
();
if
(
map_diffuse
)
m_shader
->
uniform
(
"u_material.map_diffuse"
,
map_diffuse
->
makeTextureResident
());
if
(
map_specular
)
m_shader
->
uniform
(
"u_material.map_specular"
,
map_specular
->
makeTextureResident
());
if
(
map_transparent
)
m_shader
->
uniform
(
"u_material.map_transparent"
,
map_transparent
->
makeTextureResident
());
if
(
map_ambient
)
m_shader
->
uniform
(
"u_material.map_ambient"
,
map_ambient
->
makeTextureResident
());
if
(
base
.
texture
)
m_shader
->
uniform
(
"u_material.map_diffuse"
,
base
.
texture
->
makeTextureResident
());
if
(
ambient
.
texture
)
m_shader
->
uniform
(
"u_material.map_ambient"
,
ambient
.
texture
->
makeTextureResident
());
if
(
emission
.
texture
)
m_shader
->
uniform
(
"u_material.has_emissive"
,
emission
.
texture
->
makeTextureResident
());
if
(
map_normal
)
m_shader
->
uniform
(
"u_material.map_normal"
,
map_normal
->
makeTextureResident
());
if
(
map_displacement
)
m_shader
->
uniform
(
"u_material.map_displacement"
,
map_displacement
->
makeTextureResident
());
if
(
map_emissive
)
m_shader
->
uniform
(
"u_material.has_emissive"
,
map_emissive
->
makeTextureResident
());
m_shader
->
uniform
(
"u_material.specular_exponent"
,
specular_exponent
);
m_shader
->
uniform
(
"u_material.ior"
,
i
or
);
m_shader
->
uniform
(
"u_material.specular_exponent"
,
(
1
-
roughness
.
value
)
*
99
+
1
);
// legacy
m_shader
->
uniform
(
"u_material.ior"
,
i
ndex_of_refraction
);
m_shader
->
uniform
(
"u_material.color_diffuse"
,
color_diffus
e
);
m_shader
->
uniform
(
"u_material.color_ambient"
,
color_
ambient
);
m_shader
->
uniform
(
"u_material.color_specular"
,
color_specular
);
m_shader
->
uniform
(
"u_material.color_transparent"
,
color_transparent
);
m_shader
->
uniform
(
"u_material.color_emissive"
,
color_emissiv
e
);
m_shader
->
uniform
(
"u_material.color_diffuse"
,
base
.
valu
e
);
m_shader
->
uniform
(
"u_material.color_ambient"
,
ambient
.
value
);
m_shader
->
uniform
(
"u_material.color_specular"
,
glm
::
vec3
(
1
,
1
,
1
)
);
m_shader
->
uniform
(
"u_material.color_transparent"
,
glm
::
vec3
(
0
,
0
,
0
)
);
m_shader
->
uniform
(
"u_material.color_emissive"
,
emission
.
valu
e
);
m_shader
->
uniform
(
"u_material.has_diffuse"
,
bool
(
map_diffus
e
));
m_shader
->
uniform
(
"u_material.has_ambient"
,
bool
(
map_
ambient
));
m_shader
->
uniform
(
"u_material.has_specular"
,
bool
(
map_specular
)
);
m_shader
->
uniform
(
"u_material.has_transparent"
,
bool
(
map_transparent
)
);
m_shader
->
uniform
(
"u_material.has_diffuse"
,
bool
(
base
.
textur
e
));
m_shader
->
uniform
(
"u_material.has_ambient"
,
bool
(
ambient
.
texture
));
m_shader
->
uniform
(
"u_material.has_specular"
,
false
);
m_shader
->
uniform
(
"u_material.has_transparent"
,
false
);
m_shader
->
uniform
(
"u_material.has_normal"
,
bool
(
map_normal
));
m_shader
->
uniform
(
"u_material.has_displacement"
,
bool
(
map_displacement
));
m_shader
->
uniform
(
"u_material.has_emissive"
,
bool
(
map_
emissi
v
e
));
m_shader
->
uniform
(
"u_material.has_emissive"
,
bool
(
emissi
on
.
textur
e
));
m_shader
->
uniform
(
"u_camera_position"
,
glm
::
vec3
(
state
::
camera
->
getOwner
()
->
absoluteTransform
()
*
glm
::
vec4
(
0
,
0
,
0
,
1
)));
}
...
...
src/libraries/core/objects/material.h
View file @
26744d31
...
...
@@ -15,6 +15,18 @@ namespace glare
{
namespace
core
{
struct
MaterialParameter1f
{
float
value
;
std
::
shared_ptr
<
TextureRGBA_UB
>
texture
;
};
struct
MaterialParameter3f
{
glm
::
vec3
value
;
std
::
shared_ptr
<
TextureRGBA_UB
>
texture
;
};
class
Material
{
public:
...
...
@@ -30,23 +42,18 @@ namespace glare
std
::
shared_ptr
<
Program
>
getShader
()
const
;
float
specular_exponent
=
100
;
MaterialParameter3f
emission
=
{
glm
::
vec3
(
0
)
};
MaterialParameter3f
ambient
=
{
glm
::
vec3
(
0
)
};
MaterialParameter3f
base
=
{
glm
::
vec3
(
1
)
};
glm
::
vec3
color_diffuse
=
glm
::
vec3
(
0
);
glm
::
vec3
color_ambient
=
glm
::
vec3
(
0
);
glm
::
vec3
color_specular
=
glm
::
vec3
(
0
);
glm
::
vec3
color_transparent
=
glm
::
vec3
(
0
);
glm
::
vec3
color_emissive
=
glm
::
vec3
(
0
);
MaterialParameter1f
roughness
=
{
0
};
MaterialParameter1f
metallic
=
{
0
};
MaterialParameter1f
transmissive
=
{
0
};
std
::
shared_ptr
<
TextureRGBA_UB
>
map_ambient
;
std
::
shared_ptr
<
TextureRGBA_UB
>
map_diffuse
;
std
::
shared_ptr
<
TextureRGBA_UB
>
map_specular
;
std
::
shared_ptr
<
TextureRGBA_UB
>
map_transparent
;
std
::
shared_ptr
<
TextureRGBA_UB
>
map_emissive
;
float
index_of_refraction
=
1.45
f
;
std
::
shared_ptr
<
TextureRGBA_UB
>
map_normal
;
std
::
shared_ptr
<
TextureRGBA_UB
>
map_displacement
;
float
ior
;
private:
static
std
::
atomic
<
size_t
>
m_current_id
;
const
size_t
m_material_id
;
...
...
src/libraries/core/res/collada.cpp
View file @
26744d31
...
...
@@ -216,7 +216,7 @@ namespace glare
{
auto
mesh_spt
=
mesh_mat
.
mesh
;
std
::
shared_ptr
<
core
::
GraphNode
>
mesh_node
=
std
::
make_shared
<
core
::
GraphNode
>
(
sub
.
attribute
(
"url"
).
as_string
());
mesh_node
->
addComponent
(
std
::
make_shared
<
core
::
MeshRenderer
>
(
mesh_spt
,
data
->
materials
[
"
qeng
_coll_default_material"
]));
mesh_node
->
addComponent
(
std
::
make_shared
<
core
::
MeshRenderer
>
(
mesh_spt
,
data
->
materials
[
"
_
_coll
ada
_default_material
__
"
]));
root
->
attach
(
mesh_node
);
}
continue
;
...
...
@@ -441,7 +441,7 @@ namespace glare
if
(
material_name
==
""
)
{
material_name
=
"
qeng
_coll_default_material"
;
material_name
=
"
_
_coll
ada
_default_material
__
"
;
}
const
auto
&
positions
=
sources
[
vertices_id
];
...
...
@@ -544,11 +544,7 @@ namespace glare
void
Collada
::
decodeMaterialsNode
(
const
pugi
::
xml_node
&
mat_node
)
const
{
//Add a default material.
auto
default_material
=
std
::
make_shared
<
core
::
Material
>
(
"qeng_coll_default_material"
);
default_material
->
color_diffuse
=
color
::
preset
::
white
.
rgb
;
default_material
->
ior
=
1.0
;
default_material
->
specular_exponent
=
1
;
data
->
materials
.
emplace
(
"qeng_coll_default_material"
,
default_material
);
data
->
materials
.
emplace
(
"__collada_default_material__"
,
std
::
make_shared
<
core
::
Material
>
(
"__collada_default_material__"
));
for
(
const
auto
&
mat_sub
:
mat_node
.
children
())
{
...
...
@@ -561,22 +557,25 @@ namespace glare
auto
material
=
std
::
make_shared
<
core
::
Material
>
(
mat_name
);
material
->
color_diffuse
=
glm
::
vec3
(
effect
->
diffuse
);
material
->
color_ambient
=
glm
::
vec3
(
effect
->
ambient
);
material
->
color_specular
=
glm
::
vec3
(
effect
->
specular
);
material
->
color_transparent
=
glm
::
vec3
(
effect
->
transparent
);
material
->
color_emissive
=
glm
::
vec3
(
effect
->
emission
);
material
->
base
.
value
=
glm
::
vec3
(
effect
->
diffuse
);
material
->
ambient
.
value
=
glm
::
vec3
(
effect
->
ambient
);
material
->
emission
.
value
=
glm
::
vec3
(
effect
->
emission
);
material
->
specular_exponent
=
effect
->
shininess
;
material
->
ior
=
effect
->
ior
;
material
->
metallic
.
value
=
glm
::
max
(
glm
::
compMax
(
glm
::
vec3
(
effect
->
reflective
)),
effect
->
reflectivity
);
material
->
roughness
.
value
=
1
-
glm
::
compMax
(
glm
::
vec3
(
effect
->
specular
));
material
->
transmissive
.
value
=
glm
::
compMax
(
glm
::
vec3
(
effect
->
transparent
));
material
->
index_of_refraction
=
effect
->
ior
;
material
->
map_ambient
=
data
->
images
[
effect
->
ambient_sampler_id
];
material
->
map_diffuse
=
data
->
images
[
effect
->
diffuse_sampler_id
];
material
->
map_specular
=
data
->
images
[
effect
->
specular_sampler_id
];
material
->
map_transparent
=
data
->
images
[
effect
->
transparent_sampler_id
];
material
->
map_emissive
=
data
->
images
[
effect
->
emission_sampler_id
];
material
->
map_normal
=
data
->
images
[
effect
->
normal_sampler_id
];
material
->
map_displacement
=
data
->
images
[
effect
->
displacement_sampler_id
];
material
->
base
.
texture
=
data
->
images
[
effect
->
diffuse_sampler_id
];
material
->
ambient
.
texture
=
data
->
images
[
effect
->
ambient_sampler_id
];
material
->
emission
.
texture
=
data
->
images
[
effect
->
emission_sampler_id
];
material
->
metallic
.
texture
=
data
->
images
[
effect
->
reflective_sampler_id
];
material
->
roughness
.
texture
=
data
->
images
[
effect
->
specular_sampler_id
];
material
->
transmissive
.
texture
=
data
->
images
[
effect
->
transparent_sampler_id
];
data
->
materials
.
emplace
(
mat_id
,
material
);
}
...
...
@@ -676,6 +675,19 @@ namespace glare
mat_effect
->
transparent
=
glm
::
vec4
(
1
-
float
(
atof
(
col_node
.
child_value
())));
}
}
else
if
(
tag
==
"reflective"
)
{
if
(
const
auto
col_node
=
phong_sub_node
.
child
(
"color"
))
{
//We have a color here.
mat_effect
->
reflective
=
color
::
arrayString
<
color
::
rgba32f
>
(
col_node
.
child_value
());
}
else
{
//We have a texture here.
mat_effect
->
reflective_sampler_id
=
decodeTextureSampler
(
effect_profile_COMMON
,
phong_sub_node
.
child
(
"texture"
).
attribute
(
"texture"
).
as_string
());
}
}
else
if
(
tag
==
"shininess"
)
{
mat_effect
->
shininess
=
float
(
atof
(
phong_sub_node
.
child
(
"float"
).
child_value
()));
...
...
src/libraries/core/res/collada.h
View file @
26744d31
...
...
@@ -23,7 +23,7 @@ namespace glare
color
::
rgba32f
ambient
=
color
::
preset
::
white
;
color
::
rgba32f
diffuse
=
color
::
preset
::
white
;
color
::
rgba32f
specular
=
color
::
preset
::
white
;
color
::
rgba32f
reflective
=
color
::
preset
::
white
;
color
::
rgba32f
reflective
=
color
::
preset
::
black
;
color
::
rgba32f
transparent
=
color
::
preset
::
black
;
float
reflectivity
=
0
;
float
shininess
=
0
;
...
...
@@ -34,6 +34,7 @@ namespace glare
std
::
string
specular_sampler_id
;
std
::
string
ambient_sampler_id
;
std
::
string
emission_sampler_id
;
std
::
string
reflective_sampler_id
;
std
::
string
normal_sampler_id
;
std
::
string
displacement_sampler_id
;
};
...
...
src/libraries/raytrace/structs.cpp
View file @
26744d31
...
...
@@ -17,59 +17,25 @@ namespace glare
Material
convert
::
material
(
const
core
::
Material
&
material
)
{
Material
mat
;
mat
.
specular_exponent
=
material
.
specular_exponent
;
mat
.
color_diffuse
=
glm
::
vec4
(
glm
::
vec3
(
material
.
color_diffuse
),
1
);
mat
.
color_ambient
=
glm
::
vec4
(
glm
::
vec3
(
material
.
color_ambient
),
1
);
mat
.
color_specular
=
glm
::
vec4
(
glm
::
vec3
(
material
.
color_specular
),
1
);
mat
.
color_transparent
=
glm
::
vec4
(
glm
::
vec3
(
material
.
color_transparent
),
1
);
mat
.
color_emissive
=
glm
::
vec4
(
glm
::
vec3
(
material
.
color_emissive
),
1
);
mat
.
ior
=
material
.
ior
;
mat
.
flags
=
uint32_t
(
MapFlag
::
eNone
);
mat
.
map_diffuse
=
0
;
if
(
material
.
map_diffuse
)
{
mat
.
flags
|=
uint32_t
(
MapFlag
::
eDiffuse
);
mat
.
map_diffuse
=
material
.
map_diffuse
->
makeTextureResident
();
}
mat
.
map_ambient
=
0
;
if
(
material
.
map_ambient
)
{
mat
.
flags
|=
uint32_t
(
MapFlag
::
eAmbient
);
mat
.
map_ambient
=
material
.
map_ambient
->
makeTextureResident
();
}
mat
.
map_displacement
=
0
;
if
(
material
.
map_displacement
)
{
mat
.
flags
|=
uint32_t
(
MapFlag
::
eDisplacement
);
mat
.
map_displacement
=
material
.
map_displacement
->
makeTextureResident
();
}
mat
.
map_normal
=
0
;
if
(
material
.
map_normal
)
{
mat
.
flags
|=
uint32_t
(
MapFlag
::
eNormal
);
mat
.
map_normal
=
material
.
map_normal
->
makeTextureResident
();
}
mat
.
map_specular
=
0
;
if
(
material
.
map_specular
)
{
mat
.
flags
|=
uint32_t
(
MapFlag
::
eSpecular
);
mat
.
map_specular
=
material
.
map_specular
->
makeTextureResident
();
}
mat
.
map_transparent
=
0
;
if
(
material
.
map_transparent
)
{