34 #include <mesh_utils.h> 61 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
64 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
65 VPL(
const uint32 _prim_id,
const float2 _uv,
const float _e)
67 VertexGeometryId::prim_id = _prim_id;
68 VertexGeometryId::uv = _uv;
74 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
75 static float pdf(
const float4 E) {
return cugar::max3(fabsf(E.x), fabsf(E.y), fabsf(E.z)); }
90 #if !defined(OPTIX_COMPILATION) 92 Light() : type(LightType::kPoint) {}
99 Light(LightType _type) : type(_type) {}
148 void intersect(
const Ray ray, float2* uv,
float* t)
const;
184 #if !defined(OPTIX_COMPILATION) 203 map_impl(*prim_id, *uv, geom, pdf, edf);
223 geom->position = pos +
224 u * disk.x * radius +
227 geom->normal_g = geom->normal_s = cugar::normalize(dir);
228 geom->tangent = cugar::orthogonal(geom->normal_g);
229 geom->binormal = cugar::cross(geom->normal_g, geom->tangent);
231 *pdf = 1.0f / (M_PIf * radius*radius);
241 *pdf = 1.0f / (M_PIf * radius*radius);
254 #if !defined(OPTIX_COMPILATION) 285 const float FAR = 1.0e8f;
287 geom->position = p - dir * FAR;
288 geom->normal_s = geom->normal_g = dir;
289 geom->tangent = cugar::orthogonal(dir);
290 geom->binormal = cugar::cross(dir,geom->tangent);
292 *edf =
Edf( FAR*FAR * color );
301 #if !defined(OPTIX_COMPILATION) 310 MeshLight(
const uint32 _n_prims,
const float* _prims_cdf,
const float* _prims_inv_area,
MeshView _mesh,
const MipMapView* _textures,
const uint32 _n_vpls,
const float* _vpls_cdf,
const VPL* _vpls,
const float _norm) :
311 Light(LightType::kMesh), n_prims(_n_prims), prims_cdf(_prims_cdf), prims_inv_area(_prims_inv_area), mesh(_mesh), textures(_textures), n_vpls(_n_vpls), vpls_cdf(_vpls_cdf), vpls(_vpls), norm(_norm) {}
329 const uint32 l = cugar::min( uint32(Z[2] *
float(n_vpls)), n_vpls-1 );
330 *prim_id = vpls[l].prim_id;
333 map_impl(*prim_id, *uv, geom, pdf, edf);
339 FERMAT_ASSERT(tri_id < n_prims);
345 if (uv->x + uv->y > 1.0f)
347 uv->x = 1.0f - uv->x;
348 uv->y = 1.0f - uv->y;
351 map_impl(*prim_id, *uv, geom, pdf, edf);
376 if (n_vpls || n_prims)
378 FERMAT_ASSERT(prim_id < uint32(mesh.num_triangles));
381 const int material_id = mesh.material_indices[prim_id];
384 material.emissive =
cugar::Vector4f(material.emissive) * texture_lookup(geom->texture_coords, material.emissive_map, textures,
cugar::Vector4f(1.0f));
387 *pdf = VPL::pdf(material.emissive) / norm;
389 *pdf = (prims_cdf[prim_id] - (prim_id ? prims_cdf[prim_id-1] : 0)) * prims_inv_area[prim_id];
391 *edf =
Edf(material);
411 if (n_vpls || n_prims)
413 FERMAT_ASSERT(prim_id < uint32(mesh.num_triangles));
414 const int material_id = mesh.material_indices[prim_id];
417 material.emissive =
cugar::Vector4f(material.emissive) * texture_lookup(geom.texture_coords, material.emissive_map, textures,
cugar::Vector4f(1.0f));
420 *pdf = VPL::pdf(material.emissive) / norm;
422 *pdf = (prims_cdf[prim_id] - (prim_id ? prims_cdf[prim_id - 1] : 0)) * prims_inv_area[prim_id];
424 *edf =
Edf(material);
440 FERMAT_ASSERT(prim_id < uint32(mesh.num_triangles));
441 const float cdf_1 = prim_id ? prims_cdf[prim_id - 1] : 0;
442 const float cdf_2 = prims_cdf[prim_id];
443 const float cdf_delta = cdf_2 - cdf_1;
447 out_Z[2] = in_Z[0] * cdf_delta + cdf_1;
449 *out_pdf =
prim_area(mesh, prim_id) / cdf_delta;
452 return cdf_delta > 0.0f;
456 out_Z[0] = out_Z[1] = out_Z[2] = 0.5f;
469 FERMAT_ASSERT(prim_id < uint32(mesh.num_triangles));
470 const float cdf_1 = prim_id ? prims_cdf[prim_id - 1] : 0;
471 const float cdf_2 = prims_cdf[prim_id];
472 const float cdf_delta = cdf_2 - cdf_1;
475 return prim_area(mesh, prim_id) / cdf_delta;
483 uint32 vpl_count()
const {
return n_vpls; }
486 VPL get_vpl(
const uint32 i)
const {
return vpls[i]; }
492 const uint32 vpl_idx,
500 *prim_id = vpls[vpl_idx].prim_id;
501 *uv = vpls[vpl_idx].uv;
503 map_impl(*prim_id, *uv, geom, pdf, edf);
507 const float* prims_cdf;
508 const float* prims_inv_area;
512 const float* vpls_cdf;
531 case LightType::kDisk:
532 return reinterpret_cast<const DiskLight*
>(
this)->sample_impl( Z, prim_id, uv, geom, pdf, edf );
533 case LightType::kMesh:
534 return reinterpret_cast<const MeshLight*
>(
this)->sample_impl( Z, prim_id, uv, geom, pdf, edf );
535 case LightType::kDirectional:
536 return reinterpret_cast<const DirectionalLight*
>(
this)->sample_impl( Z, prim_id, uv, geom, pdf, edf );
555 case LightType::kDisk:
556 return reinterpret_cast<const DiskLight*
>(
this)->sample_impl( Z, prim_id, uv, geom, pdf, edf );
557 case LightType::kMesh:
558 return reinterpret_cast<const MeshLight*
>(
this)->sample_impl( Z, prim_id, uv, geom, pdf, edf );
559 case LightType::kDirectional:
560 return reinterpret_cast<const DirectionalLight*
>(
this)->sample_impl( p, Z, prim_id, uv, geom, pdf, edf );
572 case LightType::kDisk:
573 reinterpret_cast<const DiskLight*
>(
this)->intersect_impl( ray, uv, t );
575 case LightType::kMesh:
576 reinterpret_cast<const MeshLight*
>(
this)->intersect_impl(ray, uv, t);
588 case LightType::kDisk:
589 reinterpret_cast<const DiskLight*
>(
this)->map_impl( prim_id, uv, geom, pdf, edf );
591 case LightType::kMesh:
592 reinterpret_cast<const MeshLight*
>(
this)->map_impl( prim_id, uv, geom, pdf, edf );
604 case LightType::kDisk:
605 reinterpret_cast<const DiskLight*
>(
this)->map_impl(prim_id, uv, geom, pdf, edf);
607 case LightType::kMesh:
608 reinterpret_cast<const MeshLight*
>(
this)->map_impl(prim_id, uv, geom, pdf, edf);
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE index_type upper_bound_index(const Value x, Iterator begin, const index_type n)
Definition: algorithms.h:193
FERMAT_HOST_DEVICE void map_impl(const uint32_t prim_id, const cugar::Vector2f &uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:219
FERMAT_HOST_DEVICE bool sample_impl(const float *Z, uint32_t *prim_id, cugar::Vector2f *uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:261
FERMAT_HOST_DEVICE float prim_area(const MeshView &mesh, const uint32 tri_id)
Definition: mesh_utils.h:168
FERMAT_HOST_DEVICE void intersect_impl(const Ray ray, float2 *uv, float *t) const
Definition: lights.h:210
FERMAT_HOST_DEVICE bool sample_impl(const float *Z, uint32_t *prim_id, cugar::Vector2f *uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:316
FERMAT_HOST_DEVICE void map(const uint32_t prim_id, const cugar::Vector2f &uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:584
FERMAT_HOST_DEVICE bool sample_impl(const float *Z, uint32_t *prim_id, cugar::Vector2f *uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:191
Defines various spherical mappings.
Definition: MeshView.h:55
FERMAT_HOST_DEVICE void setup_differential_geometry(const MeshView &mesh, const uint32 tri_id, const float u, const float v, VertexGeometry *geom, float *pdf=0)
Definition: mesh_utils.h:185
Defines some general purpose algorithms.
FERMAT_HOST_DEVICE void map_impl(const uint32_t prim_id, const cugar::Vector2f &uv, const VertexGeometry &geom, float *pdf, Edf *edf) const
Definition: lights.h:239
Definition: MeshView.h:96
CUGAR_HOST CUGAR_DEVICE Vector2f square_to_unit_disk(const Vector2f uv)
Definition: mappings_inline.h:56
FERMAT_HOST_DEVICE float inverse_pdf_impl(const uint32_t prim_id, const cugar::Vector2f &uv, const float *out_Z) const
Definition: lights.h:465
FERMAT_HOST_DEVICE void intersect_impl(const Ray ray, float2 *uv, float *t) const
Definition: lights.h:366
FERMAT_HOST_DEVICE bool invert_impl(const uint32_t prim_id, const cugar::Vector2f &uv, const float *in_Z, float *out_Z, float *out_pdf) const
Definition: lights.h:436
FERMAT_HOST_DEVICE void intersect(const Ray ray, float2 *uv, float *t) const
Definition: lights.h:568
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Out binary_cast(const In in)
Definition: types.h:288
FERMAT_HOST_DEVICE bool sample(const float *Z, uint32_t *prim_id, cugar::Vector2f *uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:521
Definition: texture_view.h:73
FERMAT_HOST_DEVICE void map_impl(const uint32_t prim_id, const cugar::Vector2f &uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:374
FERMAT_HOST_DEVICE void map_vpl(const uint32 vpl_idx, uint32_t *prim_id, cugar::Vector2f *uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:491
FERMAT_HOST_DEVICE void map_impl(const uint32_t prim_id, const cugar::Vector2f &uv, const VertexGeometry &geom, float *pdf, Edf *edf) const
Definition: lights.h:409
FERMAT_HOST_DEVICE bool sample_impl(const cugar::Vector3f p, const float *Z, uint32_t *prim_id, cugar::Vector2f *uv, VertexGeometry *geom, float *pdf, Edf *edf) const
Definition: lights.h:276