File: PathTracerUtil.ih

package info (click to toggle)
ospray 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,040 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 171; python: 69
file content (60 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "render/Renderer.ih"
#include "render/ScreenSample.ih"
#include "render/pathtracer/PathStructs.ih"
#ifdef OSPRAY_ENABLE_VOLUMES
#include "render/pathtracer/volumes/VolumeSampler.ih"
#endif

OSPRAY_BEGIN_ISPC_NAMESPACE

inline bool isSmooth(const PathVertex &pathVertex)
{
  if (pathVertex.type == SURFACE && pathVertex.bsdf
      && pathVertex.bsdf->scatteringType & SCATTERING_SMOOTH)
    return true;
#ifdef OSPRAY_ENABLE_VOLUMES
  if (pathVertex.type == VOLUME && pathVertex.volume
      && isSmoothVolumeVertex(pathVertex))
    return true;
#endif
  return false;
}

inline float misHeuristic(
    const PathContext &pathContext, float pdf1, float pdf2)
{
#ifdef OSPRAY_PATHTRACER_DEBUG
  if (pathContext.disableNEE || pathContext.disableFWD)
    return 1.f;
#else
  (void)pathContext;
#endif

  // power heuristic with beta=2
  const float p = sqr(pdf1) * rcp(sqr(pdf1) + sqr(pdf2));
  // guard against high pdf (including Dirac delta)
  // using the limit when pdf1 approaches inf
  // compare with bit less than sqrt(float_max) (when sqr starts to overflow)
  return pdf1 > 1e17f ? 1.0f : p;
}

inline void updateAuxilliaryData(
    PathState &pathState, const PathVertex &pathVertex, ScreenSample &sample)
{
  sample.albedo = pathState.throughput * pathVertex.albedo;
  if (pathVertex.type == SURFACE) {
    vec3f Ns = pathVertex.dg.Ns;
    foreach_unique (f in pathVertex.bsdf) {
      if (f != NULL && f->frame != NULL)
        Ns = getN(f);
    }
    sample.normal = pathState.throughput * Ns;
  }
}

OSPRAY_END_ISPC_NAMESPACE