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

debugging mesh

parent 7a519aaa
......@@ -324,15 +324,14 @@ void OptixGeometryHandler::loadMeshFromMRF(
if (optix_materials.size() == 1)
{
// 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);
}
else
{
memcpy(
mesh.mat_indices,
&mrf_mesh.materialPerFaces()[0],
mrf_mesh.materialPerFaces().size() * sizeof(unsigned int));
&mrf_mesh.materialPerFaces()[0], mrf_mesh.materialPerFaces().size() * sizeof(uint32_t));
}
......@@ -346,6 +345,7 @@ void OptixGeometryHandler::loadMeshFromMRF(
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);
......@@ -368,6 +368,7 @@ void OptixGeometryHandler::loadMeshFromMRF(
optix_mesh.geom_instance
= optix_mesh.context->createGeometryInstance(geometry, optix_materials.begin(), optix_materials.end());
//unmap(buffers, mesh);
buffers.tri_indices->unmap();
buffers.mat_indices->unmap();
......@@ -392,7 +393,7 @@ void OptixGeometryHandler::loadMeshFromMRF(
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.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.normals = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, mesh.has_normals ? mesh.num_vertices : 0);
buffers.texcoords
......@@ -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);
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.normals = reinterpret_cast<float *>(mesh.has_normals ? buffers.normals->map() : 0);
mesh.texcoords = reinterpret_cast<float *>(mesh.has_texcoords ? buffers.texcoords->map() : 0);
......
......@@ -96,7 +96,7 @@ struct MRF_OPTIX_EXPORT Mesh
int32_t num_triangles; // Number of triangles
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_max[3]; //
......
......@@ -944,7 +944,7 @@ void OptixMaterialHandler::applyMaterial(/*OptiXMesh &optix_mesh,*/
geom_instance["_thickness"]->setFloat(0.f);
geom_instance["repeat"]->setFloat(0.f);
geom_instance->setMaterial(0, _lambert);
geom_instance->setMaterial(i, _lambert);
continue;
}
......
......@@ -47,6 +47,7 @@ rtBuffer<float3> normal_buffer;
rtBuffer<float2> texcoord_buffer;
rtBuffer<float3> tangent_buffer;
rtBuffer<int3> index_buffer;
rtBuffer<uint> mat_index_buffer;
rtDeclareVariable(float3, tangent, attribute tangent, );
rtDeclareVariable(float3, bitangent, attribute bitangent, );
......@@ -57,6 +58,8 @@ rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, );
rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, );
// rtDeclareVariable(uint, mat_index, attribute mat_index, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
// template<bool DO_REFINE>
......@@ -88,6 +91,15 @@ RT_PROGRAM void triangle_attributes()
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)
{
texcoord = make_float3(0.0f, 0.0f, 0.0f);
......
......@@ -25,6 +25,7 @@ rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, );
rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, );
rtDeclareVariable(PerRayData_pathtrace, current_prd, rtPayload, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
rtDeclareVariable(float, t_hit, rtIntersectionDistance, );
......@@ -228,6 +229,9 @@ RT_PROGRAM void material_eval()
}
float3 hitpoint = ray.origin + t_hit * ray.direction;
float3 ffnormal = get_normal(shading_normal, true);
......
......@@ -29,6 +29,9 @@ rtDeclareVariable(PerRayData_pathtrace, current_prd, rtPayload, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
rtDeclareVariable(float, t_hit, rtIntersectionDistance, );
// rtDeclareVariable(uint, mat_index, attribute mat_index, );
rtBuffer<QuadLight> lights;
rtBuffer<SphereLight> sphere_lights;
rtBuffer<DirectionnalLight> directionnal_lights;
......@@ -119,6 +122,42 @@ RT_PROGRAM void material_eval()
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 ffnormal = get_normal(shading_normal, true);
......
......@@ -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);
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);
for (size_t face_idx = 0; face_idx < enforced_materials.size(); face_idx++)
......
......@@ -162,10 +162,15 @@ public:
}
inline ProgArg const &option(std::string const &option_name) const
{
if (hasOption(option_name))
{
auto it = _arguments.find(option_name);
return it->second;
}
else
return ProgArg();
}
inline std::map<std::string, ProgArg> const &options() const { return _arguments; }
......
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