cgv
Loading...
Searching...
No Matches
textured_surface_material.cxx
1#include "textured_surface_material.h"
2#include <map>
3#include <string>
4
5namespace cgv {
6 namespace media {
7 namespace illum {
8
11 const std::string& _name,
12 BrdfType _brdf_type,
13 color_type _diffuse_reflectance,
14 float _roughness,
15 float _metalness,
16 float _ambient_occlusion,
17 color_type _emission,
18 float _transparency,
19 const std::complex<float>& _propagation_slow_down,
20 float _roughness_anisotropy,
21 float _roughness_orientation,
22 color_type _specular_reflectance,
23 float _bump_scale) : name(_name), surface_material(_brdf_type, _diffuse_reflectance, _roughness, _metalness, _ambient_occlusion, _emission, _transparency, _propagation_slow_down, _roughness_anisotropy, _roughness_orientation, _specular_reflectance), bump_scale(1)
24{
25 diffuse_index = -1;
26 roughness_index = -1;
27 metalness_index = -1;
28 ambient_index = -1;
29 emission_index = -1;
32 normal_index = -1;
33 bump_index = -1;
34 specular_index = -1;
35 sRGBA_textures = false;
36}
37
43
46{
47 sRGBA_textures = false;
48 diffuse_index = -1;
49 roughness_index = -1;
50 metalness_index = -1;
51 ambient_index = -1;
52 emission_index = -1;
55 normal_index = -1;
56 bump_index = -1;
57 specular_index = -1;
58 set_name(obj_mat.get_name());
59 set_brdf_type(BrdfType(BT_LAMBERTIAN + BT_PHONG));
60 obj_material::color_type a = obj_mat.get_ambient(), d = obj_mat.get_diffuse();
61 float la = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
62 float ld = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
63 set_ambient_occlusion(la >= ld ? la : la/ld);
64 set_diffuse_reflectance(obj_mat.get_diffuse());
65 set_specular_reflectance(obj_mat.get_specular());
66 set_emission(obj_mat.get_emission());
67 set_roughness(std::max(0.0f, std::min(1.0f, 1.0f/(obj_mat.get_shininess()+0.992307f) - 0.0077524f)));
68 set_transparency(1.0f - obj_mat.get_opacity());
70 std::map<std::string, int> file_name_map;
71 if (!obj_mat.get_ambient_texture_name().empty()) {
72 if (file_name_map.find(obj_mat.get_ambient_texture_name()) == file_name_map.end())
73 file_name_map[obj_mat.get_ambient_texture_name()] = add_image_file(obj_mat.get_ambient_texture_name());
74 set_ambient_index(file_name_map[obj_mat.get_ambient_texture_name()]);
75 }
76 if (!obj_mat.get_diffuse_texture_name().empty()) {
77 if (file_name_map.find(obj_mat.get_diffuse_texture_name()) == file_name_map.end())
78 file_name_map[obj_mat.get_diffuse_texture_name()] = add_image_file(obj_mat.get_diffuse_texture_name());
79 set_diffuse_index(file_name_map[obj_mat.get_diffuse_texture_name()]);
80 }
81 if (!obj_mat.get_opacity_texture_name().empty()) {
82 if (file_name_map.find(obj_mat.get_opacity_texture_name()) == file_name_map.end())
83 file_name_map[obj_mat.get_opacity_texture_name()] = add_image_file(obj_mat.get_opacity_texture_name());
84 set_transparency_index(file_name_map[obj_mat.get_opacity_texture_name()]);
85 }
86 if (!obj_mat.get_specular_texture_name().empty()) {
87 if (file_name_map.find(obj_mat.get_specular_texture_name()) == file_name_map.end())
88 file_name_map[obj_mat.get_specular_texture_name()] = add_image_file(obj_mat.get_specular_texture_name());
89 set_specular_index(file_name_map[obj_mat.get_specular_texture_name()]);
90 }
91 if (!obj_mat.get_emission_texture_name().empty()) {
92 if (file_name_map.find(obj_mat.get_emission_texture_name()) == file_name_map.end())
93 file_name_map[obj_mat.get_emission_texture_name()] = add_image_file(obj_mat.get_emission_texture_name());
94 set_emission_index(file_name_map[obj_mat.get_emission_texture_name()]);
95 }
96 if (!obj_mat.get_bump_texture_name().empty()) {
97 if (file_name_map.find(obj_mat.get_bump_texture_name()) == file_name_map.end())
98 file_name_map[obj_mat.get_bump_texture_name()] = add_image_file(obj_mat.get_bump_texture_name());
99 set_bump_index(file_name_map[obj_mat.get_bump_texture_name()]);
100 }
101}
102
104int textured_surface_material::add_image_file(const std::string& file_name)
105{
106 int idx = int(image_file_names.size());
107 image_file_names.push_back(file_name);
108 return idx;
109}
110
111
112
113 }
114 }
115}
>extension of a phong material with support for texture mapped color channels
const std::string & get_name() const
return name value
float get_bump_scale() const
return bump scale
const std::string & get_emission_texture_name() const
return emission_texture_name value
const std::string & get_specular_texture_name() const
return specular_texture_name value
float get_opacity() const
return opacity value
const std::string & get_ambient_texture_name() const
return ambient_texture_name value
const std::string & get_bump_texture_name() const
return bump_texture_name value
const std::string & get_opacity_texture_name() const
return opacity_texture_name value
const std::string & get_diffuse_texture_name() const
return diffuse_texture_name value
simple class to hold the material properties of a phong material
int metalness_index
index of image from which metalness should be mapped, -1 corresponds to no mapping
std::vector< std::string > image_file_names
vector of image file names
int propagation_slow_down_index
index of image from which diffuse_reflectance should be mapped, -1 corresponds to no mapping
textured_surface_material(const std::string &_name="default", BrdfType _brdf_type=BrdfType(BT_STRAUSS_DIFFUSE+BT_STRAUSS), color_type _diffuse_reflectance=0.5f, float _roughness=0.5f, float _metalness=0.0f, float _ambient_occlusion=1.0f, color_type _emission=color_type(0, 0, 0), float _transparency=0.0f, const std::complex< float > &_propagation_slow_down=std::complex< float >(1.5f, 0.0f), float _roughness_anisotropy=0.0f, float _roughness_orientation=0.0f, color_type _specular_reflectance=color_type(1, 1, 1), float _bump_scale=0.1f)
define default material
void set_name(std::string o)
set the name of the material
int transparency_index
index of image from which transparency should be mapped, -1 corresponds to no mapping
void set_sRGBA_textures(bool do_set=true)
set whether textures are interpreted in sRGB format
bool sRGBA_textures
whether textures are in sRGB format
int roughness_index
index of image from which roughness should be mapped, -1 corresponds to no mapping
int add_image_file(const std::string &file_name)
add a new image and return its index
int specular_index
index of image from which specular_reflectance should be mapped, -1 corresponds to no mapping
int ambient_index
index of image from which ambient_occlusion should be mapped, -1 corresponds to no mapping
int emission_index
index of image from which emission should be mapped, -1 corresponds to no mapping
int bump_index
index of image from which bumps should be mapped, -1 corresponds to no mapping
int diffuse_index
index of image from which diffuse_reflectance should be mapped, -1 corresponds to no mapping
int normal_index
index of image from which normals should be mapped, -1 corresponds to no mapping
the cgv namespace
Definition print.h:11