Skip to content

Commit

Permalink
Implement new sdfgrid shape (OptiX only)
Browse files Browse the repository at this point in the history
  • Loading branch information
njroussel committed Jul 28, 2023
1 parent dc0c179 commit 272a5bf
Show file tree
Hide file tree
Showing 17 changed files with 3,532 additions and 82 deletions.
26 changes: 26 additions & 0 deletions include/mitsuba/python/docstr.h
Expand Up @@ -6196,6 +6196,32 @@ static const char *__doc_mitsuba_Resampler_target_resolution = R"doc(Return the

static const char *__doc_mitsuba_Resampler_to_string = R"doc(Return a human-readable summary)doc";

static const char *__doc_mitsuba_SDF = R"doc()doc";

static const char *__doc_mitsuba_SDF_2 = R"doc()doc";

static const char *__doc_mitsuba_SDF_3 = R"doc()doc";

static const char *__doc_mitsuba_SDF_4 = R"doc()doc";

static const char *__doc_mitsuba_SDF_SDF = R"doc()doc";

static const char *__doc_mitsuba_SDF_SDF_2 = R"doc()doc";

static const char *__doc_mitsuba_SDF_bbox = R"doc()doc";

static const char *__doc_mitsuba_SDF_class = R"doc()doc";

static const char *__doc_mitsuba_SDF_parameters_changed = R"doc()doc";

static const char *__doc_mitsuba_SDF_smooth = R"doc()doc";

static const char *__doc_mitsuba_SDF_smooth_hessian = R"doc()doc";

static const char *__doc_mitsuba_SDF_smooth_sh = R"doc(//! @{ \name Accessors (normals, hessians, normals, etc))doc";

static const char *__doc_mitsuba_SDF_traverse = R"doc(@})doc";

