Skip to content

Commit

Permalink
Fix mipmapping regression (#98)
Browse files Browse the repository at this point in the history
* Fix compilation errors and fix UV data not being set prior to LoD calculations

* Revert weird BSPParser commit

* Fix markups
  • Loading branch information
yogwoggf authored Nov 9, 2024
1 parent 3c0ef66 commit 06ba9ee
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/vistrace/Structs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <cstddef>

namespace VisTrace
{
struct Pixel
Expand Down
2 changes: 1 addition & 1 deletion source/objects/AccelStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions source/objects/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions source/objects/Primitives.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <Utils.h>

#include "Material.h"

class AccelStruct;
Expand Down Expand Up @@ -75,9 +77,14 @@ struct TriangleBackfaceCull
const bvh::Vector3<Scalar> p1,
const bvh::Vector3<Scalar> 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();
}

Expand Down

0 comments on commit 06ba9ee

Please sign in to comment.