Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit c223dab0 authored by MURRAY David's avatar MURRAY David
Browse files

add support on cpp side for texture index, NOT TESTED

parent 812b06c9
Pipeline #257767 failed with stages
in 6 minutes and 16 seconds
......@@ -1078,6 +1078,35 @@ void OptixMaterialHandler::updateTexturesPhong(mrf::materials::LPhysicalPhongTex
}
void OptixMaterialHandler::updateMaterialIndex(mrf::materials::MultiMaterial *multi_mat)
{
optix::TextureSampler tex_sampler;
if (multi_mat->hasTexture())
{
if (multi_mat->getIndexMap().width() > 0 && multi_mat->getIndexMap().height() > 0)
{
auto it = _mat_index_maps.find(multi_mat);
if (it == _mat_index_maps.end())
{
tex_sampler = mrf::optix_backend::createOptixTexture(
_context,
RT_FORMAT_FLOAT4,
multi_mat->getIndexMap().width(),
multi_mat->getIndexMap().height());
_mat_index_maps[multi_mat] = tex_sampler;
mrf::optix_backend::updateTextureFromImage(multi_mat->getIndexMap(), tex_sampler);
}
else
{
tex_sampler = it->second;
}
}
}
}
#ifdef MRF_RENDERING_MODE_SPECTRAL
void OptixMaterialHandler::updateMaterials(std::vector<uint> wavelengths)
#else
......@@ -1372,10 +1401,21 @@ void OptixMaterialHandler::applyMaterial(/*OptiXMesh &optix_mesh,*/
if (multi_mat)
{
mrf_indices = multi_mat->getAllMRFId();
auto it = _mat_index_maps.find(multi_mat);
if (it != _mat_index_maps.end())
{
geom_instance["index_tex_id"]->setInt(it->second->getId());
}
else
{
geom_instance["index_tex_id"]->setInt(-1);
}
}
else
{
mrf_indices.push_back(material_index);
geom_instance["index_tex_id"]->setInt(-1);
}
......
......@@ -22,6 +22,7 @@
#include <vector>
#include <map>
#include <mrf_core/materials/multi_material.hpp>
#include <mrf_core/materials/l_phong_textured.hpp>
#include <mrf_core/materials/fresnel_glass.hpp>
#include <mrf_core/materials/walter_bsdf.hpp>
......@@ -94,6 +95,8 @@ public:
#endif
void updateMaterialIndex(mrf::materials::MultiMaterial *multi_mat);
bool needMeshRefine(uint material_id) const;
......@@ -171,6 +174,9 @@ private:
//
std::map<mrf::materials::UMat *, optix::Material> _materials;
std::map<mrf::materials::UMat *, optix::TextureSampler> _mat_index_maps;
/**
* All the non-material specific textures
**/
......
......@@ -228,12 +228,6 @@ public:
static constexpr char const *const ANISOTROPIC_MK = "anisotropic";
static constexpr char const *const METALLIC_MK = "metallic";
static constexpr char const *const COUNT_AT = "count";
static constexpr char const *const INDEX_AT = "index";
//LIGHTS
static constexpr char const *const LIGHTS_MK = "lights";
static constexpr char const *const POINT_LIGHT_MK = "point_light";
......@@ -299,6 +293,8 @@ public:
static constexpr char const *const CAM_POSITION_MK = "position";
static constexpr char const *const CAM_UP_MK = "up";
//Multi material
static constexpr char const *const TEXTURE_INDEX_MK = "texture";
//ATTRIBUTE VALUES
static constexpr char const *const BCKG_UNIFORM_TYPE_VAL = "uniform";
......
......@@ -1599,9 +1599,7 @@ bool SceneParser::addMaterial(XMLElement *a_mat_element, mrf::rendering::Scene &
if (type.compare(BRDFTypes::MULTI_MAT) == 0)
{
_loger->trace("Multi-Material Detected, parsing them");
unsigned int count;
int rOk = a_mat_element->QueryUnsignedAttribute(SceneLexer::COUNT_AT, &count);
MultiMaterial *multimat = new MultiMaterial(name, count);
MultiMaterial *multimat = new MultiMaterial(name);
bool rOK = parseMultiMaterial(a_mat_element, multimat, scene);
if (rOK)
{
......@@ -2799,7 +2797,27 @@ bool SceneParser::parseMultiMaterial(
mrf::materials::MultiMaterial *multi_mat,
mrf::rendering::Scene & scene)
{
XMLElement *material = a_mat_element->FirstChildElement();
if (a_mat_element->FirstChildElement(SceneLexer::TEXTURE_INDEX_MK))
{
//const char *path = a_mat_element->FirstChildElement(SceneLexer::TEXTURE_INDEX_MK)->Attribute(SceneLexer::FILE_PATH_AT);
//if(path) multi_mat->setTexturePath(path);
std::string path;
if (parseTexture(a_mat_element, SceneLexer::TEXTURE_INDEX_MK, path))
{
if (!checkErrorOnTextureLoading(multi_mat->loadIndexTexture(path), path))
{
_loger->fatal("In multi-material: Specified a texture index without path.");
return false;
}
}
else
{
_loger->fatal("In multi-material: Specified a texture index without path.");
return false;
}
}
XMLElement *material = a_mat_element->FirstChildElement(SceneLexer::MATERIAL_MK);
_loger->trace("Materials Found ! Parsing it....");
......
#include "multi_material.hpp"
#include <mrf_core/image/image_formats.hpp>
namespace mrf
{
namespace materials
{
MultiMaterial::MultiMaterial(std::string const &name, unsigned int nb_mat): BRDF(name) {}
MultiMaterial::MultiMaterial(std::string const &name): BRDF(name) {}
MultiMaterial::~MultiMaterial() {}
mrf::image::IMAGE_LOAD_SAVE_FLAGS MultiMaterial::loadIndexTexture(std::string const &path)
{
try
{
_index_map = mrf::image::load(path);
_index_texture_path = std::string(path);
}
catch (mrf::image::IMAGE_LOAD_SAVE_FLAGS &error)
{
return error;
}
return mrf::image::IMAGE_LOAD_SAVE_FLAGS::MRF_NO_ERROR;
}
} // namespace materials
} // namespace mrf
\ No newline at end of file
......@@ -6,6 +6,8 @@
#include <mrf_core/materials/brdf.hpp>
#include <mrf_core/image/color_image.hpp>
namespace mrf
{
namespace materials
......@@ -19,8 +21,12 @@ protected:
std::vector<unsigned int> _mrf_indices;
std::vector<std::string> _names;
std::string _index_texture_path;
std::unique_ptr<mrf::image::ColorImage> _index_map;
public:
MultiMaterial(std::string const &name, unsigned int nb_mat);
MultiMaterial(std::string const &name);
~MultiMaterial();
//void addEntry(unsigned int idx, std::string name) { _material_map[idx] = name; }
......@@ -32,9 +38,16 @@ public:
void addMRFIdEntry(unsigned int idx) { _mrf_indices.push_back(idx); }
void addNameEntry(std::string name) { _names.push_back(name); }
mrf::image::IMAGE_LOAD_SAVE_FLAGS loadIndexTexture(std::string const &path);
std::vector<unsigned int> &getAllMRFId() { return _mrf_indices; }
std::vector<std::string> & getAllNames() { return _names; }
std::string getTexturePath() const { return _index_texture_path; }
mrf::image::ColorImage const &getIndexMap() const { return *_index_map.get(); }
bool hasTexture() const { return _index_map.get() != nullptr; }
size_t size() { return _names.size(); }
};
} // namespace materials
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment