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) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9 // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //
29 
30 // Interface header.
31 #include "bsdf.h"
32 
33 // appleseed.renderer headers.
34 #include "renderer/kernel/shading/shadingcontext.h"
35 #include "renderer/kernel/shading/shadingpoint.h"
36 #include "renderer/modeling/input/inputarray.h"
37 #include "renderer/modeling/input/sourceinputs.h"
38 
39 // appleseed.foundation headers.
40 #include "foundation/utility/arena.h"
41 
42 using namespace foundation;
43 
44 namespace renderer
45 {
46 
47 //
48 // BSDF class implementation.
49 //
50 
51 namespace
52 {
53     const UniqueID g_class_uid = new_guid();
54 }
55 
get_class_uid()56 UniqueID BSDF::get_class_uid()
57 {
58     return g_class_uid;
59 }
60 
61 const float BSDF::DiracDelta = -1.0f;
62 
BSDF(const char * name,const Type type,const int modes,const ParamArray & params)63 BSDF::BSDF(
64     const char*             name,
65     const Type              type,
66     const int               modes,
67     const ParamArray&       params)
68   : ConnectableEntity(g_class_uid, params)
69   , m_type(type)
70   , m_modes(modes)
71 {
72     set_name(name);
73 }
74 
compute_input_data_size() const75 size_t BSDF::compute_input_data_size() const
76 {
77     return get_inputs().compute_data_size();
78 }
79 
evaluate_inputs(const ShadingContext & shading_context,const ShadingPoint & shading_point) const80 void* BSDF::evaluate_inputs(
81     const ShadingContext&   shading_context,
82     const ShadingPoint&     shading_point) const
83 {
84     void* data = shading_context.get_arena().allocate(compute_input_data_size());
85 
86     get_inputs().evaluate(
87         shading_context.get_texture_cache(),
88         SourceInputs(shading_point.get_uv(0)),
89         data);
90 
91     prepare_inputs(
92         shading_context.get_arena(),
93         shading_point,
94         data);
95 
96     return data;
97 }
98 
prepare_inputs(Arena & arena,const ShadingPoint & shading_point,void * data) const99 void BSDF::prepare_inputs(
100     Arena&                  arena,
101     const ShadingPoint&     shading_point,
102     void*                   data) const
103 {
104 }
105 
sample_ior(SamplingContext & sampling_context,const void * data) const106 float BSDF::sample_ior(
107     SamplingContext&        sampling_context,
108     const void*             data) const
109 {
110     return 1.0f;
111 }
112 
compute_absorption(const void * data,const float distance,Spectrum & absorption) const113 void BSDF::compute_absorption(
114     const void*             data,
115     const float             distance,
116     Spectrum&               absorption) const
117 {
118     absorption.set(1.0f);
119 }
120 
121 }   // namespace renderer
122