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 ac0e4d29 authored by MURRAY David's avatar MURRAY David
Browse files

wip on adding utia material (cpp holder) for parsing and cuda kernel

parent c6fe23c7
......@@ -155,6 +155,12 @@ endif()
if (ENABLE_TEST)
add_subdirectory(unit_tests)
message("Adding Test for mrf/image_laplacian_filling Module")
compile_named_test( image_laplacian_filling ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/image_laplacian_filling/main.cpp )
message("Adding Test for mrf/brdf_slice_normalization Module")
compile_named_test( brdf_slice_normalization ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/brdf_slice_normalization/main.cpp )
# Util module Tests
endif()
# ----------------------------------------------------------------------------
......
......@@ -568,97 +568,109 @@ _renderer.setMaxRenderingTime(max_rendering_time);
loger.info(_renderer->getInfos());
auto total_rendering_time = _renderer->renderSamples();
_renderer->enableAssetsUpdate();
//for (int env_phi = 0; env_phi < 1; ++env_phi)
{
//_renderer->setRotationPhi(env_phi);
auto total_rendering_time = _renderer->renderSamples();
//_renderer->disableAssetsUpdate();
std::string temp_file_name;
std::string temp_file_extension;
string dir;
std::string temp_file_name;
std::string temp_file_extension;
string dir;
// Sets the image output file will be overriden IF -o is passed fro mthe command line
mrf::util::StringParsing::fileNameFromAbsPathWithoutExtension(
parser.getSingleValue(ARG_LIST::SCENE).c_str(),
temp_file_name);
mrf::util::StringParsing::getDirectory(parser.getSingleValue(ARG_LIST::SCENE).c_str(), dir);
// Sets the image output file will be overriden IF -o is passed fro mthe command line
mrf::util::StringParsing::fileNameFromAbsPathWithoutExtension(
parser.getSingleValue(ARG_LIST::SCENE).c_str(),
temp_file_name);
mrf::util::StringParsing::getDirectory(parser.getSingleValue(ARG_LIST::SCENE).c_str(), dir);
loger.trace(" Temp file name ", temp_file_name);
loger.trace(" temp_file_extension", temp_file_extension);
loger.trace(" dir ", dir);
loger.trace(" Temp file name ", temp_file_name);
loger.trace(" temp_file_extension", temp_file_extension);
loger.trace(" dir ", dir);
//RGB rendering can save under multiples formats
#ifndef MRF_RENDERING_MODE_SPECTRAL
//multiples filename is usefull to save an image under several formats
// RP: IS this code robust when -o is not specified on the command line?
for (mrf::uint i = 0; i < parser.getMultipleValue(ARG_LIST::OUTPUT).size(); i++)
{
mrf::util::StringParsing::fileNameFromAbsPathWithoutExtension(
parser.getMultipleValue(ARG_LIST::OUTPUT)[i].c_str(),
temp_file_name);
mrf::util::StringParsing::getFileExtension(
parser.getMultipleValue(ARG_LIST::OUTPUT)[i].c_str(),
temp_file_extension);
mrf::util::StringParsing::getDirectory(parser.getMultipleValue(ARG_LIST::OUTPUT)[i].c_str(), dir);
//multiples filename is usefull to save an image under several formats
// RP: IS this code robust when -o is not specified on the command line?
for (mrf::uint i = 0; i < parser.getMultipleValue(ARG_LIST::OUTPUT).size(); i++)
{
mrf::util::StringParsing::fileNameFromAbsPathWithoutExtension(
parser.getMultipleValue(ARG_LIST::OUTPUT)[i].c_str(),
temp_file_name);
mrf::util::StringParsing::getFileExtension(
parser.getMultipleValue(ARG_LIST::OUTPUT)[i].c_str(),
temp_file_extension);
mrf::util::StringParsing::getDirectory(parser.getMultipleValue(ARG_LIST::OUTPUT)[i].c_str(), dir);
#else //spectral rendering mode
string const tmp = parser.getSingleValue(ARG_LIST::OUTPUT);
mrf::util::StringParsing::fileNameFromAbsPathWithoutExtension(tmp.c_str(), temp_file_name);
loger.trace("Current output image filename is = ", temp_file_name);
string const tmp = parser.getSingleValue(ARG_LIST::OUTPUT);
mrf::util::StringParsing::fileNameFromAbsPathWithoutExtension(tmp.c_str(), temp_file_name);
loger.trace("Current output image filename is = ", temp_file_name);
mrf::util::StringParsing::getDirectory(parser.getSingleValue(ARG_LIST::OUTPUT).c_str(), dir);
mrf::util::StringParsing::getFileExtension(parser.getSingleValue(ARG_LIST::OUTPUT).c_str(), temp_file_extension);
mrf::util::StringParsing::getDirectory(parser.getSingleValue(ARG_LIST::OUTPUT).c_str(), dir);
mrf::util::StringParsing::getFileExtension(
parser.getSingleValue(ARG_LIST::OUTPUT).c_str(),
temp_file_extension);
#endif
if (temp_file_extension == "")
{
loger.warn("File extension not specified for output. Spectral with Envy Format assigned as default!");
temp_file_extension = "hdr";
}
string samples_information = "";
if (temp_file_extension == PNG_EXTENSION)
{
samples_information = "_" + std::to_string(_renderer->numSamplesPerPixel()) + "spp";
}
if (number_of_cameras > 1)
{
// Format the Ouptut filename
unsigned int const numberOfDigits
= number_of_cameras ? static_cast<unsigned int>(std::log10(number_of_cameras)) + 1 : 1;
std::stringstream ss;
ss << std::setw(numberOfDigits + 1) << std::setfill('0') << cam_index;
std::string const s = ss.str();
if (temp_file_extension == "")
{
loger.warn("File extension not specified for output. Spectral with Envy Format assigned as default!");
temp_file_extension = "hdr";
}
string samples_information = "";
if (temp_file_extension == PNG_EXTENSION)
{
samples_information = "_" + std::to_string(_renderer->numSamplesPerPixel()) + "spp";
}
//string env_info = "_envPhi";
//if(env_phi < 10) env_info += std::to_string(0);
//if(env_phi < 100) env_info += std::to_string(0);
// env_info += std::to_string(env_phi);
if (number_of_cameras > 1)
{
// Format the Ouptut filename
unsigned int const numberOfDigits
= number_of_cameras ? static_cast<unsigned int>(std::log10(number_of_cameras)) + 1 : 1;
std::stringstream ss;
ss << std::setw(numberOfDigits + 1) << std::setfill('0') << cam_index;
std::string const s = ss.str();
Camera const *current_cam = cams[cam_index];
temp_file_name = dir + ss.str() + "_" + current_cam->idName() + "_" + temp_file_name + samples_information
/*+ env_info*/ + "." + temp_file_extension;
}
else
{
temp_file_name = dir + temp_file_name + samples_information /*+ env_info*/ + "." + temp_file_extension;
}
loger.trace("Current output image filename is = ", temp_file_name);
std::string comment_rendering_time
= "Total rendering time = " + std::to_string(total_rendering_time) + " s\n";
_renderer->saveImage(temp_file_name, comment_rendering_time);
Camera const *current_cam = cams[cam_index];
#ifndef MRF_RENDERING_MODE_SPECTRAL
} //endfor multiple filenames RGB mode
#endif
temp_file_name = dir + ss.str() + "_" + current_cam->idName() + "_" + temp_file_name + samples_information
+ "." + temp_file_extension;
}
else
if (logfile_stream.is_open())
{
temp_file_name = dir + temp_file_name + samples_information + "." + temp_file_extension;
logfile_stream << parser.getSingleValue(ARG_LIST::SCENE) << ", " << std::to_string(total_rendering_time)
<< "," << parser.getSingleValue(ARG_LIST::SAMPLES) << ","
<< parser.getSingleValue(ARG_LIST::SPF) << std::endl;
}
loger.trace("Current output image filename is = ", temp_file_name);
std::string comment_rendering_time
= "Total rendering time = " + std::to_string(total_rendering_time) + " s\n";
_renderer->saveImage(temp_file_name, comment_rendering_time);
#ifndef MRF_RENDERING_MODE_SPECTRAL
} //endfor multiple filenames RGB mode
#endif
if (logfile_stream.is_open())
{
logfile_stream << parser.getSingleValue(ARG_LIST::SCENE) << ", " << std::to_string(total_rendering_time)
<< "," << parser.getSingleValue(ARG_LIST::SAMPLES) << ","
<< parser.getSingleValue(ARG_LIST::SPF) << std::endl;
std::cout << "Image saved to: " << temp_file_name << std::endl;
std::cout << "Rendering Time: " << std::to_string(total_rendering_time) << " seconds" << std::endl;
}
std::cout << "Image saved to: " << temp_file_name << std::endl;
std::cout << "Rendering Time: " << std::to_string(total_rendering_time) << " seconds" << std::endl;
_renderer->nextCamera();
} //for loop on cameras
......
......@@ -12,6 +12,7 @@
#include <mrf_core/geometry/direction.hpp>
#include <mrf_core/materials/all_materials.hpp>
#include <mrf_core/materials/measured_utia.hpp>
#include <mrf_optix/optix_material_handler.hpp>
#include <mrf_optix/optix_util.hpp>
......@@ -59,6 +60,7 @@ void OptixMaterialHandler::releaseMemory()
//_dirac_emittance->destroy();
//_debug_shader->destroy();
//_shadow_catcher->destroy();
_measured_utia->destroy();
for (auto it_buffer = _measured_materials_buffer.begin(); it_buffer != _measured_materials_buffer.end(); ++it_buffer)
{
......@@ -95,6 +97,30 @@ void OptixMaterialHandler::releaseMemory()
auto texture = it->second;
texture->destroy();
}
for (auto it = _utia_texture.begin(); it != _utia_texture.end(); ++it)
{
auto tex_list = it->second;
tex_list->destroy();
}
for (auto it = _utia_indexed_textures.begin(); it != _utia_indexed_textures.end(); ++it)
{
auto tex_list = it->second;
tex_list.clear();
}
for (auto it = _index_map.begin(); it != _index_map.end(); ++it)
{
auto texture = it->second;
texture->destroy();
}
for (auto it = _utia_maps_indexes.begin(); it != _utia_maps_indexes.end(); ++it)
{
auto buffer = it->second;
buffer->destroy();
}
}
#ifdef MRF_RENDERING_MODE_SPECTRAL
......@@ -138,6 +164,8 @@ optix::Material OptixMaterialHandler::createMaterialFromMRF(
{
float albedo = lambert->diffuseAlbedo();
std::vector<std::string> variable_names = {"diffuse_color", "diffuse_color2"};
{"-DUTIA", nullptr},
std::vector<mrf::materials::RADIANCE_TYPE> variable_values;
variable_values.push_back(lambert->getColor() * albedo);
......@@ -251,7 +279,7 @@ optix::Material OptixMaterialHandler::createMaterialFromMRF(
optix_mat["_is_conductor"]->setInt(0); //HARDCODED FOR NOW: 0 = false.
compile_options.push_back("-DMICROFACET_DIELECTRIC");
compileBTDF(optix_mat, compile_options);
compileBSDF(optix_mat, compile_options);
return optix_mat;
}
......@@ -293,7 +321,7 @@ optix::Material OptixMaterialHandler::createMaterialFromMRF(
optix_mat["_thickness"]->setFloat(0.f);
compile_options.push_back("-DMICROFACET_DIELECTRIC");
compileBTDF(optix_mat, compile_options);
compileBSDF(optix_mat, compile_options);
return optix_mat;
}
......@@ -545,16 +573,16 @@ optix::Material OptixMaterialHandler::createMaterialFromMRF(
void OptixMaterialHandler::compileBRDF(optix::Material &mat, std::vector<std::string> const &cuda_compile_options)
{
const char * ptx = getPtxString("reflective_kernel.cu", cuda_compile_options);
const char * ptx = getPtxString("BRDF_kernel.cu", cuda_compile_options);
optix::Program closest_hit = _context->createProgramFromPTXString(ptx, "material_eval");
optix::Program any_hit = _context->createProgramFromPTXString(ptx, "shadow");
mat->setClosestHitProgram(0, closest_hit);
mat->setAnyHitProgram(1, any_hit);
}
void OptixMaterialHandler::compileBTDF(optix::Material &mat, std::vector<std::string> const &cuda_compile_options)
void OptixMaterialHandler::compileBSDF(optix::Material &mat, std::vector<std::string> const &cuda_compile_options)
{
const char * ptx = getPtxString("all_purpose_kernel.cu", cuda_compile_options);
const char * ptx = getPtxString("BSDF_kernel.cu", cuda_compile_options);
optix::Program closest_hit = _context->createProgramFromPTXString(ptx, "material_eval");
optix::Program any_hit = _context->createProgramFromPTXString(ptx, "shadow");
mat->setClosestHitProgram(0, closest_hit);
......@@ -835,6 +863,24 @@ void OptixMaterialHandler::updateTextures()
updateTexturesPhong(phong_textured, wavelengths);
#else
updateTexturesPhong(phong_textured);
#endif
}
mrf::materials::UTIA *utia = dynamic_cast<mrf::materials::UTIA *>(material);
if (utia)
{
#ifdef MRF_RENDERING_MODE_SPECTRAL
updateTextureUTIA(utia, wavelengths);
#else
updateTextureUTIA(utia);
#endif
}
mrf::materials::IndexedUTIA *idx_utia = dynamic_cast<mrf::materials::IndexedUTIA *>(material);
if (idx_utia)
{
#ifdef MRF_RENDERING_MODE_SPECTRAL
updateTextureIndexedUTIA(idx_utia, wavelengths);
#else
updateTextureIndexedUTIA(idx_utia);
#endif
}
}
......@@ -888,7 +934,7 @@ void OptixMaterialHandler::updateTexturesGlass(
auto it = _glass_cdf.find(fresnel_glass);
if (it == _glass_cdf.end())
{
tex_sampler = mrf::optix_backend::createOptixTexture(
tex_sampler = mrf::optix_backend::createClampedOptixTexture(
_context,
RT_FORMAT_FLOAT,
fresnel_glass->getTransCDF(wavelengths).size());
......@@ -924,8 +970,10 @@ void OptixMaterialHandler::updateTexturesGlass(
auto it = _glass_cdf.find(walter);
if (it == _glass_cdf.end())
{
tex_sampler
= mrf::optix_backend::createOptixTexture(_context, RT_FORMAT_FLOAT, walter->getTransCDF(wavelengths).size());
tex_sampler = mrf::optix_backend::createClampedOptixTexture(
_context,
RT_FORMAT_FLOAT,
walter->getTransCDF(wavelengths).size());
_glass_cdf[walter] = tex_sampler;
}
else
......@@ -958,7 +1006,6 @@ void OptixMaterialHandler::updateTexturesPhong(mrf::materials::LPhysicalPhongTex
_loger.trace("UPDATE PHONG TEXTURES");
mrf::util::PrecisionTimer timer;
timer.start();
optix::TextureSampler tex_sampler;
if (phong_textured->hasDiffuseTexture())
{
......@@ -968,14 +1015,14 @@ void OptixMaterialHandler::updateTexturesPhong(mrf::materials::LPhysicalPhongTex
if (it == _phong_diffuse_textures.end())
{
#ifdef MRF_RENDERING_MODE_SPECTRAL
tex_sampler = mrf::optix_backend::createOptixTexture(
tex_sampler = mrf::optix_backend::createRepeatedOptixTexture(
_context,
tex_format,
phong_textured->getDiffuseTexture().width(),
phong_textured->getDiffuseTexture().height(),
wavelengths.size());
#else
tex_sampler = mrf::optix_backend::createOptixTexture(
tex_sampler = mrf::optix_backend::createRepeatedOptixTexture(
_context,
tex_format,
phong_textured->getDiffuseTexture().width(),
......@@ -999,29 +1046,35 @@ void OptixMaterialHandler::updateTexturesPhong(mrf::materials::LPhysicalPhongTex
{
if (phong_textured->getSpecularTexture().width() > 0 && phong_textured->getSpecularTexture().height() > 0)
{
#ifdef MRF_RENDERING_MODE_SPECTRAL
#else
auto it = _phong_specular_textures.find(phong_textured);
if (it == _phong_specular_textures.end())
{
tex_sampler = mrf::optix_backend::createOptixTexture(
#ifdef MRF_RENDERING_MODE_SPECTRAL
tex_sampler = mrf::optix_backend::createRepeatedOptixTexture(
_context,
tex_format,
phong_textured->getSpecularTexture().width(),
phong_textured->getSpecularTexture().height(),
wavelengths.size());
#else
tex_sampler = mrf::optix_backend::createRepeatedOptixTexture(
_context,
tex_format,
phong_textured->getSpecularTexture().width(),
phong_textured->getSpecularTexture().height());
_phong_specular_textures[phong_textured] = tex_sampler;
#endif
}
else
{
tex_sampler = it->second;
}
//#ifdef MRF_RENDERING_MODE_SPECTRAL
// mrf::optix_backend::updateTextureFromSpectralImage(
// phong_textured->getSpecularTexture(),
// tex_sampler,
// wavelengths);
//#else
#ifdef MRF_RENDERING_MODE_SPECTRAL
mrf::optix_backend::updateTextureFromSpectralImage(
phong_textured->getSpecularTexture(),
tex_sampler,
wavelengths);
#else
mrf::optix_backend::updateTextureFromImage(phong_textured->getSpecularTexture(), tex_sampler);
#endif
}
......@@ -1034,7 +1087,7 @@ void OptixMaterialHandler::updateTexturesPhong(mrf::materials::LPhysicalPhongTex
auto it = _phong_normal_maps.find(phong_textured);
if (it == _phong_normal_maps.end())
{
tex_sampler = mrf::optix_backend::createOptixTexture(
tex_sampler = mrf::optix_backend::createRepeatedOptixTexture(
_context,
RT_FORMAT_FLOAT4,
phong_textured->getNormalMap().width(),
......@@ -1057,7 +1110,7 @@ void OptixMaterialHandler::updateTexturesPhong(mrf::materials::LPhysicalPhongTex
auto it = _phong_exponent_maps.find(phong_textured);
if (it == _phong_exponent_maps.end())
{
tex_sampler = mrf::optix_backend::createOptixTexture(
tex_sampler = mrf::optix_backend::createRepeatedOptixTexture(
_context,
RT_FORMAT_FLOAT,
phong_textured->getExponentMap().width(),
......@@ -1107,6 +1160,214 @@ void OptixMaterialHandler::updateMaterialIndex(mrf::materials::MultiMaterial *mu
}
#ifdef MRF_RENDERING_MODE_SPECTRAL
void OptixMaterialHandler::updateTextureUTIA(mrf::materials::UTIA *utia, std::vector<uint> wavelengths)
#else
void OptixMaterialHandler::updateTextureUTIA(mrf::materials::UTIA *utia)
#endif
{
RTformat tex_format;
#ifdef MRF_RENDERING_MODE_SPECTRAL
tex_format = RT_FORMAT_FLOAT;
#else
tex_format = RT_FORMAT_FLOAT4;
#endif
optix::TextureSampler tex_sampler;
if (utia->hasTexture())
{
if (utia->getUTIAData().width() > 0 && utia->getUTIAData().height() > 0)
{
auto it = _utia_texture.find(utia);
if (it == _utia_texture.end())
{
tex_sampler = mrf::optix_backend::createClampedOptixTexture(
_context,
tex_format,
utia->getUTIAData().width(),
utia->getUTIAData().height());
#ifdef MRF_RENDERING_MODE_SPECTRAL
//TODO ASAP
//mrf::optix_backend::updateTextureFromSpectralImage(utia->getUTIAData(), tex_sampler, 0);
#else
mrf::optix_backend::updateTextureFromImage(utia->getUTIAData(), tex_sampler);
#endif
_loger.info("Loaded UTIA on GPU");
}
else
{
tex_sampler = it->second;
}
}
}
else
{
_loger.fatal("UTIA has no data !");
}
_utia_texture[utia] = tex_sampler;
{
auto it = _utia_maps_indexes.find(utia);
if (it == _utia_maps_indexes.end())
{
auto index_buffer = _context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_INT);
index_buffer->setSize(1);
void *data = index_buffer->map();
int * int_data = (int *)(data);
int_data[0] = tex_sampler->getId();
index_buffer->unmap();
_utia_maps_indexes[utia] = index_buffer;
}
}
{
auto it = _utia_maps_param.find(utia);
if (it == _utia_maps_param.end())
{
auto param_buffer = _context->createBuffer(RT_BUFFER_INPUT);
param_buffer->setFormat(RT_FORMAT_USER);
param_buffer->setElementSize(sizeof(int) * 8);
param_buffer->setSize(1);
void *data = param_buffer->map();
int * int_data = (int *)(data);
int_data[0] = utia->getThetaVDiv();
int_data[1] = utia->getPhiVDiv();
int_data[2] = utia->getThetaIDiv();
int_data[3] = utia->getPhiIDiv();
int_data[4] = utia->getParameterization();
int_data[5] = utia->getInterpolate();
_loger.trace(
"T_v:" + std::to_string(int_data[0]) + " | P_v:" + std::to_string(int_data[1])
+ " | T_i:" + std::to_string(int_data[2]) + " | P_i:" + std::to_string(int_data[3]));
param_buffer->unmap();
_utia_maps_param[utia] = param_buffer;
}
}
}
#ifdef MRF_RENDERING_MODE_SPECTRAL
void OptixMaterialHandler::updateTextureIndexedUTIA(
mrf::materials::IndexedUTIA *idx_utia,
std::vector<uint> wavelengths)
#else
void OptixMaterialHandler::updateTextureIndexedUTIA(mrf::materials::IndexedUTIA *idx_utia)
#endif
{
RTformat tex_format;
#ifdef MRF_RENDERING_MODE_SPECTRAL
tex_format = RT_FORMAT_FLOAT;
#else
tex_format = RT_FORMAT_FLOAT4;
#endif
std::vector<unsigned int> indexes;
std::vector<optix::TextureSampler> textures;
optix::TextureSampler tex_sampler;
for (int i = 0; i < static_cast<int>(idx_utia->depth()); ++i)
{
if (idx_utia->hasTexture(i))
{
if (idx_utia->getUTIAData(i).width() > 0 && idx_utia->getUTIAData(i).height() > 0)
{
auto it = _utia_indexed_textures.find(idx_utia);
if (it == _utia_indexed_textures.end())
{
tex_sampler = mrf::optix_backend::createClampedOptixTexture(
_context,
tex_format,
idx_utia->getUTIAData(i).width(),
idx_utia->getUTIAData(i).height());
textures.push_back(tex_sampler);
indexes.push_back(tex_sampler->getId());
#ifdef MRF_RENDERING_MODE_SPECTRAL
//TODO ASAP
//mrf::optix_backend::updateTextureFromSpectralImage(utia->getUTIAData(i), tex_sampler, 0);
#else
mrf::optix_backend::updateTextureFromImage(idx_utia->getUTIAData(i), tex_sampler);
#endif
_loger.info("Loaded UTIA on GPU");
}
else
{
tex_sampler = it->second[i];
}
}
}
}
_utia_indexed_textures[idx_utia] = textures;
if (idx_utia->hasMap())
{
if (idx_utia->getUTIAMap().width() > 0 && idx_utia->getUTIAMap().height() > 0)
{
auto it = _index_map.find(idx_utia);
if (it == _index_map.end())
{
tex_sampler = mrf::optix_backend::createClampedOptixTexture(
_context,
tex_format,
idx_utia->getUTIAMap().width(),
idx_utia->getUTIAMap().height());
_index_map[idx_utia] = tex_sampler;
mrf::optix_backend::updateTextureFromImage(idx_utia->getUTIAMap(), tex_sampler);
_loger.info("Loaded material map on GPU");
}
else
{
tex_sampler = it->second;
}
}
}