Skip to content

Commit d3fa513

Browse files
committed
Update medium memory allocation to support Optix. Added OptiX alt images (none for medium-vdf-glass).
1 parent 633c89e commit d3fa513

File tree

14 files changed

+49
-46
lines changed

14 files changed

+49
-46
lines changed

src/testrender/shading.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,20 +1559,13 @@ struct HenyeyGreenstein final : public BSDF {
15591559

15601560
struct HomogeneousMedium final : public Medium {
15611561
MediumParams params;
1562+
HenyeyGreenstein phase_func;
15621563

15631564
OSL_HOSTDEVICE HomogeneousMedium(const MediumParams& params)
1564-
: Medium(this), params(params)
1565+
: Medium(this), params(params), phase_func(params.medium_g)
15651566
{
15661567
}
15671568

1568-
OSL_HOSTDEVICE static HomogeneousMedium* create(void* storage,
1569-
const MediumParams& params)
1570-
{
1571-
HomogeneousMedium* volume = new (storage) HomogeneousMedium(params);
1572-
volume->phase_func = new HenyeyGreenstein(params.medium_g);
1573-
return volume;
1574-
}
1575-
15761569
OSL_HOSTDEVICE Medium::Sample sample(Ray& r, Sampler& sampler,
15771570
Intersection& hit) const
15781571
{
@@ -1598,6 +1591,13 @@ struct HomogeneousMedium final : public Medium {
15981591
return Medium::Sample { t_volume, tr, weight };
15991592
}
16001593

1594+
OSL_HOSTDEVICE BSDF::Sample sample_phase_func(const Vec3& wo, float rx,
1595+
float ry,
1596+
float rz) const
1597+
{
1598+
return phase_func.sample(wo, rx, ry, rz);
1599+
}
1600+
16011601
OSL_HOSTDEVICE const MediumParams* get_params() const { return &params; }
16021602

16031603
OSL_HOSTDEVICE Color3 transmittance(float distance) const
@@ -1616,20 +1616,21 @@ struct EmptyMedium final : public Medium {
16161616
{
16171617
}
16181618

1619-
OSL_HOSTDEVICE static EmptyMedium* create(void* storage,
1620-
const MediumParams& params)
1621-
{
1622-
EmptyMedium* volume = new (storage) EmptyMedium(params);
1623-
return volume;
1624-
}
1619+
OSL_HOSTDEVICE const MediumParams* get_params() const { return &params; }
16251620

16261621
OSL_HOSTDEVICE Medium::Sample sample(Ray& ray, Sampler& sampler,
16271622
Intersection& hit) const
16281623
{
16291624
return { 0.0f, Color3(1.0f), Color3(1.0f) };
16301625
}
16311626

1632-
OSL_HOSTDEVICE const MediumParams* get_params() const { return &params; }
1627+
OSL_HOSTDEVICE BSDF::Sample sample_phase_func(const Vec3& wo, float rx,
1628+
float ry,
1629+
float rz) const
1630+
{
1631+
return { Vec3(1.0f), Color3(1.0f), 0.0f, 0.0f };
1632+
}
1633+
16331634
};
16341635

16351636

@@ -2204,14 +2205,20 @@ BSDF::sample_vrtl(const Vec3& wo, float rx, float ry, float rz) const
22042205
return dispatch([&](auto bsdf) { return bsdf.sample(wo, rx, ry, rz); });
22052206
}
22062207

2207-
Medium::Sample
2208+
OSL_HOSTDEVICE Medium::Sample
22082209
Medium::sample_vrtl(Ray& ray, Sampler& sampler, Intersection& hit) const
22092210
{
22102211
return dispatch(
22112212
[&](const auto& medium) { return medium.sample(ray, sampler, hit); });
22122213
}
22132214

2214-
const MediumParams*
2215+
OSL_HOSTDEVICE BSDF::Sample
2216+
Medium::sample_phase_func_vrtl(const Vec3& wo, float rx, float ry, float rz) const
2217+
{
2218+
return dispatch([&](auto medium) { return medium.sample_phase_func(wo, rx, ry, rz); });
2219+
}
2220+
2221+
OSL_HOSTDEVICE const MediumParams*
22152222
Medium::get_params_vrtl() const
22162223
{
22172224
return dispatch([&](const auto& medium) { return medium.get_params(); });

src/testrender/shading.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -393,21 +393,14 @@ struct Medium : public AbstractMedium {
393393

394394
template<typename LOBE>
395395
OSL_HOSTDEVICE Medium(LOBE* lobe)
396-
: AbstractMedium(lobe), phase_func(nullptr)
396+
: AbstractMedium(lobe)
397397
{
398398
}
399-
400-
template<typename Medium_Type, typename... Medium_Args>
401-
OSL_HOSTDEVICE static Medium_Type* create(void*, Medium_Args&&...)
402-
{
403-
static_assert(
404-
sizeof...(Medium_Args) == 0,
405-
"Subclass must implement its own static create() function"); // this is hacky
406-
return nullptr;
407-
}
408-
399+
409400
OSL_HOSTDEVICE const MediumParams* get_params() const { return {}; }
410401

402+
OSL_HOSTDEVICE const MediumParams* get_params_vrtl() const;
403+
411404
OSL_HOSTDEVICE Sample sample(Ray& r, Sampler& sampler,
412405
Intersection& hit) const
413406
{
@@ -417,9 +410,15 @@ struct Medium : public AbstractMedium {
417410
OSL_HOSTDEVICE Sample sample_vrtl(Ray& r, Sampler& sampler,
418411
Intersection& hit) const;
419412

420-
OSL_HOSTDEVICE const MediumParams* get_params_vrtl() const;
413+
OSL_HOSTDEVICE BSDF::Sample sample_phase_func(const Vec3& wo, float rx,
414+
float ry,
415+
float rz) const {
416+
return {};
417+
}
418+
OSL_HOSTDEVICE BSDF::Sample sample_phase_func_vrtl(const Vec3& wo, float rx,
419+
float ry,
420+
float rz) const;
421421

422-
BSDF* phase_func;
423422
};
424423

425424
/// Represents a weighted sum of BSDFS
@@ -472,7 +471,7 @@ struct CompositeBSDF {
472471

473472
OSL_HOSTDEVICE BSDF::Sample eval(const Vec3& wo, const Vec3& wi) const
474473
{
475-
BSDF::Sample s = {};
474+
BSDF::Sample s; // Use default constructor instead of {} initialization
476475
for (int i = 0; i < num_bsdfs; i++) {
477476
BSDF::Sample b = bsdfs[i]->eval_vrtl(wo, wi);
478477
b.weight *= weights[i];
@@ -601,10 +600,8 @@ struct MediumStack {
601600

602601
Vec3 rand_phase = sampler.get();
603602
if (scatter) {
604-
if (!mediums[0]->phase_func) { // EmptyMedium won't have one
605-
return false;
606-
}
607-
BSDF::Sample phase_sample = mediums[0]->phase_func->sample_vrtl(
603+
604+
BSDF::Sample phase_sample = mediums[0]->sample_phase_func_vrtl(
608605
-r.direction, rand_phase.x, rand_phase.y, rand_phase.z);
609606
if (phase_sample.pdf <= 0.0f) {
610607
return false;
@@ -628,9 +625,8 @@ struct MediumStack {
628625
if (num_bytes + sizeof(Medium_Type) > MaxSize)
629626
return false;
630627

631-
Medium_Type* new_medium
632-
= Medium_Type::create(pool + num_bytes,
633-
std::forward<Medium_Args>(args)...);
628+
Medium_Type* new_medium = new (pool + num_bytes)
629+
Medium_Type(std::forward<Medium_Args>(args)...);
634630

635631
if (!new_medium) {
636632
return false;
148 KB
Binary file not shown.
-17.5 KB
Binary file not shown.

testsuite/render-mx-anisotropic-vdf/scene.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
<ShaderGroup is_light="yes">float power 90000; shader emitter layer1</ShaderGroup>
20-
<Quad corner="40, 99.99, 40" edge_x="20, 0, 0" edge_y="0, 0, 20" /> <!--Lite -->
20+
<Quad corner="40, 99.95, 40" edge_x="20, 0, 0" edge_y="0, 0, 20" /> <!--Lite -->
2121

2222
<ShaderGroup>
2323
param color albedo 0.85 0.85 0.85;
@@ -26,11 +26,11 @@
2626

2727
shader anisotropic layer1;
2828
</ShaderGroup>
29-
<Quad corner="0,0,0" edge_x="99.99,0,0" edge_y="0,99.99,0" /> <!-- Bottom -->
30-
<Quad corner="0,0,0" edge_x="99.99,0,0" edge_y="0,0,149.9" /> <!-- Back -->
31-
<Quad corner="0,0,0" edge_x="0,99.99,0" edge_y="0,0,149.9" /> <!-- Left -->
32-
<Quad corner="99.99,0,0" edge_x="0,99.99,0" edge_y="0,0,149.9" /> <!-- Right -->
33-
<Quad corner="0,99.99,0" edge_x="99.99,0,0" edge_y="0,0,149.9" /> <!-- Front -->
34-
<Quad corner="0,0,149.9" edge_x="99.99,0,0" edge_y="0,99.99,0" /> <!-- Top -->
29+
<Quad corner="0,0,0" edge_x="99.9,0,0" edge_y="0,99.9,0" /> <!-- Bottom -->
30+
<Quad corner="0,0,0" edge_x="99.9,0,0" edge_y="0,0,149.9" /> <!-- Back -->
31+
<Quad corner="0,0,0" edge_x="0,99.9,0" edge_y="0,0,149.9" /> <!-- Left -->
32+
<Quad corner="99.9,0,0" edge_x="0,99.9,0" edge_y="0,0,149.9" /> <!-- Right -->
33+
<Quad corner="0,99.9,0" edge_x="99.9,0,0" edge_y="0,0,149.9" /> <!-- Front -->
34+
<Quad corner="0,0,149.9" edge_x="99.9,0,0" edge_y="0,99.9,0" /> <!-- Top -->
3535

3636
</World>
-4.17 KB
Binary file not shown.
-4.21 KB
Binary file not shown.
Binary file not shown.
-21 Bytes
Binary file not shown.
77 KB
Binary file not shown.

0 commit comments

Comments
 (0)