1 
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2016-2018 Esteban Tovagliari, The appleseedhq Organization
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // THE SOFTWARE.
27 //
28 
29 #pragma once
30 
31 // appleseed.renderer headers.
32 #include "renderer/global/globaltypes.h"
33 #include "renderer/modeling/bsdf/ibsdffactory.h"
34 #include "renderer/modeling/input/inputarray.h"
35 
36 // appleseed.foundation headers.
37 #include "foundation/platform/compiler.h"
38 #include "foundation/utility/autoreleaseptr.h"
39 
40 // appleseed.main headers.
41 #include "main/dllsymbol.h"
42 
43 // Forward declarations.
44 namespace foundation    { class Dictionary; }
45 namespace foundation    { class DictionaryArray; }
46 namespace renderer      { class BSDF; }
47 namespace renderer      { class ParamArray; }
48 
49 namespace renderer
50 {
51 
52 //
53 // Glass BSDF input values.
54 //
55 
APPLESEED_DECLARE_INPUT_VALUES(GlassBSDFInputValues)56 APPLESEED_DECLARE_INPUT_VALUES(GlassBSDFInputValues)
57 {
58     Spectrum        m_surface_transmittance;
59     float           m_surface_transmittance_multiplier;
60     Spectrum        m_reflection_tint;
61     Spectrum        m_refraction_tint;
62     float           m_roughness;
63     float           m_anisotropy;
64     float           m_ior;
65     Spectrum        m_volume_transmittance;
66     float           m_volume_transmittance_distance;
67     Spectrum        m_volume_absorption;
68     float           m_volume_density;
69     float           m_volume_scale;
70     float           m_energy_compensation;
71 
72     struct Precomputed
73     {
74         bool        m_backfacing;
75         float       m_outside_ior;
76         Spectrum    m_reflection_color;
77         Spectrum    m_refraction_color;
78         float       m_reflection_weight;
79         float       m_refraction_weight;
80     };
81 
82     Precomputed     m_precomputed;
83 };
84 
85 
86 //
87 // Glass BSDF factory.
88 //
89 
90 class APPLESEED_DLLSYMBOL GlassBSDFFactory
91   : public IBSDFFactory
92 {
93   public:
94     // Delete this instance.
95     void release() override;
96 
97     // Return a string identifying this BSDF model.
98     const char* get_model() const override;
99 
100     // Return metadata for this BSDF model.
101     foundation::Dictionary get_model_metadata() const override;
102 
103     // Return metadata for the inputs of this BSDF model.
104     foundation::DictionaryArray get_input_metadata() const override;
105 
106     // Create a new BSDF instance.
107     foundation::auto_release_ptr<BSDF> create(
108         const char*         name,
109         const ParamArray&   params) const override;
110 };
111 
112 // Write the computed tables to OpenEXR images and C++ arrays.
113 // Used in Renderer_Modeling_BSDF_EnergyCompensation unit tests.
114 void write_glass_directional_albedo_tables(const char* directory);
115 
116 }   // namespace renderer
117