It finally imports somewhat
This commit is contained in:
@@ -26,10 +26,10 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
{
|
||||
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for(uint i = 0; i < pLightEnv.numPointLights; ++i)
|
||||
for(uint i = 0; i < lightCount; ++i)
|
||||
{
|
||||
//uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
||||
}
|
||||
return float4(result, 1.0f);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ struct BlinnPhong : IBRDF
|
||||
float3 baseColor;
|
||||
float metallic;
|
||||
float3 normal;
|
||||
float3 specular;
|
||||
float roughness;
|
||||
float sheen;
|
||||
|
||||
@@ -18,7 +17,6 @@ struct BlinnPhong : IBRDF
|
||||
{
|
||||
metallic = 0;
|
||||
normal = float3(0, 0, 1);
|
||||
specular = 0.5;
|
||||
roughness = 0.5;
|
||||
sheen = 1;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import Common;
|
||||
|
||||
#define MAX_NUM_TEXCOORDS 8
|
||||
|
||||
struct MaterialParameter
|
||||
{
|
||||
float3 position_WS;
|
||||
float2 texCoords[MAX_NUM_TEXCOORDS];
|
||||
float2 texCoords[1];
|
||||
float3 vertexColor;
|
||||
};
|
||||
|
||||
@@ -27,16 +25,13 @@ struct FragmentParameter
|
||||
float3 biTangent_WS : TANGENT1;
|
||||
float3 position_WS : POSITION2;
|
||||
float3 vertexColor : COLOR0;
|
||||
float2 texCoords[MAX_NUM_TEXCOORDS] : TEXCOORD0;
|
||||
float2 texCoords : TEXCOORD0;
|
||||
MaterialParameter getMaterialParameter()
|
||||
{
|
||||
MaterialParameter result;
|
||||
result.position_WS = position_WS;
|
||||
result.vertexColor = vertexColor;
|
||||
for(int i = 0; i < MAX_NUM_TEXCOORDS; ++i)
|
||||
{
|
||||
result.texCoords[i] = texCoords[i];
|
||||
}
|
||||
result.texCoords[0] = texCoords;
|
||||
return result;
|
||||
}
|
||||
LightingParameter getLightingParameter()
|
||||
@@ -57,7 +52,7 @@ struct VertexAttributes
|
||||
float3 tangent_MS;
|
||||
float3 biTangent_MS;
|
||||
float3 vertexColor;
|
||||
float2 texCoords[MAX_NUM_TEXCOORDS];
|
||||
float2 texCoords;
|
||||
FragmentParameter getParameter(float4x4 transformMatrix)
|
||||
{
|
||||
float4 modelPos = float4(position_MS, 1);
|
||||
@@ -75,10 +70,7 @@ struct VertexAttributes
|
||||
result.position_WS = worldPos.xyz;
|
||||
result.position_CS = clipPos;
|
||||
result.vertexColor = vertexColor;
|
||||
for(int i = 0; i < MAX_NUM_TEXCOORDS; ++i)
|
||||
{
|
||||
result.texCoords[i] = texCoords[i];
|
||||
}
|
||||
result.texCoords = texCoords;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ struct StaticMeshVertexData : IVertexData
|
||||
attributes.normal_MS = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
|
||||
attributes.tangent_MS = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
|
||||
attributes.biTangent_MS = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
|
||||
attributes.texCoords[0] = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
|
||||
attributes.texCoords = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
|
||||
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@@ -378,8 +378,8 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
|
||||
std::string subKey = "NormalSub";
|
||||
expressions.add(new SubExpression());
|
||||
expressions.back()->key = subKey;
|
||||
expressions.back()->inputs["lhs"].source = "1";
|
||||
expressions.back()->inputs["rhs"].source = mulKey;
|
||||
expressions.back()->inputs["lhs"].source = mulKey;
|
||||
expressions.back()->inputs["rhs"].source = "float3(1,1,1)";
|
||||
|
||||
outputNormal = subKey;
|
||||
}
|
||||
@@ -388,7 +388,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Map<std::string, PTex
|
||||
MaterialNode brdf;
|
||||
brdf.profile = "BlinnPhong";
|
||||
brdf.variables["baseColor"] = outputDiffuse;
|
||||
brdf.variables["specular"] = outputSpecular;
|
||||
//brdf.variables["specular"] = outputSpecular;
|
||||
if (!outputNormal.empty())
|
||||
{
|
||||
brdf.variables["normal"] = outputNormal;
|
||||
@@ -491,7 +491,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
|
||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||
//#pragma omp parallel for
|
||||
for (int32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||
{
|
||||
indices[faceIndex * 3 + 0] = mesh->mFaces[faceIndex].mIndices[0];
|
||||
indices[faceIndex * 3 + 1] = mesh->mFaces[faceIndex].mIndices[1];
|
||||
@@ -503,7 +503,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
Meshlet::build(positions, indices, meshlets);
|
||||
vertexData->loadMesh(id, indices, meshlets);
|
||||
|
||||
collider.physicsMesh.addCollider(positions, indices, Matrix4(1.0f));
|
||||
//collider.physicsMesh.addCollider(positions, indices, Matrix4(1.0f));
|
||||
|
||||
globalMeshes[meshIndex] = new Mesh();
|
||||
globalMeshes[meshIndex]->vertexData = vertexData;
|
||||
|
||||
@@ -31,7 +31,6 @@ private:
|
||||
|
||||
RenderGraph renderGraph;
|
||||
|
||||
ThreadPool pool;
|
||||
ViewportControl cameraSystem;
|
||||
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||
|
||||
@@ -632,13 +632,14 @@ private:
|
||||
}
|
||||
else
|
||||
{
|
||||
allocated = calculateGrowth(newSize);
|
||||
// The array is not big enough, so we make a new one
|
||||
T *newData = allocateArray(newSize);
|
||||
T *newData = allocateArray(allocated);
|
||||
|
||||
if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>)
|
||||
{
|
||||
std::memcpy(newData, _data, sizeof(T) * arraySize);
|
||||
std::memset(&newData[arraySize], 0, sizeof(T) * (newSize - arraySize));
|
||||
std::memset(&newData[arraySize], 0, sizeof(T) * (allocated - arraySize));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -648,14 +649,13 @@ private:
|
||||
newData[i] = std::forward<Type>(_data[i]);
|
||||
}
|
||||
// As well as default initialize the others
|
||||
for (size_type i = arraySize; i < newSize; ++i)
|
||||
for (size_type i = arraySize; i < allocated; ++i)
|
||||
{
|
||||
std::allocator_traits<allocator_type>::construct(allocator, &newData[i], value);
|
||||
}
|
||||
}
|
||||
deallocateArray(_data, allocated);
|
||||
arraySize = newSize;
|
||||
allocated = newSize;
|
||||
_data = newData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Shader.h"
|
||||
#include "ThreadPool.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Graphics/RenderPass/DepthPrepass.h"
|
||||
#include "Graphics/RenderPass/BasePass.h"
|
||||
@@ -51,57 +52,83 @@ void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, std::string
|
||||
|
||||
void ShaderCompiler::compile()
|
||||
{
|
||||
List<std::function<void()>> work;
|
||||
for (const auto& [name, pass] : passes)
|
||||
{
|
||||
ShaderPermutation permutation;
|
||||
if (pass.useMeshShading)
|
||||
{
|
||||
permutation.setMeshFile(pass.mainFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
permutation.setVertexFile(pass.mainFile);
|
||||
}
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
permutation.setFragmentFile(pass.fragmentFile);
|
||||
}
|
||||
if (pass.hasTaskShader)
|
||||
{
|
||||
permutation.setTaskFile(pass.taskFile);
|
||||
}
|
||||
for (const auto& [vdName, vd] : vertexData)
|
||||
{
|
||||
permutation.setVertexData(vd->getTypeName());
|
||||
if (pass.useMaterial)
|
||||
{
|
||||
for (const auto& [matName, mat] : materials)
|
||||
{
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
||||
permutation.setMaterial(mat->getName());
|
||||
createShaders(permutation, std::move(layout));
|
||||
work.add([=]() {
|
||||
ShaderPermutation permutation;
|
||||
if (pass.useMeshShading)
|
||||
{
|
||||
permutation.setMeshFile(pass.mainFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
permutation.setVertexFile(pass.mainFile);
|
||||
}
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
permutation.setFragmentFile(pass.fragmentFile);
|
||||
}
|
||||
if (pass.hasTaskShader)
|
||||
{
|
||||
permutation.setTaskFile(pass.taskFile);
|
||||
}
|
||||
permutation.setVertexData(vd->getTypeName());
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
||||
permutation.setMaterial(mat->getName());
|
||||
createShaders(permutation, std::move(layout));
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
createShaders(permutation, std::move(layout));
|
||||
work.add([=]() {
|
||||
ShaderPermutation permutation;
|
||||
if (pass.useMeshShading)
|
||||
{
|
||||
permutation.setMeshFile(pass.mainFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
permutation.setVertexFile(pass.mainFile);
|
||||
}
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
permutation.setFragmentFile(pass.fragmentFile);
|
||||
}
|
||||
if (pass.hasTaskShader)
|
||||
{
|
||||
permutation.setTaskFile(pass.taskFile);
|
||||
}
|
||||
permutation.setVertexData(vd->getTypeName());
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
createShaders(permutation, std::move(layout));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
getThreadPool().runAndWait(std::move(work));
|
||||
}
|
||||
|
||||
void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout)
|
||||
{
|
||||
std::scoped_lock lock(shadersLock);
|
||||
PermutationId perm = PermutationId(permutation);
|
||||
if (shaders.contains(perm))
|
||||
return;
|
||||
{
|
||||
std::scoped_lock lock(shadersLock);
|
||||
if (shaders.contains(perm))
|
||||
return;
|
||||
}
|
||||
ShaderCollection collection;
|
||||
collection.pipelineLayout = std::move(layout);
|
||||
|
||||
@@ -142,5 +169,8 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
|
||||
collection.fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
}
|
||||
collection.pipelineLayout->create();
|
||||
shaders[perm] = std::move(collection);
|
||||
{
|
||||
std::scoped_lock lock(shadersLock);
|
||||
shaders[perm] = std::move(collection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ struct ShaderPermutation
|
||||
char fragmentFile[32];
|
||||
char vertexDataName[32];
|
||||
char materialName[64];
|
||||
uint8 hasFragment : 1;
|
||||
uint8 useMeshShading : 1;
|
||||
uint8 hasTaskShader : 1;
|
||||
uint8 useMaterial : 1;
|
||||
uint8 hasFragment;
|
||||
uint8 useMeshShading;
|
||||
uint8 hasTaskShader;
|
||||
uint8 useMaterial;
|
||||
//TODO: lightmapping etc
|
||||
ShaderPermutation()
|
||||
{
|
||||
|
||||
@@ -105,12 +105,12 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
|
||||
Array<Vector> tan(numVertices);
|
||||
Array<Vector> bit(numVertices);
|
||||
Array<Vector> col(numVertices);
|
||||
std::memcpy(positionData.data() + offset, pos.data(), numVertices * sizeof(Vector));
|
||||
std::memcpy(texCoordsData.data() + offset, tex.data(), numVertices * sizeof(Vector2));
|
||||
std::memcpy(normalData.data() + offset, nor.data(), numVertices * sizeof(Vector));
|
||||
std::memcpy(tangentData.data() + offset, tan.data(), numVertices * sizeof(Vector));
|
||||
std::memcpy(biTangentData.data() + offset, bit.data(), numVertices * sizeof(Vector));
|
||||
std::memcpy(colorData.data() + offset, col.data(), numVertices * sizeof(Vector));
|
||||
std::memcpy(pos.data(), positionData.data() + offset, numVertices * sizeof(Vector));
|
||||
std::memcpy(tex.data(), texCoordsData.data() + offset, numVertices * sizeof(Vector2));
|
||||
std::memcpy(nor.data(), normalData.data() + offset, numVertices * sizeof(Vector));
|
||||
std::memcpy(tan.data(), tangentData.data() + offset, numVertices * sizeof(Vector));
|
||||
std::memcpy(bit.data(), biTangentData.data() + offset, numVertices * sizeof(Vector));
|
||||
std::memcpy(col.data(), colorData.data() + offset, numVertices * sizeof(Vector));
|
||||
Serialization::save(buffer, pos);
|
||||
Serialization::save(buffer, tex);
|
||||
Serialization::save(buffer, nor);
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
return Dependencies<>();
|
||||
}
|
||||
template<typename... Deps>
|
||||
void setupView(Dependencies<Deps...>, ThreadPool& pool)
|
||||
void setupView(Dependencies<Deps...>)
|
||||
{
|
||||
List<std::function<void()>> work;
|
||||
registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){
|
||||
@@ -33,12 +33,12 @@ public:
|
||||
update(comp...);
|
||||
});
|
||||
});
|
||||
pool.runAndWait(std::move(work));
|
||||
getThreadPool().runAndWait(std::move(work));
|
||||
}
|
||||
virtual void run(ThreadPool& pool, double delta) override
|
||||
virtual void run(double delta) override
|
||||
{
|
||||
SystemBase::run(pool, delta);
|
||||
setupView((getDependencies<Components>() | ...), pool);
|
||||
SystemBase::run(delta);
|
||||
setupView((getDependencies<Components>() | ...));
|
||||
}
|
||||
virtual void update() override {}
|
||||
virtual void update(Components&... components) = 0;
|
||||
|
||||
@@ -11,8 +11,6 @@ class Executor
|
||||
public:
|
||||
Executor();
|
||||
~Executor();
|
||||
private:
|
||||
ThreadPool pool;
|
||||
};
|
||||
} // namespace System
|
||||
} // namespace Seele
|
||||
|
||||
@@ -12,7 +12,7 @@ class SystemBase
|
||||
public:
|
||||
SystemBase(PScene scene) : registry(scene->registry), scene(scene) {}
|
||||
virtual ~SystemBase() {}
|
||||
virtual void run(ThreadPool&, double delta)
|
||||
virtual void run(double delta)
|
||||
{
|
||||
deltaTime = delta;
|
||||
update();
|
||||
|
||||
@@ -7,9 +7,9 @@ void SystemGraph::addSystem(System::OSystemBase system)
|
||||
systems.add(std::move(system));
|
||||
}
|
||||
|
||||
void SystemGraph::run(ThreadPool& threadPool, float deltaTime)
|
||||
void SystemGraph::run(float deltaTime)
|
||||
{
|
||||
for(auto& system : systems) {
|
||||
system->run(threadPool, deltaTime);
|
||||
system->run(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class SystemGraph
|
||||
{
|
||||
public:
|
||||
void addSystem(System::OSystemBase system);
|
||||
void run(ThreadPool& threadPool, float deltaTime);
|
||||
void run(float deltaTime);
|
||||
private:
|
||||
Array<System::OSystemBase> systems;
|
||||
};
|
||||
|
||||
@@ -61,3 +61,10 @@ void ThreadPool::work()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ThreadPool threadPool;
|
||||
|
||||
ThreadPool& Seele::getThreadPool()
|
||||
{
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
@@ -26,4 +26,5 @@ private:
|
||||
Task currentTask;
|
||||
bool running = true;
|
||||
};
|
||||
ThreadPool& getThreadPool();
|
||||
}
|
||||
@@ -43,7 +43,7 @@ void GameView::update()
|
||||
{
|
||||
vd->resetMeshData();
|
||||
}
|
||||
systemGraph->run(threadPool, updateTime);
|
||||
systemGraph->run(updateTime);
|
||||
scene->update(updateTime);
|
||||
for (VertexData* vd : VertexData::getList())
|
||||
{
|
||||
|
||||
@@ -36,7 +36,6 @@ protected:
|
||||
|
||||
PSystemGraph systemGraph;
|
||||
System::PKeyboardInput keyboardSystem;
|
||||
ThreadPool threadPool;
|
||||
float updateTime = 0;
|
||||
|
||||
virtual void keyCallback(Seele::KeyCode code, Seele::InputAction action, Seele::KeyModifier modifier) override;
|
||||
|
||||
Reference in New Issue
Block a user