Commit 3614f06d authored by MURRAY David's avatar MURRAY David
Browse files

restore classic optix geometry (no core) for multi-materials ONLY

parent fd0c44a4
......@@ -66,8 +66,9 @@ void OptixGeometryHandler::importMrfScene(
top_group->addChild(geometry_group);
//Set up generic triangle mesh programs
//ptx = getPtxString("triangle_mesh.cu", cuda_compile_options_temp);
ptx = getPtxString("triangle_attributes.cu", cuda_compile_options);
ptx = getPtxString("triangle_mesh.cu", cuda_compile_options);
const char *tri_ptx = getPtxString("triangle_attributes.cu", cuda_compile_options);
//ptx = getPtxString("triangle_attributes.cu", cuda_compile_options);
//Create geometry group for triangle geometry (using GeometryTriangle)
optix::GeometryGroup tri_geometry_group = _context->createGeometryGroup();
......@@ -95,7 +96,6 @@ void OptixGeometryHandler::importMrfScene(
unsigned int mat_index = a_sphere->materialIndex();
_optix_analytical_shapes.push_back(std::make_pair(gi, mat_index));
// ADD MATERIAL Dummy material for now
gi->addMaterial(material_handler.getMaterialFromMRF(mat_index)[0]);
//TODO UPDATE aabb ?
......@@ -119,11 +119,32 @@ void OptixGeometryHandler::importMrfScene(
uint material_id = (*shape_it)->materialIndex();
if (material_handler.needMeshRefine(material_id))
optix_mesh.attributes = _context->createProgramFromPTXString(ptx, "triangle_attributes_refine");
std::vector<optix::Material> optix_materials = material_handler.getMaterialFromMRF(material_id);
optix::Matrix4x4 transform = optix::Matrix4x4((*shape_it)->worldToObjectTransform().ptr());
if (optix_materials.size() == 1)
{
if (material_handler.needMeshRefine(material_id))
optix_mesh.attributes = _context->createProgramFromPTXString(tri_ptx, "triangle_attributes_refine");
else
optix_mesh.attributes = _context->createProgramFromPTXString(tri_ptx, "triangle_attributes");
loadMeshFromMRF(*mrf_mesh, optix_mesh, transform, optix_materials);
tri_geometry_group->addChild(optix_mesh.geom_instance);
}
else
optix_mesh.attributes = _context->createProgramFromPTXString(ptx, "triangle_attributes");
{
if (material_handler.needMeshRefine(material_id))
optix_mesh.intersection = _context->createProgramFromPTXString(ptx, "mesh_intersect_refine");
else
optix_mesh.intersection = _context->createProgramFromPTXString(ptx, "mesh_intersect");
optix_mesh.bounds = _context->createProgramFromPTXString(ptx, "mesh_bounds");
loadMeshFromMRF(*mrf_mesh, optix_mesh, transform, optix_materials);
geometry_group->addChild(optix_mesh.geom_instance);
}
//if (material_handler.needMeshRefine(material_id))
// optix_mesh.intersection = _context->createProgramFromPTXString(ptx, "mesh_intersect_refine");
//else
......@@ -138,22 +159,14 @@ void OptixGeometryHandler::importMrfScene(
//that hasn't got any material or closesthit/
//optix_mesh.material = material_handler.lambert();
std::vector<optix::Material> optix_materials = material_handler.getMaterialFromMRF(material_id);
//std::vector<optix::Material> optix_materials;
//optix_materials.push_back(material_handler.lambert());
optix::Matrix4x4 transform = optix::Matrix4x4((*shape_it)->worldToObjectTransform().ptr());
//transform = transform.transpose();
//loadMesh(file_name, optix_mesh, transform);
loadMeshFromMRF(*mrf_mesh, optix_mesh, transform, optix_materials);
//optix_mesh.has_texcoords = mesh.has_texcoords;
tri_geometry_group->addChild(optix_mesh.geom_instance);
aabb.include(optix_mesh.bbox_min, optix_mesh.bbox_max);
......@@ -192,7 +205,7 @@ void OptixGeometryHandler::importMrfScene(
//gi->addMaterial(material_handler.diffuseEmittance());
int light_index = std::distance(optix_sph_lights.cbegin(), it);
int light_index = std::distance(optix_sph_lights.cbegin(), it);
auto mat = light_handler.getUMatPointerSpereLight(light_index);
gi->addMaterial(material_handler.getMaterialFromUMat(mat));
......@@ -336,50 +349,82 @@ void OptixGeometryHandler::loadMeshFromMRF(
{
// Rewrite all mat_indices to point to single override material
memset(mesh.mat_indices, 0, mesh.num_triangles * sizeof(uint32_t));
//optix_materials.push_back(optix_mesh.material);
optix::GeometryTriangles geometry = optix_mesh.context->createGeometryTriangles();
geometry->setPrimitiveCount(mesh.num_triangles);
geometry->setVertices(static_cast<unsigned int>(mrf_mesh.vertices().size()), buffers.positions, RT_FORMAT_FLOAT3);
geometry->setTriangleIndices(buffers.tri_indices, RT_FORMAT_UNSIGNED_INT3);
geometry["vertex_buffer"]->setBuffer(buffers.positions);
geometry["normal_buffer"]->setBuffer(buffers.normals);
geometry["texcoord_buffer"]->setBuffer(buffers.texcoords);
geometry["tangent_buffer"]->setBuffer(buffers.tangents);
geometry["index_buffer"]->setBuffer(buffers.tri_indices);
geometry->setAttributeProgram(optix_mesh.attributes);
//Materials: TODO: per face
geometry->setMaterialCount(optix_materials.size());
geometry->setMaterialIndices(buffers.mat_indices, 0, 0, RT_FORMAT_UNSIGNED_INT);
optix_mesh.geom_instance
= optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end());
}
else
{
assert(mrf_mesh.materialPerFaces().size() == mesh.num_triangles);
memcpy(
mesh.mat_indices,
&mrf_mesh.materialPerFaces()[0], mrf_mesh.materialPerFaces().size() * sizeof(uint32_t));
memcpy(mesh.mat_indices, &mrf_mesh.materialPerFaces()[0], mrf_mesh.materialPerFaces().size() * sizeof(uint32_t));
optix::Geometry geometry = optix_mesh.context->createGeometry();
geometry->setPrimitiveCount(mesh.num_triangles);
geometry["vertex_buffer"]->setBuffer(buffers.positions);
geometry["normal_buffer"]->setBuffer(buffers.normals);
geometry["texcoord_buffer"]->setBuffer(buffers.texcoords);
geometry["tangent_buffer"]->setBuffer(buffers.tangents);
geometry["material_buffer"]->setBuffer(buffers.mat_indices);
geometry["index_buffer"]->setBuffer(buffers.tri_indices);
geometry->setPrimitiveCount(mesh.num_triangles);
geometry->setBoundingBoxProgram(optix_mesh.bounds);
geometry->setIntersectionProgram(optix_mesh.intersection);
optix_mesh.geom_instance
= optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end());
}
optix::GeometryTriangles geometry = optix_mesh.context->createGeometryTriangles();
geometry->setPrimitiveCount(mesh.num_triangles);
geometry->setVertices(static_cast<unsigned int>(mrf_mesh.vertices().size()), buffers.positions, RT_FORMAT_FLOAT3);
geometry->setTriangleIndices(buffers.tri_indices, RT_FORMAT_UNSIGNED_INT3);
geometry["vertex_buffer"]->setBuffer(buffers.positions);
geometry["normal_buffer"]->setBuffer(buffers.normals);
geometry["texcoord_buffer"]->setBuffer(buffers.texcoords);
geometry["tangent_buffer"]->setBuffer(buffers.tangents);
geometry["index_buffer"]->setBuffer(buffers.tri_indices);
//geometry["mat_index_buffer"]->setBuffer(buffers.mat_indices);
geometry->setAttributeProgram(optix_mesh.attributes);
//Materials: TODO: per face
geometry->setMaterialCount(optix_materials.size());
geometry->setMaterialIndices(buffers.mat_indices, 0, 0, RT_FORMAT_UNSIGNED_INT);
//optix::GeometryTriangles geometry = optix_mesh.context->createGeometryTriangles();
//geometry->setPrimitiveCount(mesh.num_triangles);
//geometry->setVertices(static_cast<unsigned int>(mrf_mesh.vertices().size()), buffers.positions, RT_FORMAT_FLOAT3);
//geometry->setTriangleIndices(buffers.tri_indices, RT_FORMAT_UNSIGNED_INT3);
//optix::Geometry geometry = optix_mesh.context->createGeometry();
//geometry["vertex_buffer"]->setBuffer(buffers.positions);
//geometry["normal_buffer"]->setBuffer(buffers.normals);
//geometry["texcoord_buffer"]->setBuffer(buffers.texcoords);
//geometry["tangent_buffer"]->setBuffer(buffers.tangents);
//geometry["material_buffer"]->setBuffer(buffers.mat_indices);
//geometry["index_buffer"]->setBuffer(buffers.tri_indices);
//geometry->setPrimitiveCount(mesh.num_triangles);
//geometry->setBoundingBoxProgram(optix_mesh.bounds);
//geometry->setIntersectionProgram(optix_mesh.intersection);
////geometry["mat_index_buffer"]->setBuffer(buffers.mat_indices);
//geometry->setAttributeProgram(optix_mesh.attributes);
////Materials: TODO: per face
//geometry->setMaterialCount(optix_materials.size());
//geometry->setMaterialIndices(buffers.mat_indices, 0, 0, RT_FORMAT_UNSIGNED_INT);
////optix::Geometry geometry = optix_mesh.context->createGeometry();
////geometry["vertex_buffer"]->setBuffer(buffers.positions);
////geometry["normal_buffer"]->setBuffer(buffers.normals);
////geometry["texcoord_buffer"]->setBuffer(buffers.texcoords);
////geometry["tangent_buffer"]->setBuffer(buffers.tangents);
////geometry["material_buffer"]->setBuffer(buffers.mat_indices);
////geometry["index_buffer"]->setBuffer(buffers.tri_indices);
////geometry->setPrimitiveCount(mesh.num_triangles);
////geometry->setBoundingBoxProgram(optix_mesh.bounds);
////geometry->setIntersectionProgram(optix_mesh.intersection);
optix_mesh.geom_instance
= optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end());
//optix_mesh.geom_instance
// = optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end());
//
//unmap(buffers, mesh);
buffers.tri_indices->unmap();
......
......@@ -232,12 +232,12 @@ void OptixLightHandler::updateLights(OptixMaterialHandler &material_handler)
_optix_quad_lights[i].emission
= light_color; //Putting a value here for spectral rendering with one wavelength (no multiplexing)
material_handler.setCustomRadianceVariables(
_optix_quad_light_geometries[i],
_optix_quad_light_materials[i],
variable_values,
variable_names,
wavelengths);
//material_handler.setCustomRadianceVariables(
// _optix_quad_light_geometries[i],
// _optix_quad_light_materials[i],
// variable_values,
// variable_names,
// wavelengths);
#else
auto light_color = diffuse_emittance->getColor() * radiance;
/* material_handler.setCustomRadianceVariables(
......@@ -328,12 +328,12 @@ void OptixLightHandler::updateLights(OptixMaterialHandler &material_handler)
_optix_sphere_lights[i].emission
= light_color; //Putting a value here for spectral rendering with one wavelength (no multiplexing)
material_handler.setCustomRadianceVariables(
_optix_sphere_light_geometries[i],
_optix_sphere_light_materials[i],
variable_values,
variable_names,
wavelengths);
//material_handler.setCustomRadianceVariables(
// _optix_sphere_light_geometries[i],
// _optix_sphere_light_materials[i],
// variable_values,
// variable_names,
// wavelengths);
#else
auto light_color = diffuse_emittance->getColor() * radiance;
//material_handler.setCustomRadianceVariables(_optix_sphere_light_geometries[i], variable_values, variable_names);
......
......@@ -42,7 +42,11 @@ public:
mrf::gui::fb::Loger const & loger);
~OptixMaterialHandler();
void releaseMemory();
#ifdef MRF_RENDERING_MODE_SPECTRAL
void createMaterials(std::vector<std::string> const &cuda_compile_options, std::vector<uint> wavelengths);
#else
void createMaterials(std::vector<std::string> const &cuda_compile_options);
#endif
//optix::Material getMaterialFromMRF(unsigned int index);
std::vector<optix::Material> getMaterialFromMRF(unsigned int index) const;
......@@ -50,7 +54,15 @@ public:
optix::Material getMaterialFromUMat(mrf::materials::UMat *material) const { return _materials.at(material); }
//optix::Material & getMaterialFromUMat(mrf::materials::UMat *material) { return _materials.at(material); }
optix::Material createMaterialFromMRF(mrf::materials::UMat *material, std::vector<std::string> const &cuda_compile_options);
#ifdef MRF_RENDERING_MODE_SPECTRAL
optix::Material createMaterialFromMRF(
mrf::materials::UMat * material,
std::vector<std::string> const &cuda_compile_options,
std::vector<uint> wavelengths);
#else
optix::Material
createMaterialFromMRF(mrf::materials::UMat *material, std::vector<std::string> const &cuda_compile_options);
#endif
void compileBRDF(optix::Material &mat, std::vector<std::string> const &cuda_compile_options);
void compileBTDF(optix::Material &mat, std::vector<std::string> const &cuda_compile_options);
......
......@@ -930,7 +930,12 @@ void OptixRenderer::importMrfScene(std::string scene_file, std::string camera_fi
//then cuda compile options are ok, we create the materials
#ifdef MRF_RENDERING_MODE_SPECTRAL
_material_handler->createMaterials(_cuda_compile_options, _wavelengths);
#else
_material_handler->createMaterials(_cuda_compile_options);
#endif
//then the lights
_light_handler->createLights();
......
......@@ -43,7 +43,7 @@ rtBuffer<float3> normal_buffer;
rtBuffer<float2> texcoord_buffer;
rtBuffer<float3> tangent_buffer;
rtBuffer<int3> index_buffer;
rtBuffer<int> material_buffer;
rtBuffer<uint> material_buffer;
rtDeclareVariable(float3, tangent, attribute tangent, );
rtDeclareVariable(float3, texcoord, attribute texcoord, );
......@@ -108,7 +108,7 @@ static __device__ void meshIntersect(int primIdx)
float3 t2 = tangent_buffer[v_idx.z];
tangent = normalize(t1 * beta + t2 * gamma + t0 * (1.0f - beta - gamma));
}
if (DO_REFINE)
{
refine_and_offset_hitpoint(
......
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