File: Metal.cpp

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (70 lines) | stat: -rw-r--r-- 1,903 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
61
62
63
64
65
66
67
68
69
70
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "Metal.h"
#include "common/Data.h"
#ifndef OSPRAY_TARGET_SYCL
// ispc
#include "render/materials/Metal_ispc.h"
#endif

namespace ospray {
namespace pathtracer {

Metal::Metal(api::ISPCDevice &device)
    : AddStructShared(device.getDRTDevice(), device, FFO_MATERIAL_METAL)
{
#ifndef OSPRAY_TARGET_SYCL
  getSh()->super.getBSDF =
      reinterpret_cast<ispc::Material_GetBSDFFunc>(ispc::Metal_getBSDF_addr());
#endif
}

std::string Metal::toString() const
{
  return "ospray::pathtracer::Metal";
}

void Metal::commit()
{
  auto ior = getParamDataT<vec3f>("ior");
  const vec3f &eta = getParam<vec3f>("eta", vec3f(RGB_AL_ETA));
  const vec3f &k = getParam<vec3f>("k", vec3f(RGB_AL_K));
  roughness = getMaterialParam1f("roughness", 0.1f);

  if (ior) {
    // resample, relies on ordered samples
    spectrum etaResampled;
    spectrum kResampled;
    auto iorP = ior->begin();
    auto iorPrev = *iorP;
    const auto iorLast = ior->end();
    float wl = SPECTRUM_FIRSTWL;
    for (int l = 0; l < SPECTRUM_SAMPLES; wl += SPECTRUM_SPACING, l++) {
      for (; iorP != iorLast && iorP->x < wl; iorP++)
        iorPrev = *iorP;
      if (iorP->x == iorPrev.x) {
        etaResampled[l] = iorPrev.y;
        kResampled[l] = iorPrev.z;
      } else {
        auto f = (wl - iorPrev.x) / (iorP->x - iorPrev.x);
        etaResampled[l] = (1.f - f) * iorPrev.y + f * iorP->y;
        kResampled[l] = (1.f - f) * iorPrev.z + f * iorP->z;
      }
    }
    getSh()->spectral = true;
    getSh()->eta = etaResampled;
    getSh()->k = kResampled;
  } else {
    // default to Aluminium, used when ior not given
    getSh()->spectral = false;
    getSh()->etaRGB = eta;
    getSh()->kRGB = k;
  }

  getSh()->roughness = roughness.factor;
  getSh()->roughnessMap = roughness.tex;
}

} // namespace pathtracer
} // namespace ospray