Skip to content

Commit

Permalink
MDL_renderer: Fix nullptr access when using unsupported MDL volume.sc…
Browse files Browse the repository at this point in the history
…attering expressions.

The renderer handles only direct anisotropic_vdf() at this time, not mixers or modifiers or the new fog_vdf() added in MDL 1.8.
Initialize PRD flags for primary rays to use epsilon == 0.0f.
Changed readData() to use file tellg() and read() instead of the slow std::istreambuf_iterator method.
Moved assimp includes from Application.h to Assimp.cpp.
Cast vertex attributes to const pointers inside hit.cu.
Added fabsf() overloads for float2/3/4 to vector_math.h.
Put OptiX validation mode behind USE_DEBUG_EXCEPTIONS define.
Removed duplicate "the" from comments.
  • Loading branch information
droettger committed Oct 16, 2023
1 parent a5cc46b commit 44a1775
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 100 deletions.
2 changes: 1 addition & 1 deletion apps/MDL_renderer/dp/math/Matmnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace dp
* \param m1 A constant reference to the second matrix to compare.
* \return \c true, if \a m0 and \a m1 are equal, otherwise \c false.
* \remarks Two matrices are considered to be equal, if each element of \a m0 differs less than
* the type dependent epsilon from the the corresponding element of \a m1. */
* the type dependent epsilon from the corresponding element of \a m1. */
template<unsigned int m, unsigned int n, typename T>
bool operator==( const Matmnt<m,n,T> & m0, const Matmnt<m,n,T> & m1 );

Expand Down
7 changes: 0 additions & 7 deletions apps/MDL_renderer/inc/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@
// This include gl.h and needs to be done after glew.h
#include <GLFW/glfw3.h>

// assimp include files.
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/LogStream.hpp>

#include <map>
#include <memory>
#include <string>
Expand Down
14 changes: 7 additions & 7 deletions apps/MDL_renderer/shaders/hit.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef mi::neuraylib::Shading_state_material Mdl_state;

extern "C" __constant__ SystemData sysData;

// This shader handles every supported feature of the the renderer.
// This shader handles every supported feature of the renderer.
extern "C" __global__ void __closesthit__radiance()
{
// Get the current rtPayload pointer from the unsigned int payload registers p0 and p1.
Expand Down Expand Up @@ -106,7 +106,7 @@ extern "C" __global__ void __closesthit__radiance()
const uint3* indices = reinterpret_cast<uint3*>(theData.indices);
const uint3 tri = indices[thePrimitiveIndex];

const TriangleAttributes* attributes = reinterpret_cast<TriangleAttributes*>(theData.attributes);
const TriangleAttributes* attributes = reinterpret_cast<const TriangleAttributes*>(theData.attributes);

const TriangleAttributes& attr0 = attributes[tri.x];
const TriangleAttributes& attr1 = attributes[tri.y];
Expand Down Expand Up @@ -553,7 +553,7 @@ extern "C" __global__ void __closesthit__radiance_no_emission()
const uint3* indices = reinterpret_cast<uint3*>(theData.indices);
const uint3 tri = indices[thePrimitiveIndex];

const TriangleAttributes* attributes = reinterpret_cast<TriangleAttributes*>(theData.attributes);
const TriangleAttributes* attributes = reinterpret_cast<const TriangleAttributes*>(theData.attributes);

const TriangleAttributes& attr0 = attributes[tri.x];
const TriangleAttributes& attr1 = attributes[tri.y];
Expand Down Expand Up @@ -843,7 +843,7 @@ extern "C" __global__ void __anyhit__radiance_cutout()
const uint3* indices = reinterpret_cast<uint3*>(theData.indices);
const uint3 tri = indices[thePrimitiveIndex];

const TriangleAttributes* attributes = reinterpret_cast<TriangleAttributes*>(theData.attributes);
const TriangleAttributes* attributes = reinterpret_cast<const TriangleAttributes*>(theData.attributes);

const TriangleAttributes& attr0 = attributes[tri.x];
const TriangleAttributes& attr1 = attributes[tri.y];
Expand All @@ -864,7 +864,7 @@ extern "C" __global__ void __anyhit__radiance_cutout()
float3 tg = attr0.tangent * alpha + attr1.tangent * theBarycentrics.x + attr2.tangent * theBarycentrics.y;

// Transform attributes into internal space == world space.
po = transformPoint(objectToWorld, po);
po = transformPoint(objectToWorld, po);
ns = normalize(transformNormal(worldToObject, ns));
ng = normalize(transformNormal(worldToObject, ng));
// This is actually the geometry tangent which for the runtime generated geometry objects
Expand Down Expand Up @@ -966,7 +966,7 @@ extern "C" __global__ void __anyhit__shadow_cutout() // For the radiance ray typ
const uint3 tri = indices[thePrimitiveIndex];

// Cast the CUdeviceptr to the actual format for Triangles geometry.
const TriangleAttributes* attributes = reinterpret_cast<TriangleAttributes*>(theData.attributes);
const TriangleAttributes* attributes = reinterpret_cast<const TriangleAttributes*>(theData.attributes);

const TriangleAttributes& attr0 = attributes[tri.x];
const TriangleAttributes& attr1 = attributes[tri.y];
Expand Down Expand Up @@ -1311,7 +1311,7 @@ extern "C" __global__ void __closesthit__curves()
const unsigned int* indices = reinterpret_cast<unsigned int*>(theData.indices);
const unsigned int index = indices[thePrimitiveIndex];

const CurveAttributes* attributes = reinterpret_cast<CurveAttributes*>(theData.attributes);
const CurveAttributes* attributes = reinterpret_cast<const CurveAttributes*>(theData.attributes);

float4 spline[4];

Expand Down
1 change: 1 addition & 0 deletions apps/MDL_renderer/shaders/raygeneration.cu
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ __forceinline__ __device__ float3 integrator(PerRayData& prd)
prd.radiance = make_float3(0.0f);
prd.pdf = 0.0f;
prd.throughput = make_float3(1.0f);
prd.flags = 0;
prd.sigma_t = make_float3(0.0f); // Extinction coefficient: sigma_a + sigma_s.
prd.walk = 0; // Number of random walk steps taken through volume scattering.
prd.eventType = mi::neuraylib::BSDF_EVENT_ABSORB; // Initialize for exit. (Otherwise miss programs do not work.)
Expand Down
Loading

0 comments on commit 44a1775

Please sign in to comment.