From 06ba9ee74ba67e3acefbed8e6518f16313bd772e Mon Sep 17 00:00:00 2001 From: jason <100450992+yogwoggf@users.noreply.github.com> Date: Sat, 9 Nov 2024 14:49:17 -0800 Subject: [PATCH] Fix mipmapping regression (#98) * Fix compilation errors and fix UV data not being set prior to LoD calculations * Revert weird BSPParser commit * Fix markups --- include/vistrace/Structs.h | 2 ++ source/objects/AccelStruct.cpp | 2 +- source/objects/Model.cpp | 9 +++++++-- source/objects/Primitives.h | 7 +++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/vistrace/Structs.h b/include/vistrace/Structs.h index b9ae850..489b834 100644 --- a/include/vistrace/Structs.h +++ b/include/vistrace/Structs.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace VisTrace { struct Pixel diff --git a/source/objects/AccelStruct.cpp b/source/objects/AccelStruct.cpp index 5d9bba6..a4fb793 100644 --- a/source/objects/AccelStruct.cpp +++ b/source/objects/AccelStruct.cpp @@ -403,6 +403,7 @@ World::World(GarrysMod::Lua::ILuaBase* LUA, const std::string& mapName) Vector3{ vertices[vi1].x, vertices[vi1].y, vertices[vi1].z }, Vector3{ vertices[vi2].x, vertices[vi2].y, vertices[vi2].z }, world.materials[submatIds[strPath]], + uvs + vi0, // Backface cull on the world to prevent z fighting on 2 sided water surfaces // (given you shouldnt be refracting through any other brushes this should be fine) @@ -411,7 +412,6 @@ World::World(GarrysMod::Lua::ILuaBase* LUA, const std::string& mapName) memcpy(tri.normals, normals + vi0, sizeof(glm::vec3) * 3); memcpy(tri.tangents, tangents + vi0, sizeof(glm::vec3) * 3); - memcpy(tri.uvs, uvs + vi0, sizeof(glm::vec2) * 3); memcpy(tri.alphas, alphas + vi0, sizeof(float) * 3); triangles.push_back(tri); diff --git a/source/objects/Model.cpp b/source/objects/Model.cpp index 2b60f2c..1ddd7b1 100644 --- a/source/objects/Model.cpp +++ b/source/objects/Model.cpp @@ -73,11 +73,18 @@ Mesh::Mesh( tangents[j] = GetModel()->GetTangent(mesh->GetTangentIndex(vtxVerts[j])); } + const glm::vec2 uvs[3] = { + glm::vec2(verts[0]->texCoord.x, verts[0]->texCoord.y), + glm::vec2(verts[1]->texCoord.x, verts[1]->texCoord.y), + glm::vec2(verts[2]->texCoord.x, verts[2]->texCoord.y) + }; + Triangle tri( Vector3(verts[0]->pos.x, verts[0]->pos.y, verts[0]->pos.z), Vector3(verts[1]->pos.x, verts[1]->pos.y, verts[1]->pos.z), Vector3(verts[2]->pos.x, verts[2]->pos.y, verts[2]->pos.z), mesh->material, + uvs, false ); @@ -94,8 +101,6 @@ Mesh::Mesh( tri.tangents[j] = glm::normalize(glm::vec3(tri.e1[0], tri.e1[1], tri.e1[2])); } - tri.uvs[j] = glm::vec2(verts[j]->texCoord.x, verts[j]->texCoord.y); - if (vtxVerts[j]->numBones > 0) { tri.numBones[j] = vtxVerts[j]->numBones; diff --git a/source/objects/Primitives.h b/source/objects/Primitives.h index 4fe9564..295f54c 100644 --- a/source/objects/Primitives.h +++ b/source/objects/Primitives.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "Material.h" class AccelStruct; @@ -75,9 +77,14 @@ struct TriangleBackfaceCull const bvh::Vector3 p1, const bvh::Vector3 p2, const int16_t material, + const glm::vec2 uvs[3], const bool oneSided = false ) : p0(p0), e1(p0 - p1), e2(p2 - p0), material(material), oneSided(oneSided) { + this->uvs[0] = uvs[0]; + this->uvs[1] = uvs[1]; + this->uvs[2] = uvs[2]; + ComputeNormalAndLoD(); }