2020-06-02 11:46:18 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include "MinimalEngine.h"
|
2023-02-24 22:09:07 +01:00
|
|
|
#include "Containers/Map.h"
|
2023-02-13 14:56:13 +01:00
|
|
|
#include "Math/Math.h"
|
|
|
|
|
#include "Asset/TextureAsset.h"
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
namespace Seele
|
|
|
|
|
{
|
2023-02-24 22:09:07 +01:00
|
|
|
enum class ExpressionType
|
|
|
|
|
{
|
|
|
|
|
UNKNOWN,
|
|
|
|
|
FLOAT,
|
|
|
|
|
FLOAT2,
|
|
|
|
|
FLOAT3,
|
|
|
|
|
FLOAT4,
|
|
|
|
|
TEXTURE,
|
|
|
|
|
SAMPLER,
|
|
|
|
|
};
|
2020-06-02 11:46:18 +02:00
|
|
|
struct ExpressionInput
|
|
|
|
|
{
|
2023-02-24 22:09:07 +01:00
|
|
|
int source;
|
|
|
|
|
ExpressionType type = ExpressionType::UNKNOWN;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
|
|
|
|
struct ExpressionOutput
|
|
|
|
|
{
|
2023-02-24 22:09:07 +01:00
|
|
|
std::string name;
|
|
|
|
|
ExpressionType type = ExpressionType::UNKNOWN;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2023-02-24 22:09:07 +01:00
|
|
|
DECLARE_REF(ShaderExpression);
|
2020-06-02 11:46:18 +02:00
|
|
|
struct ShaderExpression
|
|
|
|
|
{
|
2023-02-24 22:09:07 +01:00
|
|
|
Map<std::string, ExpressionInput> inputs;
|
|
|
|
|
ExpressionOutput output;
|
|
|
|
|
int32 key;
|
|
|
|
|
virtual uint64 getIdentifier() const = 0;
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const = 0;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer);
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2023-02-24 22:09:07 +01:00
|
|
|
DEFINE_REF(ShaderExpression)
|
|
|
|
|
|
2021-04-01 16:40:14 +02:00
|
|
|
DECLARE_NAME_REF(Gfx, DescriptorSet)
|
2020-06-02 11:46:18 +02:00
|
|
|
struct ShaderParameter : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
std::string name;
|
2020-10-03 11:00:10 +02:00
|
|
|
uint32 byteOffset;
|
|
|
|
|
uint32 binding;
|
2023-02-13 14:56:13 +01:00
|
|
|
ShaderParameter() {}
|
2020-10-03 11:00:10 +02:00
|
|
|
ShaderParameter(std::string name, uint32 byteOffset, uint32 binding);
|
|
|
|
|
virtual ~ShaderParameter();
|
|
|
|
|
// update a descriptorset, in case of a uniform buffer, copy the data to the dst + byteOffset
|
|
|
|
|
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) = 0;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual void generateDeclaration(std::ofstream& stream) const = 0;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual uint64 getIdentifier() const = 0;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual void save(ArchiveBuffer& buffer) const;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer);
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2021-04-01 16:40:14 +02:00
|
|
|
DEFINE_REF(ShaderParameter)
|
2020-06-02 11:46:18 +02:00
|
|
|
struct FloatParameter : public ShaderParameter
|
|
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
static constexpr uint64 IDENTIFIER = 0x01;
|
2020-10-03 11:00:10 +02:00
|
|
|
float data;
|
2023-02-13 14:56:13 +01:00
|
|
|
FloatParameter() {}
|
2020-10-03 11:00:10 +02:00
|
|
|
FloatParameter(std::string name, uint32 byteOffset, uint32 binding);
|
|
|
|
|
virtual ~FloatParameter();
|
|
|
|
|
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual void generateDeclaration(std::ofstream& stream) const override;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2021-04-01 16:40:14 +02:00
|
|
|
DEFINE_REF(FloatParameter)
|
2020-06-02 11:46:18 +02:00
|
|
|
struct VectorParameter : public ShaderParameter
|
|
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
static constexpr uint64 IDENTIFIER = 0x02;
|
2023-01-21 18:43:21 +01:00
|
|
|
Vector data;
|
2023-02-13 14:56:13 +01:00
|
|
|
VectorParameter() {}
|
2020-10-03 11:00:10 +02:00
|
|
|
VectorParameter(std::string name, uint32 byteOffset, uint32 binding);
|
|
|
|
|
virtual ~VectorParameter();
|
|
|
|
|
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual void generateDeclaration(std::ofstream& stream) const override;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2021-04-01 16:40:14 +02:00
|
|
|
DEFINE_REF(VectorParameter)
|
2020-06-02 11:46:18 +02:00
|
|
|
struct TextureParameter : public ShaderParameter
|
|
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
static constexpr uint64 IDENTIFIER = 0x04;
|
2020-10-03 11:00:10 +02:00
|
|
|
PTextureAsset data;
|
2023-02-13 14:56:13 +01:00
|
|
|
TextureParameter() {}
|
2020-10-03 11:00:10 +02:00
|
|
|
TextureParameter(std::string name, uint32 byteOffset, uint32 binding);
|
|
|
|
|
virtual ~TextureParameter();
|
|
|
|
|
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual void generateDeclaration(std::ofstream& stream) const override;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2021-04-01 16:40:14 +02:00
|
|
|
DEFINE_REF(TextureParameter)
|
|
|
|
|
DECLARE_NAME_REF(Gfx, SamplerState)
|
2020-06-02 11:46:18 +02:00
|
|
|
struct SamplerParameter : public ShaderParameter
|
|
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
static constexpr uint64 IDENTIFIER = 0x08;
|
2020-10-03 11:00:10 +02:00
|
|
|
Gfx::PSamplerState data;
|
2023-02-13 14:56:13 +01:00
|
|
|
SamplerParameter() {}
|
2020-10-03 11:00:10 +02:00
|
|
|
SamplerParameter(std::string name, uint32 byteOffset, uint32 binding);
|
|
|
|
|
virtual ~SamplerParameter();
|
|
|
|
|
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual void generateDeclaration(std::ofstream& stream) const override;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
2021-04-01 16:40:14 +02:00
|
|
|
DEFINE_REF(SamplerParameter)
|
2021-05-10 23:57:55 +02:00
|
|
|
struct CombinedTextureParameter : public ShaderParameter
|
|
|
|
|
{
|
2023-02-13 14:56:13 +01:00
|
|
|
static constexpr uint64 IDENTIFIER = 0x10;
|
2021-05-10 23:57:55 +02:00
|
|
|
PTextureAsset data;
|
|
|
|
|
Gfx::PSamplerState sampler;
|
2023-02-13 14:56:13 +01:00
|
|
|
CombinedTextureParameter() {}
|
2021-05-10 23:57:55 +02:00
|
|
|
CombinedTextureParameter(std::string name, uint32 byteOffset, uint32 binding);
|
|
|
|
|
virtual ~CombinedTextureParameter();
|
|
|
|
|
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
2023-02-24 22:09:07 +01:00
|
|
|
virtual void generateDeclaration(std::ofstream& stream) const override;
|
2023-02-13 14:56:13 +01:00
|
|
|
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
2021-05-10 23:57:55 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(CombinedTextureParameter)
|
2023-02-24 22:09:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ConstantExpression : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint64 IDENTIFIER = 0x11;
|
|
|
|
|
std::string expr;
|
|
|
|
|
ConstantExpression();
|
|
|
|
|
ConstantExpression(std::string expr, ExpressionType type);
|
|
|
|
|
virtual ~ConstantExpression();
|
|
|
|
|
virtual uint64 getIdentifier() const { return IDENTIFIER; }
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(ConstantExpression)
|
|
|
|
|
struct AddExpression : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint64 IDENTIFIER = 0x12;
|
|
|
|
|
AddExpression();
|
|
|
|
|
virtual ~AddExpression();
|
|
|
|
|
virtual uint64 getIdentifier() const { return IDENTIFIER; }
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(AddExpression)
|
|
|
|
|
struct SubExpression : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint64 IDENTIFIER = 0x13;
|
|
|
|
|
SubExpression() {}
|
|
|
|
|
virtual ~SubExpression() {}
|
|
|
|
|
virtual uint64 getIdentifier() const { return IDENTIFIER; }
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(SubExpression)
|
|
|
|
|
struct MulExpression : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint64 IDENTIFIER = 0x14;
|
|
|
|
|
MulExpression() {}
|
|
|
|
|
virtual ~MulExpression() {}
|
|
|
|
|
virtual uint64 getIdentifier() const { return IDENTIFIER; }
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(MulExpression)
|
|
|
|
|
struct SwizzleExpression : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint64 IDENTIFIER = 0x15;
|
|
|
|
|
StaticArray<int32, 4> comp = {-1, -1, -1, -1};
|
|
|
|
|
SwizzleExpression() {}
|
|
|
|
|
virtual ~SwizzleExpression() {}
|
|
|
|
|
virtual uint64 getIdentifier() const { return IDENTIFIER; }
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(SwizzleExpression)
|
|
|
|
|
struct SampleExpression : public ShaderExpression
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint64 IDENTIFIER = 0x16;
|
|
|
|
|
SampleExpression() {}
|
|
|
|
|
virtual ~SampleExpression() {}
|
|
|
|
|
virtual uint64 getIdentifier() const { return IDENTIFIER; }
|
|
|
|
|
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
|
|
|
|
virtual void save(ArchiveBuffer& buffer) const override;
|
|
|
|
|
virtual void load(ArchiveBuffer& buffer) override;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(SampleExpression)
|
|
|
|
|
|
|
|
|
|
struct MaterialNode
|
|
|
|
|
{
|
|
|
|
|
std::string profile;
|
|
|
|
|
Map<std::string, PShaderExpression> variables;
|
|
|
|
|
MaterialNode() {}
|
|
|
|
|
virtual ~MaterialNode() {}
|
|
|
|
|
virtual std::string evaluate() const { return ""; }
|
|
|
|
|
void save(ArchiveBuffer& buffer) const;
|
|
|
|
|
void load(ArchiveBuffer& buffer);
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(MaterialNode)
|
2023-02-13 14:56:13 +01:00
|
|
|
namespace Serialization
|
|
|
|
|
{
|
2023-02-24 22:09:07 +01:00
|
|
|
void save(ArchiveBuffer& buffer, const PShaderExpression& parameter);
|
|
|
|
|
void load(ArchiveBuffer& buffer, PShaderExpression& parameter);
|
2023-02-13 14:56:13 +01:00
|
|
|
void save(ArchiveBuffer& buffer, const PShaderParameter& parameter);
|
|
|
|
|
void load(ArchiveBuffer& buffer, PShaderParameter& parameter);
|
|
|
|
|
} // namespace Serialization
|
2020-06-02 11:46:18 +02:00
|
|
|
} // namespace Seele
|