implemented basic shader expressions
This commit is contained in:
@@ -1,21 +1,44 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/Map.h"
|
||||
#include "Math/Math.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
enum class ExpressionType
|
||||
{
|
||||
UNKNOWN,
|
||||
FLOAT,
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
TEXTURE,
|
||||
SAMPLER,
|
||||
};
|
||||
struct ExpressionInput
|
||||
{
|
||||
|
||||
int source;
|
||||
ExpressionType type = ExpressionType::UNKNOWN;
|
||||
};
|
||||
struct ExpressionOutput
|
||||
{
|
||||
|
||||
std::string name;
|
||||
ExpressionType type = ExpressionType::UNKNOWN;
|
||||
};
|
||||
DECLARE_REF(ShaderExpression);
|
||||
struct ShaderExpression
|
||||
{
|
||||
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);
|
||||
};
|
||||
DEFINE_REF(ShaderExpression)
|
||||
|
||||
DECLARE_NAME_REF(Gfx, DescriptorSet)
|
||||
struct ShaderParameter : public ShaderExpression
|
||||
{
|
||||
@@ -27,7 +50,9 @@ struct ShaderParameter : public ShaderExpression
|
||||
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;
|
||||
virtual void generateDeclaration(std::ofstream& stream) const = 0;
|
||||
virtual uint64 getIdentifier() const = 0;
|
||||
virtual std::string evaluate(Map<int32, std::string>& varState) const override;
|
||||
virtual void save(ArchiveBuffer& buffer) const;
|
||||
virtual void load(ArchiveBuffer& buffer);
|
||||
};
|
||||
@@ -40,6 +65,7 @@ struct FloatParameter : public ShaderParameter
|
||||
FloatParameter(std::string name, uint32 byteOffset, uint32 binding);
|
||||
virtual ~FloatParameter();
|
||||
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
||||
virtual void generateDeclaration(std::ofstream& stream) const override;
|
||||
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
@@ -53,6 +79,7 @@ struct VectorParameter : public ShaderParameter
|
||||
VectorParameter(std::string name, uint32 byteOffset, uint32 binding);
|
||||
virtual ~VectorParameter();
|
||||
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
||||
virtual void generateDeclaration(std::ofstream& stream) const override;
|
||||
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
@@ -66,6 +93,7 @@ struct TextureParameter : public ShaderParameter
|
||||
TextureParameter(std::string name, uint32 byteOffset, uint32 binding);
|
||||
virtual ~TextureParameter();
|
||||
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
||||
virtual void generateDeclaration(std::ofstream& stream) const override;
|
||||
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
@@ -80,6 +108,7 @@ struct SamplerParameter : public ShaderParameter
|
||||
SamplerParameter(std::string name, uint32 byteOffset, uint32 binding);
|
||||
virtual ~SamplerParameter();
|
||||
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
||||
virtual void generateDeclaration(std::ofstream& stream) const override;
|
||||
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
@@ -94,13 +123,99 @@ struct CombinedTextureParameter : public ShaderParameter
|
||||
CombinedTextureParameter(std::string name, uint32 byteOffset, uint32 binding);
|
||||
virtual ~CombinedTextureParameter();
|
||||
virtual void updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst) override;
|
||||
virtual void generateDeclaration(std::ofstream& stream) const override;
|
||||
virtual uint64 getIdentifier() const override { return IDENTIFIER; }
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
};
|
||||
DEFINE_REF(CombinedTextureParameter)
|
||||
|
||||
|
||||
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)
|
||||
namespace Serialization
|
||||
{
|
||||
void save(ArchiveBuffer& buffer, const PShaderExpression& parameter);
|
||||
void load(ArchiveBuffer& buffer, PShaderExpression& parameter);
|
||||
void save(ArchiveBuffer& buffer, const PShaderParameter& parameter);
|
||||
void load(ArchiveBuffer& buffer, PShaderParameter& parameter);
|
||||
} // namespace Serialization
|
||||
|
||||
Reference in New Issue
Block a user