text: 
  //
  // This source file is part of appleseed.
  // Visit https://appleseedhq.net/ for additional information and resources.
  //
  // This software is released under the MIT license.
  //
  // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
  // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
  //
  // Permission is hereby granted, free of charge, to any person obtaining a copy
  // of this software and associated documentation files (the "Software"), to deal
  // in the Software without restriction, including without limitation the rights
  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  // copies of the Software, and to permit persons to whom the Software is
  // furnished to do so, subject to the following conditions:
  //
  // The above copyright notice and this permission notice shall be included in
  // all copies or substantial portions of the Software.
  //
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  // THE SOFTWARE.
  //
  
  // Interface header.
  #include "specularbrdf.h"
  
  // appleseed.renderer headers.
  #include "renderer/kernel/lighting/scatteringmode.h"
  #include "renderer/kernel/shading/directshadingcomponents.h"
  #include "renderer/modeling/bsdf/bsdf.h"
  #include "renderer/modeling/bsdf/bsdfsample.h"
  #include "renderer/modeling/bsdf/bsdfwrapper.h"
  #include "renderer/modeling/bsdf/fresnel.h"
  #include "renderer/modeling/bsdf/specularhelper.h"
  
  // appleseed.foundation headers.
  #include "foundation/math/basis.h"
  #include "foundation/math/vector.h"
  #include "foundation/utility/api/specializedapiarrays.h"
  #include "foundation/utility/containers/dictionary.h"
  
  using namespace foundation;
  using namespace std;
  
  namespace renderer
  {
  
  namespace
  {
      //
      // Specular BRDF.
      //
  
      const char* Model = "specular_brdf";
  
      class SpecularBRDFImpl
        : public BSDF
      {
        public:
          SpecularBRDFImpl(
              const char*                 name,
              const ParamArray&           params)
            : BSDF(name, Reflective, ScatteringMode::Specular, params)
          {
              m_inputs.declare("reflectance", InputFormatSpectralReflectance);
              m_inputs.declare("reflectance_multiplier", InputFormatFloat, "1.0");
          }
  
          void release() override
          {
              delete this;
          }
  
          const char* get_model() const override
          {
              return Model;
          }
  
          void sample(
              SamplingContext&            sampling_context,
              const void*                 data,
              const bool                  adjoint,
              const bool                  cosine_mult,
              const int                   modes,
              BSDFSample&                 sample) const override
          {
              if (!ScatteringMode::has_specular(modes))
                  return;
  
              // No reflection below the shading surface.
              const Vector3f& shading_normal = sample.m_shading_basis.get_normal();
              const float cos_on = dot(sample.m_outgoing.get_value(), shading_normal);
              if (cos_on < 0.0f)
                  return;
  
              const InputValues* values = static_cast<const InputValues*>(data);
              
              sample.m_max_roughness = 0.0f;
  
              const NoFresnelFun f(
                  values->m_reflectance,
                  values->m_reflectance_multiplier);
  
              SpecularBRDFHelper::sample(f, sample);
              sample.m_value.m_beauty = sample.m_value.m_glossy;
          }
  
          float evaluate(
              const void*                 data,
              const bool                  adjoint,
              const bool                  cosine_mult,
              const Vector3f&             geometric_normal,
              const Basis3f&              shading_basis,
              const Vector3f&             outgoing,
              const Vector3f&             incoming,
              const int                   modes,
              DirectShadingComponents&    value) const override
          {
              return 0.0f;
          }
  
          float evaluate_pdf(
              const void*                 data,
              const bool                  adjoint,
              const Vector3f&             geometric_normal,
              const Basis3f&              shading_basis,
              const Vector3f&             outgoing,
              const Vector3f&             incoming,
              const int                   modes) const override
          {
              return 0.0f;
          }
  
        private:
          typedef SpecularBRDFInputValues InputValues;
      };
  
      typedef BSDFWrapper<SpecularBRDFImpl> SpecularBRDF;
  }
  
  
  //
  // SpecularBRDFFactory class implementation.
  //
  
  void SpecularBRDFFactory::release()
  {
      delete this;
  }
  
  const char* SpecularBRDFFactory::get_model() const
  {
      return Model;
  }
  
  Dictionary SpecularBRDFFactory::get_model_metadata() const
  {
      return
          Dictionary()
              .insert("name", Model)
              .insert("label", "Specular BRDF");
  }
  
  DictionaryArray SpecularBRDFFactory::get_input_metadata() const
  {
      DictionaryArray metadata;
  
      metadata.push_back(
          Dictionary()
              .insert("name", "reflectance")
              .insert("label", "Reflectance")
              .insert("type", "colormap")
              .insert("entity_types",
                  Dictionary()
                      .insert("color", "Colors")
                      .insert("texture_instance", "Texture Instances"))
              .insert("use", "required")
              .insert("default", "0.5"));
  
      metadata.push_back(
          Dictionary()
              .insert("name", "reflectance_multiplier")
              .insert("label", "Reflectance Multiplier")
              .insert("type", "colormap")
              .insert("entity_types",
                  Dictionary().insert("texture_instance", "Texture Instances"))
              .insert("use", "optional")
              .insert("default", "1.0"));
  
      return metadata;
  }
  
  auto_release_ptr<BSDF> SpecularBRDFFactory::create(
      const char*         name,
      const ParamArray&   params) const
  {
      return auto_release_ptr<BSDF>(new SpecularBRDF(name, params));
  }
  
  }   // namespace renderer
  