4#ifndef GREM_GRAPHICS_3D_DECALS_3D_HPP
5#define GREM_GRAPHICS_3D_DECALS_3D_HPP
30struct DecalMaterialID {
31 [[nodiscard]]
constexpr bool operator==(
const DecalMaterialID&)
const noexcept =
default;
36 friend std::hash<DecalMaterialID>;
38 constexpr explicit DecalMaterialID(uint32_t index) noexcept
59 constexpr explicit operator
bool() const noexcept {
79 [[nodiscard]]
constexpr std::strong_ordering
operator<=>(
const DecalID& other)
const noexcept =
default;
84 friend std::hash<DecalID>;
86 constexpr explicit DecalID(uint64_t value) noexcept
436 options = newOptions;
471 for (
const auto& [decalID, decal] : decals) {
472 if constexpr (CALLBACK_RETURNS_BOOL) {
473 if (callback(decalID)) {
480 if constexpr (CALLBACK_RETURNS_BOOL) {
488 static constexpr uint32_t INITIAL_RESOLUTION = 1024;
489 static constexpr uint32_t PADDING = 8;
490 static constexpr uint32_t ALIGNMENT = 16;
492 struct DecalMaterial {
493 vec4 baseColorMapPositionAndSize;
494 vec4 normalMapPositionAndSize;
495 vec4 occlusionRoughnessMetallicMapPositionAndSize;
496 vec4 emissiveMapPositionAndSize;
497 vec4 baseColorFactor;
498 vec3 occlusionRoughnessMetallicFactor;
504 DecalMaterialID materialID;
512 uint32_t modelInstanceIdentifier;
515 [[nodiscard]] GREM_API(graphics_3d)
vec2 getDefaultDecalBaseColorMapPosition();
516 [[nodiscard]] GREM_API(graphics_3d)
vec2 getDefaultDecalNormalMapPosition();
517 [[nodiscard]] GREM_API(graphics_3d)
vec2 getDefaultDecalOcclusionRoughnessMetallicMapPosition();
518 [[nodiscard]] GREM_API(graphics_3d)
vec2 getDefaultDecalEmissiveMapPosition();
520 GREM_API(graphics_3d)
void flush(Renderer3D& renderer3D)
const;
523 [[no_unique_address]] Decals3DOptions options;
524 OrderedMap<DecalID, Decal> decals{};
525 uint64_t lastDecalIDValue = 0;
526 resource::AtlasPacker atlasPacker{{.initialResolution = INITIAL_RESOLUTION, .padding = PADDING, .alignment = ALIGNMENT}};
527 Texture atlasTexture{};
528 Optional<vec2> defaultBaseColorMapPosition{};
529 Optional<vec2> defaultNormalMapPosition{};
530 Optional<vec2> defaultOcclusionRoughnessMetallicMapPosition{};
531 Optional<vec2> defaultEmissiveMapPosition{};
532 Buffer<DecalMaterial> decalMaterials{};
534 mutable bool parameterBufferDirty =
true;
540struct std::hash<
grem::graphics::DecalMaterialID> {
542 return hasher(decalMaterialID.index);
546 [[no_unique_address]] std::hash<grem::uint32_t> hasher;
550struct std::hash<
grem::graphics::DecalID> {
552 return hasher(decalID.value);
556 [[no_unique_address]] std::hash<grem::uint64_t> hasher;
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
static const Color WHITE
Definition Color.hpp:215
Set of decals in 3D space.
Definition Decals3D.hpp:255
UniformBuffer< Parameters, "Decals3DParameters"> ParameterBuffer
Shader buffer for decal parameters.
Definition Decals3D.hpp:264
auto forEachDecal(auto callback)
Execute a callback function for each decal in the decal set.
Definition Decals3D.hpp:469
void clearDecals() noexcept
Remove all decals from the set.
void clearDecalMaterials() noexcept
Remove all decal materials and images from the set, and consequently all decals as well.
bool containsDecal(DecalID id) const noexcept
Check if a specific decal handle is still valid, meaning that the decal has not yet been destroyed.
void setDecalColor(DecalID id, Color newColor)
Update the tint color of a decal.
bool destroyDecal(DecalID id)
Destroy a decal and remove it from the set.
DecalID createDecal(DecalMaterialID materialID, const DecalOptions3D &options)
Create a decal.
void setDecalEmissiveFactor(DecalID id, vec3 newEmissiveFactor)
Update the emissive factor of a decal.
void setDecalModelInstanceIdentifier(DecalID id, uint32_t newModelInstanceIdentifier)
Update the model instance identifier of a decal.
void setDecalOrientation(DecalID id, quat newOrientation)
Update the rotation of a decal.
void setOptions(const Decals3DOptions &newOptions)
Set the configuration options of the decal set.
Definition Decals3D.hpp:435
Decals3DOptions getOptions() const noexcept
Get the configuration options of the decal set.
Definition Decals3D.hpp:444
DecalMaterialID createDecalMaterial(const DecalMaterialOptions &options)
Create a decal material.
void setDecalSize(DecalID id, vec2 newSize)
Update the size of a decal.
void setDecalPosition(DecalID id, vec3 newPosition)
Update the position of a decal.
void setDecalOrigin(DecalID id, vec2 newOrigin)
Update the origin of a decal.
void setDecalRange(DecalID id, float newRange)
Update the range of a decal.
Decals3D(Device &device, const Decals3DOptions &options={})
Construct a set of decals.
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Persistent system that provides 3D rendering capabilities.
Definition Renderer3D.hpp:120
Read-only non-owning view over a 2D image.
Definition Image.hpp:108
Definition concepts.hpp:47
Definition concepts.hpp:243
Definition buffer_layouts.hpp:20
qua< float > quat
Definition math.hpp:892
vec< 4, float > vec4
Definition math.hpp:440
vec< 2, float > vec2
Definition math.hpp:438
vec< 3, float > vec3
Definition math.hpp:439
static constexpr T MAX
Definition fundamentals.hpp:29
Opaque handle to a specific decal in a Decals3D set.
Definition Decals3D.hpp:47
constexpr bool operator==(const DecalID &other) const noexcept=default
Compare this handle to another for equality.
constexpr std::strong_ordering operator<=>(const DecalID &other) const noexcept=default
Compare this handle to another.
constexpr DecalID() noexcept=default
Construct an invalid decal handle.
Opaque identifier for a specific decal material in a Decals3D set.
Definition Decals3D.hpp:30
constexpr bool operator==(const DecalMaterialID &) const noexcept=default
Configuration options for a decal material.
Definition Decals3D.hpp:95
float occlusionStrength
Occlusion strength of the decal material.
Definition Decals3D.hpp:140
resource::ImageView emissiveMapImage
Emissive map image of the decal material, or an empty image view to use a fully white texture.
Definition Decals3D.hpp:130
bool convertToPremultipliedAlpha
Convert the decal base color map image from straight to pre-multiplied alpha.
Definition Decals3D.hpp:168
resource::ImageView occlusionRoughnessMetallicMapImage
Occlusion-roughness-metallic map image of the decal material, or an empty image view to use a fully w...
Definition Decals3D.hpp:121
float metallicFactor
Metallic factor of the decal material.
Definition Decals3D.hpp:150
float roughnessFactor
Roughness factor of the decal material.
Definition Decals3D.hpp:145
resource::ImageView baseColorMapImage
Base color map image of the decal material, or an empty image view to use a fully white texture.
Definition Decals3D.hpp:103
vec3 emissiveFactor
Emissive factor of the decal material.
Definition Decals3D.hpp:160
float normalScale
Normal scale of the decal material.
Definition Decals3D.hpp:155
vec4 baseColorFactor
Base color factor of the decal material.
Definition Decals3D.hpp:135
resource::ImageView normalMapImage
Normal map image of the decal material, or an empty image view to use a flat normal texture.
Definition Decals3D.hpp:112
Configuration options for a 3D decal.
Definition Decals3D.hpp:174
vec2 size
Size of the decal, in world coordinates.
Definition Decals3D.hpp:194
quat orientation
Rotation of the decal around its DecalOptions3D::origin.
Definition Decals3D.hpp:189
vec2 origin
Offset, in local vertex coordinates, specifying the origin relative to the bottom left of the decal.
Definition Decals3D.hpp:201
vec3 position
Position, in world coordinates, to render the decal at.
Definition Decals3D.hpp:178
vec3 emissiveFactor
Emissive factor to use in the shader.
Definition Decals3D.hpp:220
constexpr bool operator==(const DecalOptions3D &other) const noexcept=default
Compare these options to another set of options for equality.
uint32_t modelInstanceIdentifier
Model instance identifier that the decal applies to, or the maximum value to apply to all instances.
Definition Decals3D.hpp:226
Color color
Tint color to use in the shader.
Definition Decals3D.hpp:211
Configuration options for a Decals3D set.
Definition Decals3D.hpp:241
constexpr bool operator==(const Decals3DOptions &other) const noexcept=default
Compare these options to another set of options for equality.
Struct of shader parameters representing the decals.
Definition Decals3D.hpp:258
sampler2D decalsAtlasTexture
Sampler for the decal atlas texture.
Definition Decals3D.hpp:260
Reference to a sampler2D Texture that may be used as a parameter value type in a shader-read buffer.
Definition ParameterDescription.hpp:131
std::size_t operator()(const grem::graphics::DecalID &decalID) const
Definition Decals3D.hpp:551
std::size_t operator()(const grem::graphics::DecalMaterialID &decalMaterialID) const
Definition Decals3D.hpp:541