Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ __pycache__
/docs/src/quickstart
/docs/src/generated
/docs/resources
/volume-tests/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
url = https://github.com/mitsuba-renderer/nanogui
[submodule "resources/data"]
path = resources/data
url = https://github.com/mitsuba-renderer/mitsuba-data
url = https://github.com/Microno95/mitsuba-data-emissive-volume
shallow = true
[submodule "ext/embree"]
path = ext/embree
Expand Down
38 changes: 37 additions & 1 deletion include/mitsuba/core/warp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ NAMESPACE_BEGIN(mitsuba)

/**
* \brief Implements common warping techniques that map from the unit
* square [0, 1]^2 to other domains such as spheres, hemispheres, etc.
* square [0, 1]^2 or unit cube [0, 1]^3 to other domains such as spheres,
* hemispheres, etc.
*
* The main application of this class is to generate uniformly
* distributed or weighted point sets in certain common target domains.
Expand Down Expand Up @@ -275,6 +276,41 @@ MI_INLINE Value square_to_uniform_sphere_pdf(const Vector<Value, 3> &v) {
return dr::InvFourPi<Value>;
}

/// Uniformly sample a vector on the unit sphere with respect to solid angles
template <typename Value>
MI_INLINE Vector<Value, 3> cube_to_uniform_sphere(const Point<Value, 3> &sample) {
Value radius = dr::safe_cbrt(sample.x()),
phi = 2.f * dr::Pi<Value> * sample.z(),
u = dr::fmsub(2.f, sample.y(), 1.f);
radius = dr::select(sample.x() == 0.f, sample.x(), radius);
auto [s, c] = dr::sincos(phi);
return { radius * c * dr::safe_sqrt(1 - dr::square(u)), radius * s * dr::safe_sqrt(1 - dr::square(u)), radius * u };
}

/// Inverse of the mapping \ref square_to_uniform_sphere
template <typename Value>
MI_INLINE Point<Value, 3> uniform_sphere_to_cube(const Vector<Value, 3> &p) {
Value phi = dr::atan2(p.y(), p.x()) * dr::InvTwoPi<Value>,
radius = dr::safe_sqrt(dr::square(p.x()) + dr::square(p.y()) + dr::square(p.z())),
u = (p.z() / radius + 1.f) / 2.f;
return {
dr::square(radius) * radius,
u,
dr::select(phi < 0.f, phi + 1.f, phi),
};
}

/// Density of \ref cube_to_uniform_sphere() with respect to volume
template <bool TestDomain = false, typename Value>
MI_INLINE Value cube_to_uniform_sphere_pdf(const Vector<Value, 3> &v) {
DRJIT_MARK_USED(v);
if constexpr (TestDomain)
return dr::select(dr::abs(dr::squared_norm(v) - 1.f) > math::RayEpsilon<Value>,
0.f, 3.f * dr::InvFourPi<Value>);
else
return 3.f * dr::InvFourPi<Value>;
}

// =======================================================================

/**
Expand Down
170 changes: 159 additions & 11 deletions include/mitsuba/python/docstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,8 @@ static const char *__doc_mitsuba_EmitterFlags_SpatiallyVarying = R"doc(The emiss

static const char *__doc_mitsuba_EmitterFlags_Surface = R"doc(The emitter is attached to a surface (e.g. area emitters))doc";

static const char *__doc_mitsuba_EmitterFlags_Medium = R"doc(The emitter is attached to a medium (e.g. medium emitters))doc";

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

static const char *__doc_mitsuba_Emitter_class = R"doc()doc";
Expand Down Expand Up @@ -2723,6 +2725,8 @@ static const char *__doc_mitsuba_Endpoint_m_needs_sample_2 = R"doc()doc";

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

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

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

static const char *__doc_mitsuba_Endpoint_m_to_world = R"doc()doc";
Expand All @@ -2737,6 +2741,10 @@ static const char *__doc_mitsuba_Endpoint_needs_sample_2 =
R"doc(Does the method sample_ray() require a uniformly distributed 2D sample
for the ``sample2`` parameter?)doc";

static const char *__doc_mitsuba_Endpoint_needs_sample_2_3d =
R"doc(Does the method sample_ray() require a uniformly distributed 3D sample
for the ``sample2`` parameter?)doc";

static const char *__doc_mitsuba_Endpoint_needs_sample_3 =
R"doc(Does the method sample_ray() require a uniformly distributed 2D sample
for the ``sample3`` parameter?)doc";
Expand Down Expand Up @@ -4439,9 +4447,13 @@ static const char *__doc_mitsuba_MediumInteraction_sigma_s = R"doc()doc";

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

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

static const char *__doc_mitsuba_MediumInteraction_to_local =
R"doc(Convert a world-space vector into local shading coordinates (defined
by ``wi``))doc";
static const char *__doc_mitsuba_MediumInteraction_emitter =
R"doc(Return the emitter associated with the intersection (if any))doc";

static const char *__doc_mitsuba_MediumInteraction_to_world =
R"doc(Convert a local shading-space (defined by ``wi``) vector into world
Expand All @@ -4465,6 +4477,24 @@ static const char *__doc_mitsuba_Medium_get_scattering_coefficients =
R"doc(Returns the medium coefficients Sigma_s, Sigma_n and Sigma_t evaluated
at a given MediumInteraction mi)doc";

static const char *__doc_mitsuba_Medium_get_interaction_probabilities =
R"doc(Returns the real scatter event probability, and the
weights of a real and null scattering event at a given MediumInteraction mi)doc";

static const char *__doc_mitsuba_Medium_medium_probabilities_analog =
R"doc(Computes the probabilities of interacting with a medium based on the point-wise
density of each event)doc";

static const char *__doc_mitsuba_Medium_medium_probabilities_max =
R"doc(Computes the probabilities of interacting with a medium based on the maximum
density of each event multiplied by the throughput)doc";

static const char *__doc_mitsuba_Medium_medium_probabilities_mean =
R"doc(Computes the probabilities of interacting with a medium based on the mean
density of each event multiplied by the throughput)doc";

static const char *__doc_mitsuba_Medium_get_radiance = R"doc(Returns the medium's radiance used for emissive media)doc";

static const char *__doc_mitsuba_Medium_has_spectral_extinction = R"doc(Returns whether this medium has a spectrally varying extinction)doc";

static const char *__doc_mitsuba_Medium_id = R"doc(Return a string identifier)doc";
Expand All @@ -4473,6 +4503,8 @@ static const char *__doc_mitsuba_Medium_intersect_aabb = R"doc(Intersects a ray

static const char *__doc_mitsuba_Medium_is_homogeneous = R"doc(Returns whether this medium is homogeneous)doc";

static const char *__doc_mitsuba_Medium_is_emitter = R"doc(Returns whether this medium is an emitter)doc";

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

static const char *__doc_mitsuba_Medium_m_id = R"doc(Identifier (if available))doc";
Expand All @@ -4483,8 +4515,20 @@ static const char *__doc_mitsuba_Medium_m_phase_function = R"doc()doc";

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

static const char *__doc_mitsuba_Medium_m_medium_sampling_mode =
R"doc(Determine how free-flight distances are sampled in the medium

Takes on one of three values --- Analogue, Maximum and Mean --- which
consider the probability of interacting with the medium based on the
point-wise densities of each event, the maximum density of each event
convolved with the throughput of the path, and the mean density of
each event convolved with the throughput of the path.
)doc";

static const char *__doc_mitsuba_Medium_phase_function = R"doc(Return the phase function of this medium)doc";

static const char *__doc_mitsuba_Medium_emitter = R"doc(Return the emitter associated with this medium)doc";

static const char *__doc_mitsuba_Medium_sample_interaction =
R"doc(Sample a free-flight distance in the medium.

Expand Down Expand Up @@ -4531,6 +4575,22 @@ static const char *__doc_mitsuba_Medium_traverse = R"doc()doc";

static const char *__doc_mitsuba_Medium_use_emitter_sampling = R"doc(Returns whether this specific medium instance uses emitter sampling)doc";

static const char *__doc_mitsuba_MediumEventSamplingMode =
R"doc(This flag is used to determine how medium interaction events
should be sampled)doc";

static const char *__doc_mitsuba_MediumEventSamplingMode_Analogue =
R"doc(Uses conventional analogue probabilities that only take into account
the local transmittance coefficient, null scattering coefficient and radiance.)doc";

static const char *__doc_mitsuba_MediumEventSamplingMode_Maximum =
R"doc(Uses the maximum throughput achievable in both real and null
scattering events to determine the interaction probabilities.)doc";

static const char *__doc_mitsuba_MediumEventSamplingMode_Mean =
R"doc(Uses the mean throughput in both real and null
scattering events to determine the interaction probabilities.)doc";

static const char *__doc_mitsuba_MemoryMappedFile =
R"doc(Basic cross-platform abstraction for memory mapped files

Expand Down Expand Up @@ -4887,7 +4947,9 @@ static const char *__doc_mitsuba_Mesh_parameters_changed = R"doc()doc";

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

static const char *__doc_mitsuba_Mesh_pdf_position = R"doc()doc";
static const char *__doc_mitsuba_Mesh_pdf_position_surface = R"doc()doc";

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

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

Expand Down Expand Up @@ -4935,7 +4997,9 @@ Affects both mesh and texture attributes.

Throws an exception if the attribute was not previously registered.)doc";

static const char *__doc_mitsuba_Mesh_sample_position = R"doc()doc";
static const char *__doc_mitsuba_Mesh_sample_position_surface = R"doc()doc";

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

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

Expand Down Expand Up @@ -6749,6 +6813,8 @@ static const char *__doc_mitsuba_Sampler_next_1d = R"doc(Retrieve the next compo

static const char *__doc_mitsuba_Sampler_next_2d = R"doc(Retrieve the next two component values from the current sample)doc";

static const char *__doc_mitsuba_Sampler_next_3d = R"doc(Retrieve the next three component values from the current sample)doc";

static const char *__doc_mitsuba_Sampler_sample_count = R"doc(Return the number of samples per pixel)doc";

static const char *__doc_mitsuba_Sampler_schedule_state = R"doc(dr::schedule() variables that represent the internal sampler state)doc";
Expand Down Expand Up @@ -8041,8 +8107,8 @@ static const char *__doc_mitsuba_Shape_parameters_grad_enabled =
R"doc(Return whether any shape's parameters that introduce visibility
discontinuities require gradients (default return false))doc";

static const char *__doc_mitsuba_Shape_pdf_direction =
R"doc(Query the probability density of sample_direction()
static const char *__doc_mitsuba_Shape_pdf_direction_surface =
R"doc(Query the probability density of sample_direction_surface()

Parameter ``it``:
A reference position somewhere within the scene.
Expand All @@ -8053,8 +8119,20 @@ Parameter ``ps``:
Returns:
The probability density per unit solid angle)doc";

static const char *__doc_mitsuba_Shape_pdf_position =
R"doc(Query the probability density of sample_position() for a particular
static const char *__doc_mitsuba_Shape_pdf_direction_volume =
R"doc(Query the probability density of sample_direction_volume()

Parameter ``it``:
A reference position somewhere within the scene.

Parameter ``ps``:
A position record describing the sample in question

Returns:
The probability density per unit solid angle)doc";

static const char *__doc_mitsuba_Shape_pdf_position_surface =
R"doc(Query the probability density of sample_position_surface() for a particular
point on the surface.

Parameter ``ps``:
Expand All @@ -8063,6 +8141,16 @@ Parameter ``ps``:
Returns:
The probability density per unit area)doc";

static const char *__doc_mitsuba_Shape_pdf_position_volume =
R"doc(Query the probability density of sample_position_surface() for a particular
point in the volume.

Parameter ``ps``:
A position record describing the sample in question

Returns:
The probability density per unit volume)doc";

static const char *__doc_mitsuba_Shape_precompute_silhouette =
R"doc(Precompute the visible silhouette of this shape for a given viewpoint.

Expand Down Expand Up @@ -8214,8 +8302,8 @@ R"doc(Remove a texture texture with the given ``name``.

Throws an exception if the attribute was not registered.)doc";

static const char *__doc_mitsuba_Shape_sample_direction =
R"doc(Sample a direction towards this shape with respect to solid angles
static const char *__doc_mitsuba_Shape_sample_direction_surface =
R"doc(Sample a direction towards this shape with respect to solid angles
measured at a reference position within the scene

An ideal implementation of this interface would achieve a uniform
Expand All @@ -8228,7 +8316,7 @@ per unit solid angle associated with the sample.

When the Shape subclass does not supply a custom implementation of
this function, the Shape class reverts to a fallback approach that
piggybacks on sample_position(). This will generally lead to a
piggybacks on sample_position_surface(). This will generally lead to a
suboptimal sample placement and higher variance in Monte Carlo
estimators using the samples.

Expand All @@ -8241,7 +8329,34 @@ Parameter ``sample``:
Returns:
A DirectionSample instance describing the generated sample)doc";

static const char *__doc_mitsuba_Shape_sample_position =
static const char *__doc_mitsuba_Shape_sample_direction_volume =
R"doc(Sample a direction towards this shape with respect to solid angles
measured at a reference position within the scene

An ideal implementation of this interface would achieve a uniform
solid angle density within the volume region that is visible from the
reference position ``it.p`` (though such an ideal implementation is
usually neither feasible nor advisable due to poor efficiency).

The function returns the sampled position and the inverse probability
per unit solid angle associated with the sample.

When the Shape subclass does not supply a custom implementation of
this function, the Shape class reverts to a fallback approach that
piggybacks on sample_position_volume(). This will generally lead to a
suboptimal sample placement and higher variance in Monte Carlo
estimators using the samples.

Parameter ``it``:
A reference position somewhere within the scene.

Parameter ``sample``:
A uniformly distributed 3D point on the domain ``[0,1]^3``

Returns:
A DirectionSample instance describing the generated sample)doc";

static const char *__doc_mitsuba_Shape_sample_position_surface =
R"doc(Sample a point on the surface of this shape

The sampling strategy is ideally uniform over the surface, though
Expand All @@ -8258,6 +8373,23 @@ Parameter ``sample``:
Returns:
A PositionSample instance describing the generated sample)doc";

static const char *__doc_mitsuba_Shape_sample_position_volume =
R"doc(Sample a point in the volume of this shape

The sampling strategy is ideally uniform over the volume, though
implementations are allowed to deviate from a perfectly uniform
distribution as long as this is reflected in the returned probability
density.

Parameter ``time``:
The scene time associated with the position sample

Parameter ``sample``:
A uniformly distributed 3D point on the domain ``[0,1]^3``

Returns:
A PositionSample instance describing the generated sample)doc";

static const char *__doc_mitsuba_Shape_sample_precomputed_silhouette =
R"doc(Samples a boundary segement on the shape's silhouette using
precomputed information computed in precompute_silhouette.
Expand Down Expand Up @@ -8321,6 +8453,14 @@ time-dependent scaling.

The default implementation throws an exception.)doc";

static const char *__doc_mitsuba_Shape_volume =
R"doc(Return the shape's volume.

The function assumes that the object is not undergoing some kind of
time-dependent scaling.

The default implementation throws an exception.)doc";

static const char *__doc_mitsuba_Shape_texture_attribute = R"doc(Return the texture attribute associated with ``name``.)doc";

static const char *__doc_mitsuba_Shape_texture_attribute_2 = R"doc(Return the texture attribute associated with ``name``.)doc";
Expand Down Expand Up @@ -9685,7 +9825,7 @@ default implementation throws an exception.
Even if the operation is provided, it may only return an
approximation.)doc";

static const char *__doc_mitsuba_Texture_pdf_position = R"doc(Returns the probability per unit area of sample_position())doc";
static const char *__doc_mitsuba_Texture_pdf_position = R"doc(Returns the probability per unit area of sample_position_surface())doc";

static const char *__doc_mitsuba_Texture_pdf_spectrum =
R"doc(Evaluate the density function of the sample_spectrum() method as a
Expand Down Expand Up @@ -12815,6 +12955,12 @@ angles)doc";

static const char *__doc_mitsuba_warp_square_to_uniform_sphere_pdf = R"doc(Density of square_to_uniform_sphere() with respect to solid angles)doc";

static const char *__doc_mitsuba_warp_cube_to_uniform_sphere =
R"doc(Uniformly sample a vector in the unit sphere with respect to solid
angles and radius)doc";

static const char *__doc_mitsuba_warp_cube_to_uniform_sphere_pdf = R"doc(Density of cube_to_uniform_sphere() with respect to solid angles and radius)doc";

static const char *__doc_mitsuba_warp_square_to_uniform_spherical_lune =
R"doc(Uniformly sample a direction in the two spherical lunes defined by the
valid boundary directions of two touching faces defined by their
Expand Down Expand Up @@ -12854,6 +13000,8 @@ static const char *__doc_mitsuba_warp_uniform_hemisphere_to_square = R"doc(Inver

static const char *__doc_mitsuba_warp_uniform_sphere_to_square = R"doc(Inverse of the mapping square_to_uniform_sphere)doc";

static const char *__doc_mitsuba_warp_uniform_sphere_to_cube = R"doc(Inverse of the mapping cube_to_uniform_sphere)doc";

static const char *__doc_mitsuba_warp_uniform_spherical_lune_to_square = R"doc(Inverse of the mapping square_to_uniform_spherical_lune)doc";

static const char *__doc_mitsuba_warp_uniform_triangle_to_square = R"doc(Inverse of the mapping square_to_uniform_triangle)doc";
Expand Down
Loading