Skip to content

Commit

Permalink
embree: render pointcloud hit param
Browse files Browse the repository at this point in the history
  • Loading branch information
larc committed Mar 21, 2024
1 parent f66b611 commit c3b269f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions include/gproshan/raytracing/embree.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class embree : public raytracing
AREA,
MEDIAN_PAIRS
};

struct pc_opts
{
bool enable = false;
Expand All @@ -33,8 +34,7 @@ class embree : public raytracing
float scale = 1;
int knn = 8;


pc_opts() {};
pc_opts() {}
};

protected:
Expand All @@ -57,6 +57,7 @@ class embree : public raytracing
RTCScene rtc_scene;

std::vector<const che *> g_meshes;
std::vector<bool> is_pointcloud;
scene_data sc;

public:
Expand Down
20 changes: 10 additions & 10 deletions include/gproshan/raytracing/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ struct t_eval_hit
t_eval_hit() {}

__host_device__
t_eval_hit(const che & mesh, const index_t aprimID, const T au, const T av, const scene_data & sc)
t_eval_hit(const che & mesh, const index_t aprimID, const T au, const T av, const scene_data & sc, const bool pointcloud = false)
{
primID = aprimID;
u = au;
v = av;

if(!mesh.n_trigs) // pointcloud
if(pointcloud || !mesh.n_trigs) // pointcloud
{
Kd = mesh.color(primID);
normal = mesh.normal(primID);
Expand All @@ -107,18 +107,18 @@ struct t_eval_hit

const uvec3 trig = mesh.trig(primID);

const vec<T, 3> ca = mesh.color(trig.x());
const vec<T, 3> cb = mesh.color(trig.y());
const vec<T, 3> cc = mesh.color(trig.z());

Kd = (1.f - u - v) * ca + u * cb + v * cc;
Kd = (1.f - u - v) * mesh.color(trig.x())
+ u * mesh.color(trig.y())
+ v * mesh.color(trig.z());
normal = (1.f - u - v) * mesh.normal(trig.x())
+ u * mesh.normal(trig.y())
+ v * mesh.normal(trig.z());
heatmap = (1.f - u - v) * mesh.heatmap(trig.x())
+ u * mesh.heatmap(trig.y())
+ v * mesh.heatmap(trig.z());

normal = normalize(normal);

if(!sc.trig_mat) return;
if(sc.trig_mat[primID] == NIL) return;

Expand Down Expand Up @@ -209,7 +209,7 @@ template <class T, class Occluded>
__host_device__
vec<T, 3> eval_li(const t_eval_hit<T> & hit, const light & ambient, const light * lights, const int n_lights, const vec<T, 3> & eye, Occluded occluded)
{
const vec<T, 3> & v = normalize(eye - hit.position);
const vec<T, 3> v = normalize(eye - hit.position);
const vec<T, 3> & n = hit.normal;

T lambertian;
Expand All @@ -234,8 +234,8 @@ vec<T, 3> eval_li(const t_eval_hit<T> & hit, const light & ambient, const light
specular = powf(std::max(dot(h, n), 0.f), hit.Ns);
#endif // __CUDACC__

const vec<T, 3> & color = hit.Ka * ambient.color * ambient.power +
(lambertian * hit.Kd + specular * hit.Ks) * L.color * L.power / (r * r);
const vec<T, 3> color = hit.Ka * ambient.color * ambient.power +
(lambertian * hit.Kd + specular * hit.Ks) * L.color * L.power / (r * r);

li += (dot(v, n) < 0 || occluded(hit.position, l, r) ? 0.4f : 1.0f) * color;
}
Expand Down
13 changes: 9 additions & 4 deletions src/gproshan/raytracing/embree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,18 @@ vec4 * embree::pc_data(const index_t geomID)
void embree::build_bvh(const std::vector<const che *> & meshes, const std::vector<mat4> & model_mats, const pc_opts & pc)
{
g_meshes.resize(size(meshes));
is_pointcloud.assign(size(meshes), 0);

for(index_t i = 0; i < size(meshes); ++i)
{
g_meshes[i] = meshes[i];
const che * mesh = meshes[i];

g_meshes[i] = mesh;
is_pointcloud[i] = pc.enable || !mesh->n_trigs;

[[maybe_unused]]
const index_t geomID = pc.enable ? add_pointcloud(meshes[i], model_mats[i], pc)
: add_mesh(meshes[i], model_mats[i]);
const index_t geomID = is_pointcloud[i] ? add_pointcloud(meshes[i], model_mats[i], pc)
: add_mesh(meshes[i], model_mats[i]);

gproshan_debug_var(i == geomID);
}
Expand Down Expand Up @@ -279,7 +284,7 @@ bool embree::closesthit_radiance( vertex & color,

const che & mesh = *g_meshes[r.hit.geomID];

eval_hit hit(mesh, r.hit.primID, r.hit.u, r.hit.v, sc);
eval_hit hit(mesh, r.hit.primID, r.hit.u, r.hit.v, sc, is_pointcloud[r.hit.geomID]);
hit.position = r.pos();
hit.normal = flat ? r.normal() : hit.normal;

Expand Down

0 comments on commit c3b269f

Please sign in to comment.