2023-01-21 18:43:21 +01:00
|
|
|
#pragma once
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
2024-06-09 12:20:04 +02:00
|
|
|
#include "ShaderExpression.h"
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
|
|
|
|
|
namespace Seele {
|
2023-01-21 18:43:21 +01:00
|
|
|
DECLARE_REF(MaterialInstance)
|
2024-06-18 19:19:05 +02:00
|
|
|
DECLARE_NAME_REF(Gfx, Texture2D)
|
|
|
|
|
DECLARE_NAME_REF(Gfx, Sampler)
|
2024-06-09 12:20:04 +02:00
|
|
|
class Material {
|
|
|
|
|
public:
|
2023-11-01 13:38:49 +01:00
|
|
|
Material();
|
2024-06-18 19:19:05 +02:00
|
|
|
Material(Gfx::PGraphics graphics, uint32 numTextures, uint32 numSamplers, uint32 numFloats,
|
2024-06-09 12:20:04 +02:00
|
|
|
std::string materialName, Array<OShaderExpression> expressions, Array<std::string> parameter, MaterialNode brdf);
|
2023-10-24 15:01:09 +02:00
|
|
|
~Material();
|
2024-06-18 19:19:05 +02:00
|
|
|
static void init(Gfx::PGraphics graphics);
|
|
|
|
|
static Gfx::PDescriptorLayout getDescriptorLayout() { return layout; }
|
|
|
|
|
static Gfx::PDescriptorSet getDescriptorSet() { return set; }
|
|
|
|
|
static void updateDescriptor();
|
|
|
|
|
static void updateTexture(uint32 index, Gfx::PTexture2D texture);
|
|
|
|
|
static void updateSampler(uint32 index, Gfx::PSampler sampler);
|
|
|
|
|
static void updateFloatData(uint32 offset, uint32 numFloats, float* data);
|
|
|
|
|
static uint32 addTextures(uint32 numTextures);
|
|
|
|
|
static uint32 addSamplers(uint32 numSamplers);
|
|
|
|
|
static uint32 addFloats(uint32 numFloats);
|
2023-11-05 10:36:01 +01:00
|
|
|
OMaterialInstance instantiate();
|
2023-11-01 23:12:30 +01:00
|
|
|
const std::string& getName() const { return materialName; }
|
2024-05-17 18:08:11 +02:00
|
|
|
constexpr uint64 getId() const { return materialId; }
|
2024-05-09 08:41:46 +02:00
|
|
|
static constexpr const PMaterial findMaterialById(uint64 id) { return materials[id]; }
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
void save(ArchiveBuffer& buffer) const;
|
|
|
|
|
void load(ArchiveBuffer& buffer);
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2023-02-24 22:09:07 +01:00
|
|
|
void compile();
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
private:
|
2023-10-24 15:01:09 +02:00
|
|
|
Gfx::PGraphics graphics;
|
2024-06-18 19:19:05 +02:00
|
|
|
uint32 numTextures;
|
|
|
|
|
uint32 numSamplers;
|
|
|
|
|
uint32 numFloats;
|
2023-10-24 15:01:09 +02:00
|
|
|
uint64 instanceId;
|
2024-05-09 08:41:46 +02:00
|
|
|
uint64 materialId;
|
2023-01-21 18:43:21 +01:00
|
|
|
std::string materialName;
|
2023-11-11 22:39:17 +01:00
|
|
|
Array<OShaderExpression> codeExpressions;
|
2023-11-05 10:36:01 +01:00
|
|
|
Array<std::string> parameters;
|
2023-02-24 22:09:07 +01:00
|
|
|
MaterialNode brdf;
|
2024-06-18 19:19:05 +02:00
|
|
|
static Array<Gfx::PTexture2D> textures;
|
|
|
|
|
static Array<Gfx::PSampler> samplers;
|
|
|
|
|
static Gfx::OShaderBuffer floatBuffer;
|
|
|
|
|
static Array<float> floatData;
|
|
|
|
|
static Gfx::ODescriptorLayout layout;
|
|
|
|
|
static Gfx::PDescriptorSet set;
|
2024-05-09 08:41:46 +02:00
|
|
|
static std::atomic_uint64_t materialIdCounter;
|
|
|
|
|
static Array<PMaterial> materials;
|
2023-01-21 18:43:21 +01:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(Material)
|
2023-02-13 14:56:13 +01:00
|
|
|
|
2023-01-21 18:43:21 +01:00
|
|
|
} // namespace Seele
|