static const char *__doc_mitsuba_Sampler =
R"doc(Base class of all sample generators.
Expand Down
3 changes: 3 additions & 0 deletions include/mitsuba/render/fwd.h
Expand Up @@ -23,6 +23,7 @@ template <typename Float, typename Spectrum> class MicrofacetDistribution;
template <typename Float, typename Spectrum> class ReconstructionFilter;
template <typename Float, typename Spectrum> class Sampler;
template <typename Float, typename Spectrum> class Scene;
template <typename Float, typename Spectrum> class SDF;
template <typename Float, typename Spectrum> class Sensor;
template <typename Float, typename Spectrum> class PhaseFunction;
template <typename Float, typename Spectrum> class ProjectiveCamera;
Expand Down Expand Up @@ -77,6 +78,7 @@ template <typename Float_, typename Spectrum_> struct RenderAliases {
using ShapeGroup = mitsuba::ShapeGroup<FloatU, SpectrumU>;
using ShapeKDTree = mitsuba::ShapeKDTree<FloatU, SpectrumU>;
using Mesh = mitsuba::Mesh<FloatU, SpectrumU>;
using SDF = mitsuba::SDF<FloatU, SpectrumU>;
using Integrator = mitsuba::Integrator<FloatU, SpectrumU>;
using SamplingIntegrator = mitsuba::SamplingIntegrator<FloatU, SpectrumU>;
using MonteCarloIntegrator = mitsuba::MonteCarloIntegrator<FloatU, SpectrumU>;
Expand Down Expand Up @@ -164,6 +166,7 @@ template <typename Float_, typename Spectrum_> struct RenderAliases {
using Shape = typename RenderAliases::Shape; \
using ShapeKDTree = typename RenderAliases::ShapeKDTree; \
using Mesh = typename RenderAliases::Mesh; \
using SDF = typename RenderAliases::SDF; \
using Integrator = typename RenderAliases::Integrator; \
using SamplingIntegrator = typename RenderAliases::SamplingIntegrator; \
using MonteCarloIntegrator = typename RenderAliases::MonteCarloIntegrator; \
Expand Down
2 changes: 1 addition & 1 deletion include/mitsuba/render/optix/math.cuh
Expand Up @@ -42,4 +42,4 @@ DEVICE bool solve_quadratic(float a, float b, float c, float& x0, float&x1) {

return true;
}
#endif
#endif
10 changes: 5 additions & 5 deletions include/mitsuba/render/optix/matrix.cuh
Expand Up @@ -141,30 +141,30 @@ struct Transform4f {
inverse_transpose[3][3] = 1.f;
}

DEVICE Vector3f transform_point(const Vector3f &p) {
DEVICE Vector3f transform_point(const Vector3f &p) const {
Vector4f result = matrix[3];
for (size_t i = 0; i < 3; ++i)
result = fmaf(p[i], matrix[i], result);
return Vector3f(result.x(), result.y(), result.z());
}

DEVICE Vector3f transform_normal(const Vector3f &n) {
DEVICE Vector3f transform_normal(const Vector3f &n) const {
Vector4f result = inverse_transpose[0];
result *= n.x();
for (size_t i = 1; i < 3; ++i)
result = fmaf(n[i], inverse_transpose[i], result);
return Vector3f(result.x(), result.y(), result.z());
}

DEVICE Vector3f transform_vector(const Vector3f &v) {
DEVICE Vector3f transform_vector(const Vector3f &v) const {
Vector4f result = matrix[0];
result *= v.x();
for (size_t i = 1; i < 3; ++i)
result = fmaf(v[i], matrix[i], result);
return Vector3f(result.x(), result.y(), result.z());
}

DEVICE Ray3f transform_ray(const Ray3f &ray) {
DEVICE Ray3f transform_ray(const Ray3f &ray) const {
return Ray3f(transform_point(ray.o), transform_vector(ray.d),
ray.maxt, ray.time);
}
Expand All @@ -178,4 +178,4 @@ struct Transform4f {
}
#endif
};
} // end namespace optix
} // end namespace optix
2 changes: 1 addition & 1 deletion include/mitsuba/render/optix/ray.cuh
Expand Up @@ -36,4 +36,4 @@ DEVICE Ray3f get_ray() {
return ray;
}
} // end namespace optix
#endif // defined __CUDACC__
#endif // defined __CUDACC__
22 changes: 19 additions & 3 deletions include/mitsuba/render/optix/shapes.h
Expand Up @@ -7,6 +7,7 @@
#include "disk.cuh"
#include "mesh.cuh"
#include "rectangle.cuh"
#include "sdfgrid.cuh"
#include "sphere.cuh"
#include "bsplinecurve.cuh"
#include "linearcurve.cuh"
Expand All @@ -24,10 +25,23 @@ NAMESPACE_BEGIN(mitsuba)

/// Mitsuba shapes types supported by OptiX (meshes not included)
enum OptixShapeType {
BSplineCurve, LinearCurve, Disk, Rectangle, Sphere, Cylinder, NumOptixShapeTypes
BSplineCurve,
LinearCurve,
Disk,
Rectangle,
Sphere,
Cylinder,
SDFGrid,
NumOptixShapeTypes
};
static std::string OPTIX_SHAPE_TYPE_NAMES[NumOptixShapeTypes] = {
"BSplineCurve", "LinearCurve", "Disk", "Rectangle", "Sphere", "Cylinder"
"BSplineCurve",
"LinearCurve",
"Disk",
"Rectangle",
"Sphere",
"Cylinder",
"SDFGrid"
};
static std::unordered_map<std::string, size_t> OPTIX_SHAPE_TYPE_INDEX = [](){
std::unordered_map<std::string, size_t> out;
Expand All @@ -39,11 +53,13 @@ static std::unordered_map<std::string, size_t> OPTIX_SHAPE_TYPE_INDEX = [](){

/// Defines the ordering of the shapes for OptiX (hitgroups, SBT)
static OptixShapeType OPTIX_SHAPE_ORDER[] = {
BSplineCurve, LinearCurve, Disk, Rectangle, Sphere, Cylinder
BSplineCurve, LinearCurve, Disk, Rectangle, Sphere, Cylinder, SDFGrid
};

static constexpr size_t OPTIX_SHAPE_TYPE_COUNT = std::size(OPTIX_SHAPE_ORDER);

static_assert(OPTIX_SHAPE_TYPE_COUNT == NumOptixShapeTypes);

struct OptixShape {
std::string name; /// Lowercase version of OPTIX_SHAPE_TYPE_NAMES
bool is_builtin; /// Whether or not this is a built-in OptiX shape type
Expand Down
55 changes: 55 additions & 0 deletions include/mitsuba/render/sdf.h
@@ -0,0 +1,55 @@
#pragma once

#include <mitsuba/render/shape.h>
#include <mitsuba/core/properties.h>

NAMESPACE_BEGIN(mitsuba)

template <typename Float, typename Spectrum>
class MI_EXPORT_LIB SDF : public Shape<Float, Spectrum> {
public:
MI_IMPORT_TYPES()
MI_IMPORT_BASE(Shape)

using typename Base::ScalarSize;

// =========================================================================
//! @{ \name Accessors (normals, hessians, normals, etc)
// =========================================================================
//

virtual Normal3f smooth_sh(const Point3f & /*p*/,
const Float * /*u_ptr*/ = nullptr,
const Float * /*u_ptr*/ = nullptr,
const Float * /*w_ptr*/ = nullptr) const {
return Normal3f(0.f);
};

virtual Normal3f smooth(const Point3f & /*p*/) const {
return Normal3f(0.f);
}

virtual Matrix3f smooth_hessian(const Point3f & /*p*/) const {
return Matrix3f(0.f);
}

virtual ScalarBoundingBox3f bbox() const override {
return ScalarBoundingBox3f(0.f);
}

/// @}
// =========================================================================

void traverse(TraversalCallback *callback) override;
void parameters_changed(const std::vector<std::string> &/*keys*/ = {}) override;

protected:
SDF(const Properties &);
inline SDF() {}
virtual ~SDF();

MI_DECLARE_CLASS()
};

MI_EXTERN_CLASS(SDF)
NAMESPACE_END(mitsuba)

0 comments on commit 272a5bf

Please sign in to comment.