THERE IS SOMETHING ON SCREEN
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
<Item Name="[value]">value</Item>
|
<Item Name="[value]">value</Item>
|
||||||
</Expand>
|
</Expand>
|
||||||
</Type>
|
</Type>
|
||||||
<Type Name="Seele::Map<*>">
|
<Type Name="Seele::Map<*,*>">
|
||||||
<DisplayString>{{ size={_size} }</DisplayString>
|
<DisplayString>{{ size={_size} }</DisplayString>
|
||||||
<Expand>
|
<Expand>
|
||||||
<Item Name="[size]">_size</Item>
|
<Item Name="[size]">_size</Item>
|
||||||
|
|||||||
Vendored
+1
-1
Submodule external/slang updated: cc222702a8...4547125ce9
@@ -15,7 +15,7 @@ layout(set=5)
|
|||||||
ParameterBlock<LightCullingData> pLightCullingData;
|
ParameterBlock<LightCullingData> pLightCullingData;
|
||||||
|
|
||||||
[shader("pixel")]
|
[shader("pixel")]
|
||||||
float4 pixelMain(in MaterialParameter params : PARAMETER) : SV_Target
|
float4 fragmentMain(in MaterialParameter params : PARAMETER) : SV_Target
|
||||||
{
|
{
|
||||||
let brdf = pMaterial.prepare(params);
|
let brdf = pMaterial.prepare(params);
|
||||||
float3 result = float3(0, 0, 0);
|
float3 result = float3(0, 0, 0);
|
||||||
@@ -27,5 +27,5 @@ float4 pixelMain(in MaterialParameter params : PARAMETER) : SV_Target
|
|||||||
{
|
{
|
||||||
result += pLightEnv.pointLights[i].illuminate(params, brdf);
|
result += pLightEnv.pointLights[i].illuminate(params, brdf);
|
||||||
}
|
}
|
||||||
return float4(1, 1, 0, 1.0f);
|
return float4(result, 1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "TerrainMaterial",
|
"name": "Placeholder",
|
||||||
"params": {
|
"params": {
|
||||||
},
|
},
|
||||||
"code": [
|
"code": [
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ struct MaterialParameter
|
|||||||
float3 tangent;
|
float3 tangent;
|
||||||
float3 biTangent;
|
float3 biTangent;
|
||||||
float3 viewDir_TS;
|
float3 viewDir_TS;
|
||||||
|
float3 vertexColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VertexAttributes
|
struct VertexAttributes
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ struct StaticMeshVertexData : IVertexData
|
|||||||
params.normal = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
|
params.normal = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
|
||||||
params.tangent = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
|
params.tangent = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
|
||||||
params.biTangent = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
|
params.biTangent = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
|
||||||
|
params.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
|
||||||
attributes.parameter = params;
|
attributes.parameter = params;
|
||||||
attributes.clipPosition = clipPos;
|
attributes.clipPosition = clipPos;
|
||||||
return attributes;
|
return attributes;
|
||||||
@@ -26,4 +27,5 @@ struct StaticMeshVertexData : IVertexData
|
|||||||
StructuredBuffer<float> normals;
|
StructuredBuffer<float> normals;
|
||||||
StructuredBuffer<float> tangents;
|
StructuredBuffer<float> tangents;
|
||||||
StructuredBuffer<float> biTangents;
|
StructuredBuffer<float> biTangents;
|
||||||
|
StructuredBuffer<float> color;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
uint32 uniformBufferOffset = 0;
|
uint32 uniformBufferOffset = 0;
|
||||||
uint32 bindingCounter = 0; // Uniform buffers are always binding 0
|
uint32 bindingCounter = 0; // Uniform buffers are always binding 0
|
||||||
int32 uniformBinding = -1;
|
int32 uniformBinding = -1;
|
||||||
Map<std::string, OShaderExpression> expressions;
|
Array<OShaderExpression> expressions;
|
||||||
uint32 key = 0;
|
uint32 key = 0;
|
||||||
uint32 auxKey = 0;
|
uint32 auxKey = 0;
|
||||||
Array<std::string> parameters;
|
Array<std::string> parameters;
|
||||||
@@ -74,7 +74,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->data = std::stof(defaultValue.value().get<std::string>());
|
p->data = std::stof(defaultValue.value().get<std::string>());
|
||||||
}
|
}
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[param.key()] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
// TODO: ALIGNMENT RULES
|
// TODO: ALIGNMENT RULES
|
||||||
else if(type.compare("float3") == 0)
|
else if(type.compare("float3") == 0)
|
||||||
@@ -91,7 +91,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->data = parseVector(defaultValue.value().get<std::string>().c_str());
|
p->data = parseVector(defaultValue.value().get<std::string>().c_str());
|
||||||
}
|
}
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[param.key()] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
else if(type.compare("Texture2D") == 0)
|
else if(type.compare("Texture2D") == 0)
|
||||||
{
|
{
|
||||||
@@ -107,7 +107,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
|
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
|
||||||
}
|
}
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[param.key()] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
else if(type.compare("SamplerState") == 0)
|
else if(type.compare("SamplerState") == 0)
|
||||||
{
|
{
|
||||||
@@ -115,7 +115,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||||
p->data = graphics->createSamplerState({});
|
p->data = graphics->createSamplerState({});
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[param.key()] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -128,14 +128,14 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
if(obj.is_string())
|
if(obj.is_string())
|
||||||
{
|
{
|
||||||
std::string str = obj.get<std::string>();
|
std::string str = obj.get<std::string>();
|
||||||
if (expressions.contains(str))
|
if (expressions.find([&str, &expressions](const OShaderExpression& exp) {return exp->key == str; }) != expressions.end())
|
||||||
{
|
{
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
||||||
std::string name = std::format("Const{0}", auxKey++);
|
std::string name = std::format("Const{0}", auxKey++);
|
||||||
c->key = name;
|
c->key = name;
|
||||||
expressions[name] = std::move(c);
|
expressions.add(std::move(c));
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -156,7 +156,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->key = name;
|
p->key = name;
|
||||||
p->inputs["lhs"].source = referenceExpression(obj["lhs"]);
|
p->inputs["lhs"].source = referenceExpression(obj["lhs"]);
|
||||||
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
||||||
expressions[name] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
if(exp.compare("Sub") == 0)
|
if(exp.compare("Sub") == 0)
|
||||||
{
|
{
|
||||||
@@ -165,7 +165,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->key = name;
|
p->key = name;
|
||||||
p->inputs["lhs"].source = referenceExpression(obj["lhs"]);
|
p->inputs["lhs"].source = referenceExpression(obj["lhs"]);
|
||||||
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
||||||
expressions[name] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
if(exp.compare("Mul") == 0)
|
if(exp.compare("Mul") == 0)
|
||||||
{
|
{
|
||||||
@@ -174,12 +174,12 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->key = name;
|
p->key = name;
|
||||||
p->inputs["lhs"].source = referenceExpression(obj["lhs"]);
|
p->inputs["lhs"].source = referenceExpression(obj["lhs"]);
|
||||||
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
p->inputs["rhs"].source = referenceExpression(obj["rhs"]);
|
||||||
expressions[name] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
if(exp.compare("Swizzle") == 0)
|
if(exp.compare("Swizzle") == 0)
|
||||||
{
|
{
|
||||||
OSwizzleExpression p = new SwizzleExpression();
|
OSwizzleExpression p = new SwizzleExpression();
|
||||||
std::string name = std::format("{0}", key);
|
std::string name = std::format("{0}", key++);
|
||||||
p->key = name;
|
p->key = name;
|
||||||
p->inputs["target"].source = referenceExpression(obj["target"]);
|
p->inputs["target"].source = referenceExpression(obj["target"]);
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
@@ -187,17 +187,17 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
{
|
{
|
||||||
p->comp[i++] = c.value().get<uint32>();
|
p->comp[i++] = c.value().get<uint32>();
|
||||||
}
|
}
|
||||||
expressions[name] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
if(exp.compare("Sample") == 0)
|
if(exp.compare("Sample") == 0)
|
||||||
{
|
{
|
||||||
OSampleExpression p = new SampleExpression();
|
OSampleExpression p = new SampleExpression();
|
||||||
std::string name = std::format("{0}", key);
|
std::string name = std::format("{0}", key++);
|
||||||
p->key = name;
|
p->key = name;
|
||||||
p->inputs["texture"].source = referenceExpression(obj["texture"]);
|
p->inputs["texture"].source = referenceExpression(obj["texture"]);
|
||||||
p->inputs["sampler"].source = referenceExpression(obj["sampler"]);
|
p->inputs["sampler"].source = referenceExpression(obj["sampler"]);
|
||||||
p->inputs["coords"].source = referenceExpression(obj["coords"]);
|
p->inputs["coords"].source = referenceExpression(obj["coords"]);
|
||||||
expressions[name] = std::move(p);
|
expressions.add(std::move(p));
|
||||||
}
|
}
|
||||||
if(exp.compare("BRDF") == 0)
|
if(exp.compare("BRDF") == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
|||||||
Array<Vector> normals(mesh->mNumVertices);
|
Array<Vector> normals(mesh->mNumVertices);
|
||||||
Array<Vector> tangents(mesh->mNumVertices);
|
Array<Vector> tangents(mesh->mNumVertices);
|
||||||
Array<Vector> biTangents(mesh->mNumVertices);
|
Array<Vector> biTangents(mesh->mNumVertices);
|
||||||
|
Array<Vector> colors(mesh->mNumVertices);
|
||||||
|
|
||||||
StaticMeshVertexData* vertexData = StaticMeshVertexData::getInstance();
|
StaticMeshVertexData* vertexData = StaticMeshVertexData::getInstance();
|
||||||
|
|
||||||
@@ -165,6 +166,14 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
|||||||
normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
||||||
tangents[i] = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
|
tangents[i] = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
|
||||||
biTangents[i] = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
|
biTangents[i] = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
|
||||||
|
if(mesh->HasVertexColors(0))
|
||||||
|
{
|
||||||
|
colors[i] = Vector(mesh->mColors[0][i].r, mesh->mColors[0][i].g, mesh->mColors[0][i].b);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
colors[i] = Vector(1, 1, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshId id = vertexData->allocateVertexData(mesh->mNumVertices);
|
MeshId id = vertexData->allocateVertexData(mesh->mNumVertices);
|
||||||
@@ -173,6 +182,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
|||||||
vertexData->loadNormals(id, normals);
|
vertexData->loadNormals(id, normals);
|
||||||
vertexData->loadTangents(id, tangents);
|
vertexData->loadTangents(id, tangents);
|
||||||
vertexData->loadBiTangents(id, biTangents);
|
vertexData->loadBiTangents(id, biTangents);
|
||||||
|
vertexData->loadColors(id, colors);
|
||||||
|
|
||||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||||
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
|
||||||
|
|||||||
@@ -50,10 +50,17 @@ void ShaderCompiler::registerRenderPass(std::string name, std::string mainFile,
|
|||||||
|
|
||||||
void ShaderCompiler::compile()
|
void ShaderCompiler::compile()
|
||||||
{
|
{
|
||||||
ShaderPermutation permutation;
|
|
||||||
for (const auto& [name, pass] : passes)
|
for (const auto& [name, pass] : passes)
|
||||||
{
|
{
|
||||||
std::strncpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
|
ShaderPermutation permutation;
|
||||||
|
if (pass.useMeshShading)
|
||||||
|
{
|
||||||
|
permutation.setMeshFile(pass.mainFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
permutation.setVertexFile(pass.mainFile);
|
||||||
|
}
|
||||||
if (pass.hasFragmentShader)
|
if (pass.hasFragmentShader)
|
||||||
{
|
{
|
||||||
permutation.setFragmentFile(pass.fragmentFile);
|
permutation.setFragmentFile(pass.fragmentFile);
|
||||||
@@ -81,19 +88,22 @@ void ShaderCompiler::compile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderCollection& ShaderCompiler::createShaders(ShaderPermutation permutation)
|
void ShaderCompiler::createShaders(ShaderPermutation permutation)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(shadersLock);
|
std::scoped_lock lock(shadersLock);
|
||||||
|
PermutationId perm = PermutationId(permutation);
|
||||||
|
if (shaders.contains(perm))
|
||||||
|
return;
|
||||||
ShaderCollection collection;
|
ShaderCollection collection;
|
||||||
|
|
||||||
ShaderCreateInfo createInfo;
|
ShaderCreateInfo createInfo;
|
||||||
createInfo.typeParameter = { Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) };
|
|
||||||
createInfo.name = std::format("Material {0}", permutation.materialName);
|
createInfo.name = std::format("Material {0}", permutation.materialName);
|
||||||
if (std::strlen(permutation.materialName) > 0)
|
if (std::strlen(permutation.materialName) > 0)
|
||||||
{
|
{
|
||||||
createInfo.additionalModules.add(permutation.materialName);
|
createInfo.additionalModules.add(permutation.materialName);
|
||||||
createInfo.typeParameter.add(Pair<const char*, const char*>("IMaterial", permutation.materialName));
|
createInfo.typeParameter.add(Pair<const char*, const char*>("IMaterial", permutation.materialName));
|
||||||
}
|
}
|
||||||
|
createInfo.typeParameter.add({ Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) });
|
||||||
createInfo.additionalModules.add(permutation.vertexDataName);
|
createInfo.additionalModules.add(permutation.vertexDataName);
|
||||||
createInfo.additionalModules.add(permutation.vertexMeshFile);
|
createInfo.additionalModules.add(permutation.vertexMeshFile);
|
||||||
if (permutation.hasFragment)
|
if (permutation.hasFragment)
|
||||||
@@ -131,8 +141,5 @@ ShaderCollection& ShaderCompiler::createShaders(ShaderPermutation permutation)
|
|||||||
collection.fragmentShader = graphics->createFragmentShader(createInfo);
|
collection.fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
}
|
}
|
||||||
collection.vertexDeclaration = graphics->createVertexDeclaration(Array<VertexElement>());
|
collection.vertexDeclaration = graphics->createVertexDeclaration(Array<VertexElement>());
|
||||||
PermutationId perm = PermutationId(permutation);
|
|
||||||
shaders[perm] = std::move(collection);
|
shaders[perm] = std::move(collection);
|
||||||
|
|
||||||
return shaders[perm];
|
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ public:
|
|||||||
std::string taskFile = "");
|
std::string taskFile = "");
|
||||||
private:
|
private:
|
||||||
void compile();
|
void compile();
|
||||||
ShaderCollection& createShaders(ShaderPermutation permutation);
|
void createShaders(ShaderPermutation permutation);
|
||||||
std::mutex shadersLock;
|
std::mutex shadersLock;
|
||||||
Map<PermutationId, ShaderCollection> shaders;
|
Map<PermutationId, ShaderCollection> shaders;
|
||||||
Map<std::string, PMaterial> materials;
|
Map<std::string, PMaterial> materials;
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ void StaticMeshVertexData::loadBiTangents(MeshId id, const Array<Vector>& data)
|
|||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Seele::StaticMeshVertexData::loadColors(MeshId id, const Array<Vector>& data)
|
||||||
|
{
|
||||||
|
uint64 offset = meshOffsets[id];
|
||||||
|
assert(offset + data.size() <= head);
|
||||||
|
std::memcpy(colorData.data() + offset, data.data(), data.size() * sizeof(Vector));
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer)
|
void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer)
|
||||||
{
|
{
|
||||||
uint64 offset = meshOffsets[id];
|
uint64 offset = meshOffsets[id];
|
||||||
@@ -69,16 +77,19 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
|
|||||||
Array<Vector> nor(numVertices);
|
Array<Vector> nor(numVertices);
|
||||||
Array<Vector> tan(numVertices);
|
Array<Vector> tan(numVertices);
|
||||||
Array<Vector> bit(numVertices);
|
Array<Vector> bit(numVertices);
|
||||||
|
Array<Vector> col(numVertices);
|
||||||
std::copy(positionData.begin() + offset, positionData.begin() + offset + numVertices, pos.begin());
|
std::copy(positionData.begin() + offset, positionData.begin() + offset + numVertices, pos.begin());
|
||||||
std::copy(texCoordsData.begin() + offset, texCoordsData.begin() + offset + numVertices, tex.begin());
|
std::copy(texCoordsData.begin() + offset, texCoordsData.begin() + offset + numVertices, tex.begin());
|
||||||
std::copy(normalData.begin() + offset, normalData.begin() + offset + numVertices, nor.begin());
|
std::copy(normalData.begin() + offset, normalData.begin() + offset + numVertices, nor.begin());
|
||||||
std::copy(tangentData.begin() + offset, tangentData.begin() + offset + numVertices, tan.begin());
|
std::copy(tangentData.begin() + offset, tangentData.begin() + offset + numVertices, tan.begin());
|
||||||
std::copy(biTangentData.begin() + offset, biTangentData.begin() + offset + numVertices, bit.begin());
|
std::copy(biTangentData.begin() + offset, biTangentData.begin() + offset + numVertices, bit.begin());
|
||||||
|
std::copy(colorData.begin() + offset, colorData.begin() + offset + numVertices, col.begin());
|
||||||
Serialization::save(buffer, pos);
|
Serialization::save(buffer, pos);
|
||||||
Serialization::save(buffer, tex);
|
Serialization::save(buffer, tex);
|
||||||
Serialization::save(buffer, nor);
|
Serialization::save(buffer, nor);
|
||||||
Serialization::save(buffer, tan);
|
Serialization::save(buffer, tan);
|
||||||
Serialization::save(buffer, bit);
|
Serialization::save(buffer, bit);
|
||||||
|
Serialization::save(buffer, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer)
|
void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer)
|
||||||
@@ -88,16 +99,19 @@ void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer)
|
|||||||
Array<Vector> nor;
|
Array<Vector> nor;
|
||||||
Array<Vector> tan;
|
Array<Vector> tan;
|
||||||
Array<Vector> bit;
|
Array<Vector> bit;
|
||||||
|
Array<Vector> col;
|
||||||
Serialization::load(buffer, pos);
|
Serialization::load(buffer, pos);
|
||||||
Serialization::load(buffer, tex);
|
Serialization::load(buffer, tex);
|
||||||
Serialization::load(buffer, nor);
|
Serialization::load(buffer, nor);
|
||||||
Serialization::load(buffer, tan);
|
Serialization::load(buffer, tan);
|
||||||
Serialization::load(buffer, bit);
|
Serialization::load(buffer, bit);
|
||||||
|
Serialization::load(buffer, col);
|
||||||
loadPositions(id, pos);
|
loadPositions(id, pos);
|
||||||
loadTexCoords(id, tex);
|
loadTexCoords(id, tex);
|
||||||
loadNormals(id, nor);
|
loadNormals(id, nor);
|
||||||
loadTangents(id, tan);
|
loadTangents(id, tan);
|
||||||
loadBiTangents(id, bit);
|
loadBiTangents(id, bit);
|
||||||
|
loadBiTangents(id, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticMeshVertexData::init(Gfx::PGraphics graphics)
|
void StaticMeshVertexData::init(Gfx::PGraphics graphics)
|
||||||
@@ -109,6 +123,7 @@ void StaticMeshVertexData::init(Gfx::PGraphics graphics)
|
|||||||
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
descriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
|
descriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
descriptorLayout->create();
|
descriptorLayout->create();
|
||||||
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
||||||
}
|
}
|
||||||
@@ -141,6 +156,7 @@ void StaticMeshVertexData::resizeBuffers()
|
|||||||
normals = graphics->createShaderBuffer(createInfo);
|
normals = graphics->createShaderBuffer(createInfo);
|
||||||
tangents = graphics->createShaderBuffer(createInfo);
|
tangents = graphics->createShaderBuffer(createInfo);
|
||||||
biTangents = graphics->createShaderBuffer(createInfo);
|
biTangents = graphics->createShaderBuffer(createInfo);
|
||||||
|
colors = graphics->createShaderBuffer(createInfo);
|
||||||
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
|
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
|
||||||
createInfo.stride = sizeof(Vector2);
|
createInfo.stride = sizeof(Vector2);
|
||||||
texCoords = graphics->createShaderBuffer(createInfo);
|
texCoords = graphics->createShaderBuffer(createInfo);
|
||||||
@@ -150,6 +166,7 @@ void StaticMeshVertexData::resizeBuffers()
|
|||||||
normalData.resize(verticesAllocated);
|
normalData.resize(verticesAllocated);
|
||||||
tangentData.resize(verticesAllocated);
|
tangentData.resize(verticesAllocated);
|
||||||
biTangentData.resize(verticesAllocated);
|
biTangentData.resize(verticesAllocated);
|
||||||
|
colorData.resize(verticesAllocated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticMeshVertexData::updateBuffers()
|
void StaticMeshVertexData::updateBuffers()
|
||||||
@@ -174,6 +191,10 @@ void StaticMeshVertexData::updateBuffers()
|
|||||||
.size = biTangentData.size() * sizeof(Vector),
|
.size = biTangentData.size() * sizeof(Vector),
|
||||||
.data = (uint8*)biTangentData.data(),
|
.data = (uint8*)biTangentData.data(),
|
||||||
});
|
});
|
||||||
|
colors->updateContents(DataSource{
|
||||||
|
.size = colorData.size() * sizeof(Vector),
|
||||||
|
.data = (uint8*)colorData.data()
|
||||||
|
});
|
||||||
descriptorLayout->reset();
|
descriptorLayout->reset();
|
||||||
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
||||||
descriptorSet->updateBuffer(0, positions);
|
descriptorSet->updateBuffer(0, positions);
|
||||||
@@ -181,5 +202,6 @@ void StaticMeshVertexData::updateBuffers()
|
|||||||
descriptorSet->updateBuffer(2, normals);
|
descriptorSet->updateBuffer(2, normals);
|
||||||
descriptorSet->updateBuffer(3, tangents);
|
descriptorSet->updateBuffer(3, tangents);
|
||||||
descriptorSet->updateBuffer(4, biTangents);
|
descriptorSet->updateBuffer(4, biTangents);
|
||||||
|
descriptorSet->updateBuffer(5, colors);
|
||||||
descriptorSet->writeChanges();
|
descriptorSet->writeChanges();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
void loadNormals(MeshId id, const Array<Vector>& data);
|
void loadNormals(MeshId id, const Array<Vector>& data);
|
||||||
void loadTangents(MeshId id, const Array<Vector>& data);
|
void loadTangents(MeshId id, const Array<Vector>& data);
|
||||||
void loadBiTangents(MeshId id, const Array<Vector>& data);
|
void loadBiTangents(MeshId id, const Array<Vector>& data);
|
||||||
|
void loadColors(MeshId id, const Array<Vector>& data);
|
||||||
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
||||||
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||||
virtual void init(Gfx::PGraphics graphics) override;
|
virtual void init(Gfx::PGraphics graphics) override;
|
||||||
@@ -36,6 +37,8 @@ private:
|
|||||||
Array<Vector> tangentData;
|
Array<Vector> tangentData;
|
||||||
Gfx::OShaderBuffer biTangents;
|
Gfx::OShaderBuffer biTangents;
|
||||||
Array<Vector> biTangentData;
|
Array<Vector> biTangentData;
|
||||||
|
Gfx::OShaderBuffer colors;
|
||||||
|
Array<Vector> colorData;
|
||||||
Gfx::ODescriptorLayout descriptorLayout;
|
Gfx::ODescriptorLayout descriptorLayout;
|
||||||
Gfx::PDescriptorSet descriptorSet;
|
Gfx::PDescriptorSet descriptorSet;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh)
|
|||||||
},
|
},
|
||||||
.indexBuffer = mesh->indexBuffer,
|
.indexBuffer = mesh->indexBuffer,
|
||||||
});
|
});
|
||||||
|
matInstanceData.materialInstance = mesh->referencedMaterial->getHandle();
|
||||||
|
matInstanceData.materialInstance->updateDescriptor();
|
||||||
matInstanceData.numMeshes += meshData[mesh->id].size();
|
matInstanceData.numMeshes += meshData[mesh->id].size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Material::Material(Gfx::PGraphics graphics,
|
|||||||
uint32 uniformDataSize,
|
uint32 uniformDataSize,
|
||||||
uint32 uniformBinding,
|
uint32 uniformBinding,
|
||||||
std::string materialName,
|
std::string materialName,
|
||||||
Map<std::string, OShaderExpression> expressions,
|
Array<OShaderExpression> expressions,
|
||||||
Array<std::string> parameter,
|
Array<std::string> parameter,
|
||||||
MaterialNode brdf)
|
MaterialNode brdf)
|
||||||
: graphics(graphics)
|
: graphics(graphics)
|
||||||
@@ -112,14 +112,15 @@ void Material::compile()
|
|||||||
codeStream << "struct " << materialName << " : IMaterial {\n";
|
codeStream << "struct " << materialName << " : IMaterial {\n";
|
||||||
for(const auto& parameter : parameters)
|
for(const auto& parameter : parameters)
|
||||||
{
|
{
|
||||||
PShaderParameter handle = PShaderExpression(codeExpressions[parameter]);
|
PShaderParameter handle = PShaderExpression(*codeExpressions.find([¶meter](const OShaderExpression& exp) {return exp->key == parameter; }));
|
||||||
handle->generateDeclaration(codeStream);
|
handle->generateDeclaration(codeStream);
|
||||||
}
|
}
|
||||||
codeStream << "\ttypedef " << brdf.profile << " BRDF;\n";
|
codeStream << "\ttypedef " << brdf.profile << " BRDF;\n";
|
||||||
codeStream << "\t" << brdf.profile << " prepare(MaterialParameter input) {\n";
|
codeStream << "\t" << brdf.profile << " prepare(MaterialParameter input) {\n";
|
||||||
codeStream << "\t\t" << brdf.profile << " result;\n";
|
codeStream << "\t\t" << brdf.profile << " result;\n";
|
||||||
Map<std::string, std::string> varState;
|
Map<std::string, std::string> varState;
|
||||||
for(const auto& [_, expr] :codeExpressions)
|
// initialize variable state
|
||||||
|
for(const auto& expr :codeExpressions)
|
||||||
{
|
{
|
||||||
codeStream << expr->evaluate(varState);
|
codeStream << expr->evaluate(varState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
uint32 uniformDataSize,
|
uint32 uniformDataSize,
|
||||||
uint32 uniformBinding,
|
uint32 uniformBinding,
|
||||||
std::string materialName,
|
std::string materialName,
|
||||||
Map<std::string, OShaderExpression> expressions,
|
Array<OShaderExpression> expressions,
|
||||||
Array<std::string> parameter,
|
Array<std::string> parameter,
|
||||||
MaterialNode brdf);
|
MaterialNode brdf);
|
||||||
~Material();
|
~Material();
|
||||||
@@ -34,7 +34,7 @@ private:
|
|||||||
uint64 instanceId;
|
uint64 instanceId;
|
||||||
Gfx::ODescriptorLayout layout;
|
Gfx::ODescriptorLayout layout;
|
||||||
std::string materialName;
|
std::string materialName;
|
||||||
Map<std::string, OShaderExpression> codeExpressions;
|
Array<OShaderExpression> codeExpressions;
|
||||||
Array<std::string> parameters;
|
Array<std::string> parameters;
|
||||||
MaterialNode brdf;
|
MaterialNode brdf;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ MaterialInstance::MaterialInstance()
|
|||||||
|
|
||||||
MaterialInstance::MaterialInstance(uint64 id,
|
MaterialInstance::MaterialInstance(uint64 id,
|
||||||
Gfx::PGraphics graphics,
|
Gfx::PGraphics graphics,
|
||||||
Map<std::string, OShaderExpression>& expressions,
|
Array<OShaderExpression>& expressions,
|
||||||
Array<std::string> params,
|
Array<std::string> params,
|
||||||
uint32 uniformBinding,
|
uint32 uniformBinding,
|
||||||
uint32 uniformSize)
|
uint32 uniformSize)
|
||||||
@@ -33,7 +33,8 @@ MaterialInstance::MaterialInstance(uint64 id,
|
|||||||
parameters.reserve(params.size());
|
parameters.reserve(params.size());
|
||||||
for (size_t i = 0; i < params.size(); ++i)
|
for (size_t i = 0; i < params.size(); ++i)
|
||||||
{
|
{
|
||||||
Serialization::save(buffer, expressions[params[i]]);
|
const std::string& name = params[i];
|
||||||
|
Serialization::save(buffer, *expressions.find([&name](const OShaderExpression& p) {return p->key == name; }));
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
OShaderParameter param;
|
OShaderParameter param;
|
||||||
Serialization::load(buffer, param);
|
Serialization::load(buffer, param);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public:
|
|||||||
MaterialInstance();
|
MaterialInstance();
|
||||||
MaterialInstance(uint64 id,
|
MaterialInstance(uint64 id,
|
||||||
Gfx::PGraphics graphics,
|
Gfx::PGraphics graphics,
|
||||||
Map<std::string, OShaderExpression>& expressions,
|
Array<OShaderExpression>& expressions,
|
||||||
Array<std::string> params,
|
Array<std::string> params,
|
||||||
uint32 uniformBinding,
|
uint32 uniformBinding,
|
||||||
uint32 uniformSize);
|
uint32 uniformSize);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ DECLARE_NAME_REF(Gfx, SamplerState)
|
|||||||
struct SamplerParameter : public ShaderParameter
|
struct SamplerParameter : public ShaderParameter
|
||||||
{
|
{
|
||||||
static constexpr uint64 IDENTIFIER = 0x08;
|
static constexpr uint64 IDENTIFIER = 0x08;
|
||||||
Gfx::PSamplerState data;
|
Gfx::OSamplerState data;
|
||||||
SamplerParameter() {}
|
SamplerParameter() {}
|
||||||
SamplerParameter(std::string name, uint32 byteOffset, uint32 binding);
|
SamplerParameter(std::string name, uint32 byteOffset, uint32 binding);
|
||||||
virtual ~SamplerParameter();
|
virtual ~SamplerParameter();
|
||||||
|
|||||||
Reference in New Issue
Block a user