MCPcopy Create free account
hub / github.com/TomClabault/HIPRT-Path-Tracer / load_scene_texture

Method load_scene_texture

src/Threads/ThreadFunctions.cpp:33–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33void ThreadFunctions::load_scene_texture(Scene& parsed_scene, std::string scene_path, const std::vector<std::pair<aiTextureType, std::string>>& tex_paths, const std::vector<int>& material_indices, int thread_index, int nb_threads)
34{
35 // Preparing the scene_filepath so that it's ready to be appended with the texture name
36 std::string corrected_filepath;
37 // Starting with the .GLTF/.OBJ/.whatever-scene-format file
38 corrected_filepath = scene_path;
39 // Removing the name of the .GLTF / .OBJ / .XXX file by looking at the *last* '/' or '\'
40 if (corrected_filepath.find('/') != std::string::npos)
41 corrected_filepath = corrected_filepath.substr(0, corrected_filepath.rfind('/') + 1);
42 else if (corrected_filepath.find('\\') != std::string::npos)
43 corrected_filepath = corrected_filepath.substr(0, corrected_filepath.rfind('\\') + 1);
44 // Converting the path to absolute
45 corrected_filepath = std::filesystem::absolute(corrected_filepath).string();
46 // Replacing backslashes by forward slashes
47 corrected_filepath = std::regex_replace(corrected_filepath, std::regex("\\\\"), "/"); // replace 'def' -> 'klm'
48
49 // While loop here so that a single thread can parse multiple textures
50 while (thread_index < parsed_scene.textures.size())
51 {
52 // Taking the name of the texture
53 std::string texture_file_path = tex_paths[thread_index].second;
54 // Adding the name of the texture to the absolute path of the scene file such that
55 // we're looking for textures next to the GLTF file
56 std::string full_path = corrected_filepath + texture_file_path;
57 aiTextureType type = tex_paths[thread_index].first;
58 int nb_channels;
59
60 switch (type)
61 {
62 case aiTextureType_BASE_COLOR:
63 case aiTextureType_DIFFUSE:
64 // 4 Channels because we may want the alpha for transparency handling
65 nb_channels = 4;
66 break;
67
68 case aiTextureType_NORMALS:
69 case aiTextureType_HEIGHT:
70 // Don't need the alpha
71 // TODO we only need 3 channels here but it's tricky to handle 3 channels texture with HIP/CUDA. Supported formats are only 1, 2, 4 channels, not three
72 nb_channels = 4;
73 break;
74
75 case aiTextureType_DIFFUSE_ROUGHNESS:
76 if (parsed_scene.materials[material_indices[thread_index]].roughness_metallic_texture_index != MaterialConstants::NO_TEXTURE)
77 {
78 // This means we have a packed metallic/roughness texture
79 nb_channels = 4;
80
81 break;
82 }
83 else
84 {
85 // Otherwise, we don't have a packed metallic/roughness texture so only 1 channel just for the roughness
86 nb_channels = 1;
87
88 break;
89 }
90

Callers

nothing calls this directly

Calls 5

ColorRGB32FClass · 0.85
is_constant_colorMethod · 0.80
sample_rgba32fMethod · 0.80
is_fully_opaqueMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected