Commit 58068c86 authored by MURRAY David's avatar MURRAY David
Browse files

debugging mesh

parent 7a519aaa
...@@ -324,15 +324,14 @@ void OptixGeometryHandler::loadMeshFromMRF( ...@@ -324,15 +324,14 @@ void OptixGeometryHandler::loadMeshFromMRF(
if (optix_materials.size() == 1) if (optix_materials.size() == 1)
{ {
// Rewrite all mat_indices to point to single override material // Rewrite all mat_indices to point to single override material
memset(mesh.mat_indices, 0, mesh.num_triangles * sizeof(int32_t)); memset(mesh.mat_indices, 0, mesh.num_triangles * sizeof(uint32_t));
//optix_materials.push_back(optix_mesh.material); //optix_materials.push_back(optix_mesh.material);
} }
else else
{ {
memcpy( memcpy(
mesh.mat_indices, mesh.mat_indices,
&mrf_mesh.materialPerFaces()[0], &mrf_mesh.materialPerFaces()[0], mrf_mesh.materialPerFaces().size() * sizeof(uint32_t));
mrf_mesh.materialPerFaces().size() * sizeof(unsigned int));
} }
...@@ -346,6 +345,7 @@ void OptixGeometryHandler::loadMeshFromMRF( ...@@ -346,6 +345,7 @@ void OptixGeometryHandler::loadMeshFromMRF(
geometry["texcoord_buffer"]->setBuffer(buffers.texcoords); geometry["texcoord_buffer"]->setBuffer(buffers.texcoords);
geometry["tangent_buffer"]->setBuffer(buffers.tangents); geometry["tangent_buffer"]->setBuffer(buffers.tangents);
geometry["index_buffer"]->setBuffer(buffers.tri_indices); geometry["index_buffer"]->setBuffer(buffers.tri_indices);
//geometry["mat_index_buffer"]->setBuffer(buffers.mat_indices);
geometry->setAttributeProgram(optix_mesh.attributes); geometry->setAttributeProgram(optix_mesh.attributes);
...@@ -367,6 +367,7 @@ void OptixGeometryHandler::loadMeshFromMRF( ...@@ -367,6 +367,7 @@ void OptixGeometryHandler::loadMeshFromMRF(
optix_mesh.geom_instance optix_mesh.geom_instance
= optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end()); = optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end());
//unmap(buffers, mesh); //unmap(buffers, mesh);
buffers.tri_indices->unmap(); buffers.tri_indices->unmap();
...@@ -392,7 +393,7 @@ void OptixGeometryHandler::loadMeshFromMRF( ...@@ -392,7 +393,7 @@ void OptixGeometryHandler::loadMeshFromMRF(
void OptixGeometryHandler::setupMeshLoaderInputs(optix::Context context, OptixMeshBuffers &buffers, Mesh &mesh) void OptixGeometryHandler::setupMeshLoaderInputs(optix::Context context, OptixMeshBuffers &buffers, Mesh &mesh)
{ {
buffers.tri_indices = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_INT3, mesh.num_triangles); buffers.tri_indices = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_INT3, mesh.num_triangles);
buffers.mat_indices = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_INT, mesh.num_triangles); buffers.mat_indices = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_INT, mesh.num_triangles);
buffers.positions = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.num_vertices); buffers.positions = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.num_vertices);
buffers.normals = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.has_normals ? mesh.num_vertices : 0); buffers.normals = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.has_normals ? mesh.num_vertices : 0);
buffers.texcoords buffers.texcoords
...@@ -401,7 +402,7 @@ void OptixGeometryHandler::setupMeshLoaderInputs(optix::Context context, OptixMe ...@@ -401,7 +402,7 @@ void OptixGeometryHandler::setupMeshLoaderInputs(optix::Context context, OptixMe
= context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.has_tangents ? mesh.num_vertices : 0); = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.has_tangents ? mesh.num_vertices : 0);
mesh.tri_indices = reinterpret_cast<int32_t *>(buffers.tri_indices->map()); mesh.tri_indices = reinterpret_cast<int32_t *>(buffers.tri_indices->map());
mesh.mat_indices = reinterpret_cast<int32_t *>(buffers.mat_indices->map()); mesh.mat_indices = reinterpret_cast<uint32_t *>(buffers.mat_indices->map());
mesh.positions = reinterpret_cast<float *>(buffers.positions->map()); mesh.positions = reinterpret_cast<float *>(buffers.positions->map());
mesh.normals = reinterpret_cast<float *>(mesh.has_normals ? buffers.normals->map() : 0); mesh.normals = reinterpret_cast<float *>(mesh.has_normals ? buffers.normals->map() : 0);
mesh.texcoords = reinterpret_cast<float *>(mesh.has_texcoords ? buffers.texcoords->map() : 0); mesh.texcoords = reinterpret_cast<float *>(mesh.has_texcoords ? buffers.texcoords->map() : 0);
......
...@@ -96,7 +96,7 @@ struct MRF_OPTIX_EXPORT Mesh ...@@ -96,7 +96,7 @@ struct MRF_OPTIX_EXPORT Mesh
int32_t num_triangles; // Number of triangles int32_t num_triangles; // Number of triangles
int32_t *tri_indices; // Indices into positions, normals, texcoords int32_t *tri_indices; // Indices into positions, normals, texcoords
int32_t *mat_indices; // Indices into mat_params (len num_triangles) uint32_t *mat_indices; // Indices into mat_params (len num_triangles)
float bbox_min[3]; // Scene BBox float bbox_min[3]; // Scene BBox
float bbox_max[3]; // float bbox_max[3]; //
......
...@@ -944,7 +944,7 @@ void OptixMaterialHandler::applyMaterial(/*OptiXMesh &optix_mesh,*/ ...@@ -944,7 +944,7 @@ void OptixMaterialHandler::applyMaterial(/*OptiXMesh &optix_mesh,*/
geom_instance["_thickness"]->setFloat(0.f); geom_instance["_thickness"]->setFloat(0.f);
geom_instance["repeat"]->setFloat(0.f); geom_instance["repeat"]->setFloat(0.f);
geom_instance->setMaterial(0, _lambert); geom_instance->setMaterial(i, _lambert);
continue; continue;
} }
......
...@@ -47,6 +47,7 @@ rtBuffer<float3> normal_buffer; ...@@ -47,6 +47,7 @@ rtBuffer<float3> normal_buffer;
rtBuffer<float2> texcoord_buffer; rtBuffer<float2> texcoord_buffer;
rtBuffer<float3> tangent_buffer; rtBuffer<float3> tangent_buffer;
rtBuffer<int3> index_buffer; rtBuffer<int3> index_buffer;
rtBuffer<uint> mat_index_buffer;
rtDeclareVariable(float3, tangent, attribute tangent, ); rtDeclareVariable(float3, tangent, attribute tangent, );
rtDeclareVariable(float3, bitangent, attribute bitangent, ); rtDeclareVariable(float3, bitangent, attribute bitangent, );
...@@ -57,6 +58,8 @@ rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); ...@@ -57,6 +58,8 @@ rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, ); rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, );
rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, ); rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, );
// rtDeclareVariable(uint, mat_index, attribute mat_index, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
// template<bool DO_REFINE> // template<bool DO_REFINE>
...@@ -88,6 +91,15 @@ RT_PROGRAM void triangle_attributes() ...@@ -88,6 +91,15 @@ RT_PROGRAM void triangle_attributes()
shading_normal = normalize(n1 * beta + n2 * gamma + n0 * (1.0f - beta - gamma)); shading_normal = normalize(n1 * beta + n2 * gamma + n0 * (1.0f - beta - gamma));
} }
// if (mat_index_buffer.size() == 0)
// {
// mat_index = 0;
// }
// else
// {
// mat_index = mat_index_buffer[rtGetPrimitiveIndex()];
// }
if (texcoord_buffer.size() == 0) if (texcoord_buffer.size() == 0)
{ {
texcoord = make_float3(0.0f, 0.0f, 0.0f); texcoord = make_float3(0.0f, 0.0f, 0.0f);
......
...@@ -25,6 +25,7 @@ rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); ...@@ -25,6 +25,7 @@ rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, ); rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, );
rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, ); rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, );
rtDeclareVariable(PerRayData_pathtrace, current_prd, rtPayload, ); rtDeclareVariable(PerRayData_pathtrace, current_prd, rtPayload, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); rtDeclareVariable(float, t_hit, rtIntersectionDistance, );
...@@ -226,6 +227,9 @@ RT_PROGRAM void material_eval() ...@@ -226,6 +227,9 @@ RT_PROGRAM void material_eval()
current_prd.done = true; current_prd.done = true;
return; return;
} }
float3 hitpoint = ray.origin + t_hit * ray.direction; float3 hitpoint = ray.origin + t_hit * ray.direction;
......
...@@ -29,6 +29,9 @@ rtDeclareVariable(PerRayData_pathtrace, current_prd, rtPayload, ); ...@@ -29,6 +29,9 @@ rtDeclareVariable(PerRayData_pathtrace, current_prd, rtPayload, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); rtDeclareVariable(float, t_hit, rtIntersectionDistance, );
// rtDeclareVariable(uint, mat_index, attribute mat_index, );
rtBuffer<QuadLight> lights; rtBuffer<QuadLight> lights;
rtBuffer<SphereLight> sphere_lights; rtBuffer<SphereLight> sphere_lights;
rtBuffer<DirectionnalLight> directionnal_lights; rtBuffer<DirectionnalLight> directionnal_lights;
...@@ -118,6 +121,42 @@ RT_PROGRAM void material_eval() ...@@ -118,6 +121,42 @@ RT_PROGRAM void material_eval()
current_prd.done = true; current_prd.done = true;
return; return;
} }
// int tmp = mat_index;
// switch(tmp) {
// case 0:
// {
// current_prd.result = make_float3(1.f, 0.f, 0.f);
// break;
// }
// case 1:
// {
// current_prd.result = make_float3(0.f, 1.f, 0.f);
// break;
// }
// case 2:
// {
// current_prd.result = make_float3(0.f, 0.f, 1.f);
// break;
// }
// case 3:
// {
// current_prd.result = make_float3(1.f, 1.f, 0.f);
// break;
// }
// case 4:
// {
// current_prd.result = make_float3(1.f, 0.f, 1.f);
// break;
// }
// case 5:
// {
// current_prd.result = make_float3(0.f, 1.f, 1.f);
// break;
// }
// }
// current_prd.done = true;
// return;
float3 hitpoint = ray.origin + t_hit * ray.direction; float3 hitpoint = ray.origin + t_hit * ray.direction;
......
...@@ -798,7 +798,7 @@ bool SceneParser::parseShapes(mrf::rendering::Scene &scene) ...@@ -798,7 +798,7 @@ bool SceneParser::parseShapes(mrf::rendering::Scene &scene)
for (auto &name : multi_mat->getAllNames()) for (auto &name : multi_mat->getAllNames())
{ {
auto current = _brdf_map.find(name); auto current = _brdf_map.find(name);
auto end = _brdf_map.end(); auto end = _brdf_map.end();
if (current != end) is_mat_used[current->second] = true; if (current != end) is_mat_used[current->second] = true;
} }
} }
...@@ -1077,11 +1077,11 @@ SceneParser::addMesh(XMLElement *a_mesh_element, mrf::rendering::Scene &scene, i ...@@ -1077,11 +1077,11 @@ SceneParser::addMesh(XMLElement *a_mesh_element, mrf::rendering::Scene &scene, i
} }
} }
if (tiny_mat) if (tiny_mat && tiny_mat->t == tinyply::Type::UINT32)
{ {
assert(tiny_mat->count == tiny_faces->count); assert(tiny_mat->count == tiny_faces->count);
const size_t numMatBytes = tiny_mat->buffer.size_bytes(); const size_t numMatBytes = tiny_mat->buffer.size_bytes();
const float *ply_mat = reinterpret_cast<float *>(tiny_mat->buffer.get()); const uint * ply_mat = reinterpret_cast<uint *>(tiny_mat->buffer.get());
enforced_materials.resize(tiny_mat->count); enforced_materials.resize(tiny_mat->count);
for (size_t face_idx = 0; face_idx < enforced_materials.size(); face_idx++) for (size_t face_idx = 0; face_idx < enforced_materials.size(); face_idx++)
...@@ -1549,8 +1549,8 @@ bool SceneParser::addMaterial(XMLElement *a_mat_element, mrf::rendering::Scene & ...@@ -1549,8 +1549,8 @@ bool SceneParser::addMaterial(XMLElement *a_mat_element, mrf::rendering::Scene &
if (type.compare(BRDFTypes::MULTI_MAT) == 0) if (type.compare(BRDFTypes::MULTI_MAT) == 0)
{ {
_loger->trace("Multi-Material Detected, parsing them"); _loger->trace("Multi-Material Detected, parsing them");
unsigned int count; unsigned int count;
int rOk = a_mat_element->QueryUnsignedAttribute(SceneLexer::COUNT_AT, &count); int rOk = a_mat_element->QueryUnsignedAttribute(SceneLexer::COUNT_AT, &count);
MultiMaterial *multimat = new MultiMaterial(name, count); MultiMaterial *multimat = new MultiMaterial(name, count);
parseMultiMaterial(a_mat_element, multimat, scene); parseMultiMaterial(a_mat_element, multimat, scene);
_brdf_map[name] = scene.addMaterial(multimat); _brdf_map[name] = scene.addMaterial(multimat);
......
...@@ -163,8 +163,13 @@ public: ...@@ -163,8 +163,13 @@ public:
inline ProgArg const &option(std::string const &option_name) const inline ProgArg const &option(std::string const &option_name) const
{ {
auto it = _arguments.find(option_name); if (hasOption(option_name))
return it->second; {
auto it = _arguments.find(option_name);
return it->second;
}
else
return ProgArg();
} }
......
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