File: materials.h

package info (click to toggle)
embree 4.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 100,656 kB
  • sloc: cpp: 228,918; xml: 40,944; ansic: 2,685; python: 812; sh: 635; makefile: 228; csh: 42
file content (260 lines) | stat: -rw-r--r-- 8,645 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#if defined (CPPTUTORIAL) && !defined(_MATERIALS_H_CPPTUTORIAL) || !defined(_MATERIALS_H_)

#if defined (CPPTUTORIAL)
#define _MATERIALS_H_CPPTUTORIAL
#else
#define _MATERIALS_H_
#endif

//#pragma once

#if !defined(ISPC)
#include "texture.h"
#include "scenegraph.h"
#endif

#if !defined(ISPC)
namespace embree
{
#endif

#if defined(ISPC) || defined(CPPTUTORIAL)
#define MATERIAL_BASE_CLASS
#define PREFIX(x) ISPC##x
#else
#define MATERIAL_BASE_CLASS : public SceneGraph::MaterialNode
#define PREFIX(x) x
#endif

#if !defined(CPPTUTORIAL)
  enum MaterialType
  {
    MATERIAL_OBJ,
    MATERIAL_THIN_DIELECTRIC,
    MATERIAL_METAL,
    MATERIAL_VELVET,
    MATERIAL_DIELECTRIC,
    MATERIAL_METALLIC_PAINT,
    MATERIAL_MATTE,
    MATERIAL_MIRROR,
    MATERIAL_REFLECTIVE_METAL,
    MATERIAL_HAIR
  };
#endif

