Trying to fix wrong tex coord imports
This commit is contained in:
@@ -152,9 +152,10 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
aiTextureMapMode mapMode = aiTextureMapMode_Clamp;
|
||||
float blend = std::numeric_limits<float>::max();
|
||||
aiTextureOp op = aiTextureOp_Add;
|
||||
if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, nullptr, nullptr, nullptr) != AI_SUCCESS) {
|
||||
if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, &blend, &op, &mapMode) != AI_SUCCESS) {
|
||||
std::cout << "fuck" << std::endl;
|
||||
}
|
||||
uvIndex = 1;
|
||||
std::string textureKey = fmt::format("{0}Texture{1}", paramKey, index);
|
||||
auto texFilename = std::filesystem::path(texPath.C_Str());
|
||||
PTextureAsset texture;
|
||||
@@ -357,7 +358,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
|
||||
}
|
||||
|
||||
// Emissive
|
||||
//addScalarParameter(KEY_EMISSIVE_INTENSITY, AI_MATKEY_EMISSIVE_INTENSITY);
|
||||
// addScalarParameter(KEY_EMISSIVE_INTENSITY, AI_MATKEY_EMISSIVE_INTENSITY);
|
||||
addVectorParameter(KEY_EMISSIVE_COLOR, AI_MATKEY_COLOR_EMISSIVE);
|
||||
std::string outputEmissive = KEY_EMISSIVE_COLOR;
|
||||
uint32 numEmissive = material->GetTextureCount(aiTextureType_EMISSION_COLOR);
|
||||
@@ -536,7 +537,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
}
|
||||
Array<StaticMeshVertexData::NormalType> normals(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::TangentType> tangents(mesh->mNumVertices);
|
||||
//Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices);
|
||||
Array<StaticMeshVertexData::ColorType> colors(mesh->mNumVertices);
|
||||
|
||||
for (uint32 i = 0; i < mesh->mNumVertices; ++i) {
|
||||
@@ -559,13 +560,15 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
normals[i] = normal; // encodeQTangent(Matrix3(tangent, biTangent, normal));
|
||||
// the fourth component encodes the sign of the bitangent.
|
||||
// in the shader we calc n x t, and b = (n x t) * sign
|
||||
// so we try to cross the two, and see what is the result, and if it is
|
||||
// the same as b, the dot product is 1, and if they are inverse, the dot product is
|
||||
// so we try to cross the two, and see what is the result, and if it is
|
||||
// the same as b, the dot product is 1, and if they are inverse, the dot product is
|
||||
// -1, which is the sign we need
|
||||
tangents[i] = Vector4(tangent, dot(glm::cross(normal, tangent), biTangent));
|
||||
|
||||
tangents[i] = tangent;
|
||||
biTangents[i] = biTangent;
|
||||
|
||||
if (mesh->HasVertexColors(0)) {
|
||||
colors[i] = StaticMeshVertexData::ColorType(mesh->mColors[0][i].r * 65535, mesh->mColors[0][i].g * 65535, mesh->mColors[0][i].b * 65535);
|
||||
colors[i] = StaticMeshVertexData::ColorType(mesh->mColors[0][i].r * 65535, mesh->mColors[0][i].g * 65535,
|
||||
mesh->mColors[0][i].b * 65535);
|
||||
} else {
|
||||
colors[i] = StaticMeshVertexData::ColorType(1, 1, 1);
|
||||
}
|
||||
@@ -577,7 +580,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
||||
}
|
||||
vertexData->loadNormals(offset, normals);
|
||||
vertexData->loadTangents(offset, tangents);
|
||||
//vertexData->loadBitangents(offset, biTangents);
|
||||
vertexData->loadBitangents(offset, biTangents);
|
||||
vertexData->loadColors(offset, colors);
|
||||
|
||||
Array<uint32> indices(mesh->mNumFaces * 3);
|
||||
|
||||
+8
-4
@@ -25,7 +25,7 @@ using namespace Seele::Editor;
|
||||
static Gfx::OGraphics graphics;
|
||||
|
||||
int main() {
|
||||
std::string gameName = "MinecraftClone";
|
||||
std::string gameName = "MeshShadingDemo";
|
||||
std::filesystem::path outputPath = fmt::format("../../{0}Game", gameName);
|
||||
std::filesystem::path sourcePath = fmt::format("../../{0}", gameName);
|
||||
#ifdef WIN32
|
||||
@@ -57,9 +57,13 @@ int main() {
|
||||
AssetImporter::importEnvironmentMap(EnvironmentImportArgs{
|
||||
.filePath = sourcePath / "import" / "textures" / "newport_loft.hdr",
|
||||
});
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = sourcePath / "import" / "textures" / "grass_block_side.png",
|
||||
.importPath = "",
|
||||
//AssetImporter::importTexture(TextureImportArgs{
|
||||
// .filePath = sourcePath / "import" / "textures" / "grass_block_side.png",
|
||||
// .importPath = "",
|
||||
//});
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import" / "models" / "main1_sponza" / "floor.glb",
|
||||
.importPath = "sponza",
|
||||
});
|
||||
|
||||
getThreadPool().waitIdle();
|
||||
|
||||
@@ -40,11 +40,11 @@ void StaticMeshVertexData::loadTangents(uint64 offset, const Array<TangentType>&
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
/*void StaticMeshVertexData::loadBitangents(uint64 offset, const Array<BiTangentType>& data) {
|
||||
void StaticMeshVertexData::loadBitangents(uint64 offset, const Array<BiTangentType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(bitData.data() + offset, data.data(), data.size() * sizeof(BiTangentType));
|
||||
dirty = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadColors(uint64 offset, const Array<ColorType>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
@@ -70,17 +70,17 @@ void StaticMeshVertexData::serializeMesh(MeshId id, ArchiveBuffer& buffer) {
|
||||
Array<PositionType> pos(numVertices);
|
||||
Array<NormalType> nor(numVertices);
|
||||
Array<TangentType> tan(numVertices);
|
||||
//Array<BiTangentType> bit(numVertices);
|
||||
Array<BiTangentType> bit(numVertices);
|
||||
Array<ColorType> col(numVertices);
|
||||
std::memcpy(pos.data(), posData.data() + offset, numVertices * sizeof(PositionType));
|
||||
std::memcpy(nor.data(), norData.data() + offset, numVertices * sizeof(NormalType));
|
||||
std::memcpy(tan.data(), tanData.data() + offset, numVertices * sizeof(TangentType));
|
||||
//std::memcpy(bit.data(), bitData.data() + offset, numVertices * sizeof(BiTangentType));
|
||||
std::memcpy(bit.data(), bitData.data() + offset, numVertices * sizeof(BiTangentType));
|
||||
std::memcpy(col.data(), colData.data() + offset, numVertices * sizeof(ColorType));
|
||||
Serialization::save(buffer, pos);
|
||||
Serialization::save(buffer, nor);
|
||||
Serialization::save(buffer, tan);
|
||||
//Serialization::save(buffer, bit);
|
||||
Serialization::save(buffer, bit);
|
||||
Serialization::save(buffer, col);
|
||||
}
|
||||
|
||||
@@ -100,22 +100,22 @@ uint64 StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
|
||||
Array<PositionType> pos;
|
||||
Array<NormalType> nor;
|
||||
Array<TangentType> tan;
|
||||
//Array<BiTangentType> bit;
|
||||
Array<BiTangentType> bit;
|
||||
Array<ColorType> col;
|
||||
Serialization::load(buffer, pos);
|
||||
Serialization::load(buffer, nor);
|
||||
Serialization::load(buffer, tan);
|
||||
//Serialization::load(buffer, bit);
|
||||
Serialization::load(buffer, bit);
|
||||
Serialization::load(buffer, col);
|
||||
loadPositions(offset, pos);
|
||||
loadNormals(offset, nor);
|
||||
loadTangents(offset, tan);
|
||||
//loadBitangents(offset, bit);
|
||||
loadBitangents(offset, bit);
|
||||
loadColors(offset, col);
|
||||
result += pos.size() * sizeof(PositionType);
|
||||
result += nor.size() * sizeof(NormalType);
|
||||
result += tan.size() * sizeof(TangentType);
|
||||
//result += bit.size() * sizeof(BiTangentType);
|
||||
result += bit.size() * sizeof(BiTangentType);
|
||||
result += col.size() * sizeof(ColorType);
|
||||
return result;
|
||||
}
|
||||
@@ -135,10 +135,10 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
|
||||
.name = TANGENTS_NAME,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
/*descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = BITANGENTS_NAME,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});*/
|
||||
});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = COLORS_NAME,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
@@ -160,7 +160,7 @@ void StaticMeshVertexData::destroy() {
|
||||
positions = nullptr;
|
||||
normals = nullptr;
|
||||
tangents = nullptr;
|
||||
//biTangents = nullptr;
|
||||
biTangents = nullptr;
|
||||
colors = nullptr;
|
||||
descriptorSet = nullptr;
|
||||
descriptorLayout = nullptr;
|
||||
@@ -170,7 +170,7 @@ void StaticMeshVertexData::resizeBuffers() {
|
||||
posData.resize(verticesAllocated);
|
||||
norData.resize(verticesAllocated);
|
||||
tanData.resize(verticesAllocated);
|
||||
//bitData.resize(verticesAllocated);
|
||||
bitData.resize(verticesAllocated);
|
||||
colData.resize(verticesAllocated);
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
texData[i].resize(verticesAllocated);
|
||||
@@ -203,14 +203,14 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
},
|
||||
.name = "Tangents",
|
||||
});
|
||||
/*biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
biTangents = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = verticesAllocated * sizeof(BiTangentType),
|
||||
.data = (uint8*)bitData.data(),
|
||||
},
|
||||
.name = "BiTangents",
|
||||
});*/
|
||||
});
|
||||
colors = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
@@ -234,7 +234,7 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
descriptorSet->updateBuffer(POSITIONS_NAME, 0, positions);
|
||||
descriptorSet->updateBuffer(NORMALS_NAME, 0, normals);
|
||||
descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents);
|
||||
//descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents);
|
||||
descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents);
|
||||
descriptorSet->updateBuffer(COLORS_NAME, 0, colors);
|
||||
for (uint32 i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]);
|
||||
|
||||
@@ -10,8 +10,8 @@ class StaticMeshVertexData : public VertexData {
|
||||
public:
|
||||
using PositionType = Vector;
|
||||
using NormalType = Vector;
|
||||
using TangentType = Vector4;
|
||||
//using BiTangentType = Vector;
|
||||
using TangentType = Vector;
|
||||
using BiTangentType = Vector;
|
||||
using TexCoordType = U16Vector2;
|
||||
using ColorType = U16Vector;
|
||||
|
||||
@@ -22,7 +22,7 @@ class StaticMeshVertexData : public VertexData {
|
||||
void loadTexCoords(uint64 offset, uint64 index, const Array<TexCoordType>& data);
|
||||
void loadNormals(uint64 offset, const Array<NormalType>& data);
|
||||
void loadTangents(uint64 offset, const Array<TangentType>& data);
|
||||
//void loadBitangents(uint64 offset, const Array<BiTangentType>& data);
|
||||
void loadBitangents(uint64 offset, const Array<BiTangentType>& data);
|
||||
void loadColors(uint64 offset, const Array<ColorType>& data);
|
||||
virtual void serializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||
virtual uint64 deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||
@@ -45,15 +45,15 @@ class StaticMeshVertexData : public VertexData {
|
||||
constexpr static const char* NORMALS_NAME = "normals";
|
||||
Gfx::OShaderBuffer tangents;
|
||||
constexpr static const char* TANGENTS_NAME = "tangents";
|
||||
//Gfx::OShaderBuffer biTangents;
|
||||
//constexpr static const char* BITANGENTS_NAME = "biTangents";
|
||||
Gfx::OShaderBuffer biTangents;
|
||||
constexpr static const char* BITANGENTS_NAME = "biTangents";
|
||||
Gfx::OShaderBuffer colors;
|
||||
constexpr static const char* COLORS_NAME = "colors";
|
||||
Array<PositionType> posData;
|
||||
Array<TexCoordType> texData[MAX_TEXCOORDS];
|
||||
Array<NormalType> norData;
|
||||
Array<TangentType> tanData;
|
||||
//Array<BiTangentType> bitData;
|
||||
Array<BiTangentType> bitData;
|
||||
Array<ColorType> colData;
|
||||
Gfx::ODescriptorLayout descriptorLayout;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
|
||||
@@ -170,12 +170,10 @@ void Material::compile() {
|
||||
for (const auto& expr : codeExpressions) {
|
||||
codeStream << "\t\t" << expr->evaluate(varState);
|
||||
}
|
||||
//for (const auto& [name, exp] : brdf.variables) {
|
||||
for(auto it = brdf.variables.begin(); it != brdf.variables.end(); ++it){
|
||||
auto [name, exp] = *it;
|
||||
for (const auto& [name, exp] : brdf.variables) {
|
||||
codeStream << "\t\tresult." << name << " = " << varState[exp] << ";" << std::endl;
|
||||
}
|
||||
codeStream << "\t\tresult.transformNormal(input.tangentToWorld);" << std::endl;
|
||||
codeStream << "\t\tresult.normal = mul(input.tangentToWorld, result.normal);" << std::endl;
|
||||
codeStream << "\t\treturn result;\n";
|
||||
codeStream << "\t}\n";
|
||||
codeStream << "};\n";
|
||||
|
||||
@@ -312,6 +312,10 @@ std::string MulExpression::evaluate(Map<std::string, std::string>& varState) con
|
||||
if (varState.contains(rhs)) {
|
||||
rhs = varState[rhs];
|
||||
}
|
||||
if (inputs.at("lhs").type == ExpressionType::MATRIX2 || inputs.at("lhs").type == ExpressionType::MATRIX3 ||
|
||||
inputs.at("lhs").type == ExpressionType::MATRIX4) { // TODO
|
||||
return fmt::format("let {} = mul({}, {});\n", varName, lhs, rhs);
|
||||
}
|
||||
return fmt::format("let {} = {} * {};\n", varName, lhs, rhs);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ enum class ExpressionType {
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
MATRIX2,
|
||||
MATRIX3,
|
||||
MATRIX4,
|
||||
TEXTURE,
|
||||
SAMPLER,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,11 @@ void GameInterface::reload() {
|
||||
destroyInstance(game);
|
||||
FreeLibrary(lib);
|
||||
}
|
||||
std::filesystem::copy(dllPath.parent_path().parent_path() / "res" / "shaders", "./shaders/game", std::filesystem::copy_options::overwrite_existing);
|
||||
auto shaderPath = dllPath.parent_path().parent_path() / "res" / "shaders";
|
||||
if (std::filesystem::exists(shaderPath))
|
||||
{
|
||||
std::filesystem::copy(shaderPath, "./shaders/game", std::filesystem::copy_options::overwrite_existing);
|
||||
}
|
||||
lib = LoadLibraryA(dllPath.string().c_str());
|
||||
createInstance = (decltype(createInstance))GetProcAddress(lib, "createInstance");
|
||||
destroyInstance = (decltype(destroyInstance))GetProcAddress(lib, "destroyInstance");
|
||||
|
||||
@@ -9,6 +9,6 @@ CameraUpdater::~CameraUpdater() {}
|
||||
|
||||
void CameraUpdater::update(Component::Camera& camera, Component::Transform& transform) {
|
||||
Vector eyePos = transform.getPosition();
|
||||
Vector lookAt = eyePos - transform.getForward();
|
||||
Vector lookAt = eyePos + transform.getForward();
|
||||
camera.viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user