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
10 name = obj_mat.name;
11 brdf_type = BrdfType(BT_LAMBERTIAN + BT_PHONG);
12 obj_material::color_type a = obj_mat.ambient, d = obj_mat.diffuse;
13 float la = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
14 float ld = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
15 ambient_occlusion = la >= ld ? la : la / ld;
18 emission = obj_mat.emission;
19 roughness = std::max(0.0f, std::min(1.0f, 1.0f / (obj_mat.shininess + 0.992307f) - 0.0077524f));
20 transparency = 1.0f - obj_mat.opacity;
21 bump_scale = obj_mat.bump_scale;
22
23 std::map<std::string, int> file_name_map;
24
25 const auto& add_texture = [this, &file_name_map](const std::string& texture_file_name, int& texture_index) {
26 if(!texture_file_name.empty()) {
27 // Insert the texture file name and index into the map if it does not already exist.
28 if(file_name_map.find(texture_file_name) == file_name_map.end())
29 file_name_map[texture_file_name] = add_image_file(texture_file_name);
30 // Get the index which is either the newly added index or an index from previous entries with the same texture name.
31 texture_index = file_name_map[texture_file_name];
32 }
33 };
34
35 add_texture(obj_mat.ambient_texture_name, ambient_index);
36 add_texture(obj_mat.diffuse_texture_name, diffuse_index);
37 add_texture(obj_mat.opacity_texture_name, transparency_index);
38 add_texture(obj_mat.specular_texture_name, specular_index);
39 add_texture(obj_mat.emission_texture_name, emission_index);
40 add_texture(obj_mat.bump_texture_name, bump_index);
41}
42
44int textured_surface_material::add_image_file(const std::string& file_name) {
45 int idx = static_cast<int>(image_file_names.size());
46 image_file_names.push_back(file_name);
47 return idx;
48}
49
50 }
51 }
52}
std::vector< std::string > image_file_names
vector of image file names
int transparency_index
index of image from which transparency 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
textured_surface_material()
construct using default values
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
the cgv namespace
Definition print.h:11
Extension of a phong material with support for texture-mapped color channels.
float bump_scale
scaling factor for bump map
std::string emission_texture_name
file name of emission texture
std::string bump_texture_name
file name of bump map texture
std::string diffuse_texture_name
file name of diffuse texture
std::string specular_texture_name
file name of specular texture
std::string ambient_texture_name
file name of ambient texture
std::string name
name of material
std::string opacity_texture_name
file name of opacity texture
color_type ambient
ambient color component
color_type emission
emissive color component
color_type diffuse
diffuse color component
color_type specular
specular color component
float shininess
exponent of the specular cosine term
color_type diffuse_reflectance
diffuse reflectance of surface, defaults to 0.5,0.5,0.5
BrdfType brdf_type
store brdf type, defaults to BT_STRAUSS_DIFFUSE + BT_STRAUSS
color_type emission
emissive color component, defaults to 0,0,0
color_type specular_reflectance
specular color used to modulate specular reflection component, should be 1,1,1
float transparency
modulation for transparency, defaults to 0
float roughness
surface roughness in the range [0,1] (1/2 trace of symmetric 2x2 matrix for anisotropic case where di...
float ambient_occlusion
scalar factor to down scale ambient light, defaults to 1