  struct PREFIX(Material)
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    Material (MaterialType type)
     : type(type) {}
#endif
#if !defined(ISPC)
    __aligned(16)
#endif
    int type;
    int align[3];
  };

  struct PREFIX(MatteMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    MatteMaterial (const Vec3fa& reflectance)
      : base(MATERIAL_MATTE), reflectance(reflectance) {}
    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa reflectance;
  };

  struct PREFIX(MirrorMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    MirrorMaterial (const Vec3fa& reflectance)
      : base(MATERIAL_MIRROR), reflectance(reflectance) {}
    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa reflectance;
  };

  struct PREFIX(ThinDielectricMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    ThinDielectricMaterial (const Vec3fa& transmission, const float eta, const float thickness)
      : base(MATERIAL_THIN_DIELECTRIC), transmission(transmission), transmissionFactor(log(transmission)*thickness), eta(eta), thickness(thickness) {}
    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa transmission;
    Vec3fa transmissionFactor;
    float eta;
    float thickness;
  };

  struct PREFIX(OBJMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    OBJMaterial (const std::string name = "")
      : SceneGraph::MaterialNode(name), base(MATERIAL_OBJ), illum(0), d(1.f), Ns(1.f), Ni(1.f), Ka(0.f), Kd(1.f), Ks(0.f), Kt(1.0f),
        map_d(nullptr), map_Ka(nullptr), map_Kd(nullptr), map_Ks(nullptr), map_Kt(nullptr), map_Ns(nullptr), map_Displ(nullptr) {}

    OBJMaterial (float d, const Vec3fa& Kd, const Vec3fa& Ks, const float Ns, const std::string name = "")
      : base(MATERIAL_OBJ), illum(0), d(d), Ns(Ns), Ni(1.f), Ka(0.f), Kd(Kd), Ks(Ks), Kt(1.0f),
        map_d(nullptr), map_Ka(nullptr), map_Kd(nullptr), map_Ks(nullptr), map_Kt(nullptr), map_Ns(nullptr), map_Displ(nullptr) {}

    OBJMaterial (float d, const std::shared_ptr<Texture> map_d,
                 const Vec3fa& Ka, const std::shared_ptr<Texture> map_Ka, 
                 const Vec3fa& Kd, const std::shared_ptr<Texture> map_Kd, 
                 const Vec3fa& Ks, const std::shared_ptr<Texture> map_Ks,
                 const Vec3fa& Kt, const std::shared_ptr<Texture> map_Kt, 
                 const float Ns, const std::shared_ptr<Texture> map_Ns, 
                 const std::shared_ptr<Texture> map_Displ)
      : base(MATERIAL_OBJ), illum(0), d(d), Ns(Ns), Ni(1.f), Ka(Ka), Kd(Kd), Ks(Ks), Kt(Kt), 
      map_d(nullptr), map_Ka(nullptr), map_Kd(nullptr), map_Ks(nullptr), map_Kt(nullptr), map_Ns(nullptr), map_Displ(nullptr),
      _map_d(map_d), _map_Ka(map_Ka), _map_Kd(map_Kd), _map_Ks(map_Ks), _map_Kt(map_Kt), _map_Ns(map_Ns), _map_Displ(map_Displ) {}

    virtual Material* material() 
    { 
      map_d = _map_d.get();
      map_Ka = _map_Ka.get();
      map_Kd = _map_Kd.get();
      map_Ks = _map_Ks.get();
      map_Kt = _map_Kt.get();
      map_Ns = _map_Ns.get();
      map_Displ = _map_Displ.get();
      return &base; 
    }

    ~OBJMaterial() { // FIXME: destructor never called
    }
#endif

    PREFIX(Material) base;
    int illum;             /*< illumination model */
    float d;               /*< dissolve factor, 1=opaque, 0=transparent */
    float Ns;              /*< specular exponent */
    float Ni;              /*< optical density for the surface (index of refraction) */

    Vec3fa Ka;              /*< ambient reflectivity */
    Vec3fa Kd;              /*< diffuse reflectivity */
    Vec3fa Ks;              /*< specular reflectivity */
    Vec3fa Kt;              /*< transmission filter */

    const Texture* map_d;            /*< d texture */
    const Texture* map_Ka;           /*< Ka texture */
    const Texture* map_Kd;           /*< Kd texture */
    const Texture* map_Ks;           /*< Ks texture */
    const Texture* map_Kt;           /*< Kt texture */
    const Texture* map_Ns;           /*< Ns texture */
    const Texture* map_Displ;        /*< Displ texture */

#if !defined(ISPC) && !defined(CPPTUTORIAL)
    std::shared_ptr<Texture> _map_d;            /*< d texture */
    std::shared_ptr<Texture> _map_Ka;           /*< Ka texture */
    std::shared_ptr<Texture> _map_Kd;           /*< Kd texture */
    std::shared_ptr<Texture> _map_Ks;           /*< Ks texture */
    std::shared_ptr<Texture> _map_Kt;           /*< Kt texture */
    std::shared_ptr<Texture> _map_Ns;           /*< Ns texture */
    std::shared_ptr<Texture> _map_Displ;        /*< Displ texture */
#endif
  };

  struct PREFIX(MetalMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    MetalMaterial (const Vec3fa& reflectance, const Vec3fa& eta, const Vec3fa& k)
      : base(MATERIAL_REFLECTIVE_METAL), reflectance(reflectance), eta(eta), k(k), roughness(0.0f) {}

    MetalMaterial (const Vec3fa& reflectance, const Vec3fa& eta, const Vec3fa& k, const float roughness)
      : base(MATERIAL_METAL), reflectance(reflectance), eta(eta), k(k), roughness(roughness) {}
    
    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa reflectance;
    Vec3fa eta;
    Vec3fa k;
    float roughness;
  };

  typedef PREFIX(MetalMaterial) PREFIX(ReflectiveMetalMaterial);

  struct PREFIX(VelvetMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    VelvetMaterial (const Vec3fa& reflectance, const float backScattering, const Vec3fa& horizonScatteringColor, const float horizonScatteringFallOff)
      : base(MATERIAL_VELVET), reflectance(reflectance), horizonScatteringColor(horizonScatteringColor), backScattering(backScattering), horizonScatteringFallOff(horizonScatteringFallOff) {}

    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa reflectance;
    Vec3fa horizonScatteringColor;
    float backScattering;
    float horizonScatteringFallOff;
  };

  struct PREFIX(DielectricMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    DielectricMaterial (const Vec3fa& transmissionOutside, const Vec3fa& transmissionInside, const float etaOutside, const float etaInside)
      : base(MATERIAL_DIELECTRIC), transmissionOutside(transmissionOutside), transmissionInside(transmissionInside), etaOutside(etaOutside), etaInside(etaInside) {}

    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa transmissionOutside;
    Vec3fa transmissionInside;
    float etaOutside;
    float etaInside;
  };

  struct PREFIX(MetallicPaintMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    MetallicPaintMaterial (const Vec3fa& shadeColor, const Vec3fa& glitterColor, float glitterSpread, float eta)
      : base(MATERIAL_METALLIC_PAINT), shadeColor(shadeColor), glitterColor(glitterColor), glitterSpread(glitterSpread), eta(eta) {}

    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa shadeColor;
    Vec3fa glitterColor;
    float glitterSpread;
    float eta;
  };

  struct PREFIX(HairMaterial) MATERIAL_BASE_CLASS
  {
#if !defined(ISPC) && !defined(CPPTUTORIAL)
    HairMaterial (const Vec3fa& Kr, const Vec3fa& Kt, float nx, float ny)
      : base(MATERIAL_HAIR), Kr(Kr), Kt(Kt), nx(nx), ny(ny) {}

    virtual Material* material() { return &base; }
#endif

    PREFIX(Material) base;
    Vec3fa Kr;
    Vec3fa Kt;
    float nx;
    float ny;
  };

#undef MATERIAL_BASE_CLASS
#undef PREFIX

#if !defined(ISPC)
}
#endif

#endif