Program Listing for File Material.h#
↰ Return to documentation for file (include/Karana/Scene/Material.h)
/*
* Copyright (c) 2024-2026 Karana Dynamics Pty Ltd. All rights reserved.
*
* NOTICE TO USER:
*
* This source code and/or documentation (the "Licensed Materials") is
* the confidential and proprietary information of Karana Dynamics Inc.
* Use of these Licensed Materials is governed by the terms and conditions
* of a separate software license agreement between Karana Dynamics and the
* Licensee ("License Agreement"). Unless expressly permitted under that
* agreement, any reproduction, modification, distribution, or disclosure
* of the Licensed Materials, in whole or in part, to any third party
* without the prior written consent of Karana Dynamics is strictly prohibited.
*
* THE LICENSED MATERIALS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
* KARANA DYNAMICS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, AND
* FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL KARANA DYNAMICS BE LIABLE FOR ANY DAMAGES WHATSOEVER,
* INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS, DATA, OR USE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, WHETHER IN CONTRACT, TORT,
* OR OTHERWISE ARISING OUT OF OR IN CONNECTION WITH THE LICENSED MATERIALS.
*
* U.S. Government End Users: The Licensed Materials are a "commercial item"
* as defined at 48 C.F.R. 2.101, and are provided to the U.S. Government
* only as a commercial end item under the terms of this license.
*
* Any use of the Licensed Materials in individual or commercial software must
* include, in the user documentation and internal source code comments,
* this Notice, Disclaimer, and U.S. Government Use Provision.
*/
/**
* @file
* @brief Contains the declarations for the Material class.
*/
#pragma once
#include "Karana/KCore/Base.h"
#include "Karana/KCore/SharedPointer.h"
#include "Karana/Scene/Color.h"
#include "Karana/Scene/Texture.h"
#include <variant>
namespace Karana::Scene {
/// Parameter struct for a PhysicalMaterial
struct PhysicalMaterialInfo {
/// constant base color
Color color = Color::GRAY;
/// base color map
Karana::Core::ks_ptr<const Texture> color_map = nullptr;
/// how metal-like the material is, between 0 and 1
float metalness = 0.0;
/// grayscale metalness map
Karana::Core::ks_ptr<const GrayscaleTexture> metalness_map = nullptr;
/// how rough the material is, between 0 and 1
float roughness = 1.0;
/// grayscale roughness map
Karana::Core::ks_ptr<const GrayscaleTexture> roughness_map = nullptr;
/// normal map (assumes tangent space)
Karana::Core::ks_ptr<const Texture> normal_map = nullptr;
};
/**
* @class PhysicalMaterial
* @brief A standard PBR material
*
* See \sref{scene_layer_sec} for more discussion on
* the scene layer.
*/
class PhysicalMaterial : public Karana::Core::Base {
public:
/**
* Constructor for a PhysicalMaterial
*
* @param mat the parameter struct
*
*/
PhysicalMaterial(const PhysicalMaterialInfo &mat);
/**
* Destructor for PhysicalMaterial
*/
~PhysicalMaterial();
/**
* @brief Create a PhysicalMaterial
* @param mat the parameter struct
* @return The created PhysicalMaterial
*/
static Karana::Core::ks_ptr<PhysicalMaterial> create(const PhysicalMaterialInfo &mat);
/// Parameters for the materials
const PhysicalMaterialInfo info;
};
/// Parameter struct for a PhongMaterial
struct PhongMaterialInfo {
/// constant diffuse color
Color color = Color::GRAY;
/// diffuse color map
Karana::Core::ks_ptr<const Texture> color_map = nullptr;
/// constant ambient color
Color ambient_color = Color::GRAY;
/// ambient color map
Karana::Core::ks_ptr<const Texture> ambient_color_map = nullptr;
/// constant specular color
Color specular_color = Color::BLACK;
/// specular color map
Karana::Core::ks_ptr<const Texture> specular_color_map = nullptr;
/// constant emissive color
Color emissive_color = Color::BLACK;
/// emissive color map
Karana::Core::ks_ptr<const Texture> emissive_color_map = nullptr;
};
/**
* @class PhongMaterial
* @brief A standard Phong material
*
* See \sref{scene_layer_sec} for more discussion on
* the scene layer.
*/
class PhongMaterial : public Karana::Core::Base {
public:
/**
* Constructor from a PhongMaterialInfo
*
* @param mat the parameter struct
*
*/
PhongMaterial(const PhongMaterialInfo &mat);
/**
* Destructor for PhongMaterial
*/
~PhongMaterial();
/**
* @brief Create a PhongMaterial
* @param mat the parameter struct
* @return The created PhongMaterial
*/
static Karana::Core::ks_ptr<PhongMaterial> create(const PhongMaterialInfo &mat);
/// Parameters for the materials
const PhongMaterialInfo info;
};
/// Variant for known material types
using VarMaterial =
std::variant<Karana::Core::ks_ptr<PhysicalMaterial>, Karana::Core::ks_ptr<PhongMaterial>>;
/**
* Gets the default material
*
* @return The default material
*/
const VarMaterial &defaultMaterial();
} // namespace Karana::Scene