1// Copyright 2009-2020 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "render/pathtracer/Scattering.ih"
7
8#include "rkcommon/math/vec.ih"
9// utilities used by (almost all) implementations
10#include "Optics.ih"
11#include "math/random.ih"
12#include "math/sampling.ih"
13
14// keep interface of BSDFs the same
15typedef Scattering_EvalRes BSDF_EvalRes;
16typedef Scattering_SampleRes BSDF_SampleRes;
17typedef Scattering_Type BSDF_Type;
18
19#define BSDF_SPECULAR_REFLECTION SCATTERING_SPECULAR_REFLECTION
20#define BSDF_GLOSSY_REFLECTION SCATTERING_GLOSSY_REFLECTION
21#define BSDF_DIFFUSE_REFLECTION SCATTERING_DIFFUSE_REFLECTION
22#define BSDF_SPECULAR_TRANSMISSION SCATTERING_SPECULAR_TRANSMISSION
23#define BSDF_GLOSSY_TRANSMISSION SCATTERING_GLOSSY_TRANSMISSION
24#define BSDF_DIFFUSE_TRANSMISSION SCATTERING_DIFFUSE_TRANSMISSION
25#define BSDF_DIFFUSE SCATTERING_DIFFUSE
26#define BSDF_GLOSSY SCATTERING_GLOSSY
27#define BSDF_SPECULAR SCATTERING_SPECULAR
28#define BSDF_REFLECTION SCATTERING_REFLECTION
29#define BSDF_TRANSMISSION SCATTERING_TRANSMISSION
30#define BSDF_SMOOTH SCATTERING_SMOOTH
31#define BSDF_NONE SCATTERING_NONE
32#define BSDF_ALL SCATTERING_ALL
33
34struct BSDF;
35
36inline BSDF_EvalRes make_BSDF_EvalRes_zero()
37{
38  BSDF_EvalRes res;
39  res.value = make_vec3f(0.0f);
40  res.pdf = 0.0f;
41  return res;
42}
43
44inline BSDF_SampleRes make_BSDF_SampleRes_zero()
45{
46  BSDF_SampleRes res;
47  res.weight = make_vec3f(0.0f);
48  return res;
49}
50
51typedef BSDF_EvalRes (*BSDF_EvalFunc)(
52    const varying BSDF *uniform self, const vec3f &wo, const vec3f &wi);
53
54typedef BSDF_SampleRes (*BSDF_SampleFunc)(const varying BSDF *uniform self,
55    const vec3f &wo,
56    const vec2f &s,
57    float ss);
58
59struct BSDF
60{
61  varying vec3f albedo;
62  varying BSDF_Type type;
63  uniform BSDF_EvalFunc eval;
64  uniform BSDF_SampleFunc sample;
65  const varying linear3f *uniform frame;
66};
67
68inline void BSDF_Constructor(varying BSDF *uniform self,
69    varying vec3f albedo,
70    varying BSDF_Type type,
71    uniform BSDF_EvalFunc eval,
72    uniform BSDF_SampleFunc sample,
73    const varying linear3f *uniform frame)
74{
75  self->albedo = albedo;
76  self->type = type;
77  self->eval = eval;
78  self->sample = sample;
79  self->frame = frame;
80}
81
82inline vec3f getN(const varying BSDF *uniform bsdf)
83{
84  return bsdf->frame->vz;
85}
86
87inline linear3f getFrame(const varying BSDF *uniform bsdf)
88{
89  return *bsdf->frame;
90}
91