Redo of render paths

This commit is contained in:
Dynamitos
2020-06-02 11:46:18 +02:00
parent bb5b48698a
commit 356e6058fe
121 changed files with 3890 additions and 572 deletions
+4 -1
View File
@@ -2,5 +2,8 @@ target_sources(SeeleEngine
PRIVATE
Material.h
Material.cpp
MaterialAsset.h
MaterialAsset.cpp
MaterialInstance.h
MaterialInstance.cpp)
MaterialInstance.cpp
ShaderExpression.h)
+66 -9
View File
@@ -1,5 +1,7 @@
#include "Material.h"
#include "Asset/AssetRegistry.h"
#include <nlohmann/json.hpp>
#include <sstream>
using namespace Seele;
using json = nlohmann::json;
@@ -9,29 +11,84 @@ Material::Material()
}
Material::Material(const std::string& directory, const std::string& name)
: FileAsset(directory, name)
: MaterialAsset(directory, name)
{
}
Material::Material(const std::string& fullPath)
: FileAsset(fullPath)
{
: MaterialAsset(fullPath)
{
}
Material::~Material()
{
}
void Material::compile()
{
auto& stream = getReadStream();
stream.seekg(0);
json j;
stream >> j;
std::cout << j["test"] << std::endl;
}
std::stringstream codeStream;
materialName = j["name"].get<std::string>();
std::string profile = j["profile"].get<std::string>();
codeStream << "import LightEnv;" << std::endl;
codeStream << "import Material;" << std::endl;
codeStream << "import BRDF;" << std::endl;
codeStream << "import InputGeometry;" << std::endl;
Gfx::PGraphicsPipeline Material::getPipeline()
{
return pipeline;
codeStream << "struct " << materialName << ": IMaterial {" << std::endl;
for(auto param : j["params"].items())
{
std::string type = param.value()["type"].get<std::string>();
auto default = param.value().find("default");
if(type.compare("float") == 0)
{
PFloatParameter p = new FloatParameter();
if(default != param.value().end())
{
p->defaultValue = std::stof(default.value().get<std::string>());
}
parameters.add(p);
}
else if(type.compare("float3") == 0)
{
PVectorParameter p = new VectorParameter();
if(default != param.value().end())
{
p->defaultValue = parseVector(default.value().get<std::string>().c_str());
}
parameters.add(p);
}
else if(type.compare("Texture2D") == 0)
{
PTextureParameter p = new TextureParameter();
if(default != param.value().end())
{
}
parameters.add(p);
}
else if(type.compare("SamplerState") == 0)
{
PSamplerParameter p = new SamplerParameter();
parameters.add(p);
}
else
{
std::cout << "Error unsupported parameter type" << std::endl;
}
codeStream << type << " " << param.key();
}
codeStream << "typedef " << profile << " BRDF;" << std::endl;
codeStream << profile << " prepare(MaterialPixelParameter geometry){" << std::endl;
codeStream << profile << " result;" << std::endl;
for(auto c : j["code"].items())
{
codeStream << c.value().get<std::string>() << std::endl;
}
codeStream << "}};" << std::endl;
}
+7 -29
View File
@@ -1,44 +1,22 @@
#pragma once
#include "MinimalEngine.h"
#include "Asset/FileAsset.h"
#include "Graphics/GraphicsResources.h"
#include <nlohmann/json_fwd.hpp>
#include "MaterialAsset.h"
namespace Seele
{
struct FloatExpression
{
float data;
std::string name;
uint32 location;
};
struct VectorExpression
{
Vector data;
std::string name;
uint32 location;
};
struct TextureExpression
{
Gfx::PTexture texture;
std::string name;
uint32 location;
};
DECLARE_NAME_REF(Gfx, GraphicsPipeline);
DECLARE_NAME_REF(Gfx, PipelineLayout);
class Material : public FileAsset
class Material : public MaterialAsset
{
public:
Material();
Material(const std::string &directory, const std::string &name);
Material(const std::string &fullPath);
~Material();
void compile();
Gfx::PGraphicsPipeline getPipeline();
inline std::string getMaterialName() const {return materialName;}
private:
Gfx::PGraphicsPipeline pipeline;
Gfx::PPipelineLayout pipelineLayout;
void compile();
std::string materialName;
friend class MaterialLoader;
};
DEFINE_REF(Material);
} // namespace Seele
+21
View File
@@ -0,0 +1,21 @@
#include "MaterialAsset.h"
using namespace Seele;
MaterialAsset::MaterialAsset()
{
}
MaterialAsset::MaterialAsset(const std::string& directory, const std::string& name)
: Asset(directory, name)
{
}
MaterialAsset::MaterialAsset(const std::string& fullPath)
: Asset(fullPath)
{
}
MaterialAsset::~MaterialAsset()
{
}
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include "Asset/Asset.h"
#include "ShaderExpression.h"
namespace Seele
{
class MaterialAsset : public Asset
{
public:
MaterialAsset();
MaterialAsset(const std::string &directory, const std::string &name);
MaterialAsset(const std::string &fullPath);
~MaterialAsset();
protected:
//For now its simply the collection of parameters, since there is no point for expressions
Array<PShaderParameter> parameters;
};
DEFINE_REF(MaterialAsset);
} // namespace Seele
+2 -2
View File
@@ -8,12 +8,12 @@ MaterialInstance::MaterialInstance()
}
MaterialInstance::MaterialInstance(const std::string& directory, const std::string& name)
: FileAsset(directory, name)
: Asset(directory, name)
{
}
MaterialInstance::MaterialInstance(const std::string& fullPath)
: FileAsset(fullPath)
: Asset(fullPath)
{
}
+2 -2
View File
@@ -1,11 +1,11 @@
#pragma once
#include "Asset/FileAsset.h"
#include "Asset/Asset.h"
namespace Seele
{
DECLARE_NAME_REF(Gfx, DescriptorSet);
DECLARE_REF(Material);
class MaterialInstance : public FileAsset
class MaterialInstance : public Asset
{
public:
MaterialInstance();
+79
View File
@@ -0,0 +1,79 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele
{
struct ExpressionInput
{
};
struct ExpressionOutput
{
};
struct ShaderExpression
{
};
struct ShaderParameter : public ShaderExpression
{
std::string name;
};
DEFINE_REF(ShaderParameter);
struct FloatParameter : public ShaderParameter
{
float defaultValue;
bool setParameter(const std::string& paramName, float newDefault)
{
if(name.compare(paramName) == 0)
{
defaultValue = newDefault;
return true;
}
return false;
}
};
DEFINE_REF(FloatParameter);
struct VectorParameter : public ShaderParameter
{
Vector defaultValue;
bool setParameter(const std::string& paramName, Vector newDefault)
{
if(name.compare(paramName) == 0)
{
defaultValue = newDefault;
return true;
}
return false;
}
};
DEFINE_REF(VectorParameter);
DECLARE_NAME_REF(Gfx, Texture2D);
struct TextureParameter : public ShaderParameter
{
Gfx::PTexture2D defaultValue;
bool setParameter(const std::string& paramName, Gfx::PTexture2D newDefault)
{
if(name.compare(paramName) == 0)
{
return true;
}
return false;
}
};
DEFINE_REF(TextureParameter);
DECLARE_NAME_REF(Gfx, SamplerState);
struct SamplerParameter : public ShaderParameter
{
Gfx::PSamplerState defaultValue;
bool setParameter(const std::string& paramName, Gfx::PSamplerState newDefault)
{
if(name.compare(paramName) == 0)
{
return true;
}
return false;
}
};
DEFINE_REF(SamplerParameter);
} // namespace Seele