Skip to content

Commit

Permalink
Merge branch 'development' into queue-sync-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesugb committed Jul 31, 2024
2 parents 0f67741 + 8db61b6 commit 2922ccf
Show file tree
Hide file tree
Showing 111 changed files with 7,699 additions and 5,204 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/cross-platform-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- 'framework/**'
- 'CMakeLists.txt'
pull_request:
workflow_dispatch:
# workflow_dispatch:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -18,7 +18,7 @@ env:
jobs:
linux:
name: ${{ matrix.config.name }}, VulkanSDK ${{ matrix.vulkan-sdk }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand All @@ -35,7 +35,7 @@ jobs:
}
# note: if a specific vulkan version (e.g. 1.1.x, or < 1.2.135) needs testing, you can add it here:
# (not that ubuntu-latest (20.04) only supports >= v1.2.148 via apt)
vulkan-sdk: ["latest", "1.3.216"]
vulkan-sdk: ["latest", "1.3.243"]

steps:
- name: Checkout repository and submodules
Expand All @@ -49,15 +49,17 @@ jobs:
# We'll use this as our working directory for all subsequent commands
run: |
# Add lunarg apt sources
sudo sed -i -e 's|disco|jammy|g' /etc/apt/sources.list
sudo apt update
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
if [ "${{ matrix.vulkan-sdk }}" = "latest" ]; then
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-focal.list https://packages.lunarg.com/vulkan/lunarg-vulkan-focal.list
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
else
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-${{ matrix.vulkan-sdk }}-focal.list https://packages.lunarg.com/vulkan/${{ matrix.vulkan-sdk }}/lunarg-vulkan-${{ matrix.vulkan-sdk }}-focal.list
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-${{ matrix.vulkan-sdk }}-jammy.list https://packages.lunarg.com/vulkan/${{ matrix.vulkan-sdk }}/lunarg-vulkan-${{ matrix.vulkan-sdk }}-jammy.list
fi
# For GCC-13
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/ppa
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
# Update package lists
sudo apt-get update -qq
Expand Down Expand Up @@ -116,7 +118,7 @@ jobs:
cxx: "cl"
}
# note: if a specific vulkan version needs testing, you can add it here:
vulkan-sdk: ["latest", "1.3.216.0"]
vulkan-sdk: ["latest", "1.3.243.0"]

steps:
# IMPORTANT: apparently checkout@v3 pulls to ${{ github.event.repository.name }}/${{ github.event.repository.name }} instead of just ${{ github.event.repository.name }} on windows
Expand Down Expand Up @@ -177,7 +179,7 @@ jobs:
cxx: "cl"
}
# note: if a specific vulkan version needs testing, you can add it here:
vulkan-sdk: ["latest", "1.3.216.0"]
vulkan-sdk: ["latest", "1.3.243.0"]

steps:
# IMPORTANT: apparently checkout@v3 pulls to ${{ github.event.repository.name }}/${{ github.event.repository.name }} instead of just ${{ github.event.repository.name }} on windows
Expand Down
2 changes: 1 addition & 1 deletion auto_vk
Submodule auto_vk updated 1 files
+1 −1 README.md
2 changes: 1 addition & 1 deletion auto_vk_toolkit/include/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace avk
float bottom_border() const { return mBottom; }

// sets the projection matrix
camera& set_projection_matrix(const glm::mat4& aMatrix);
camera& set_projection_matrix(const glm::mat4& aMatrix, avk::projection_type aProjectionType = avk::projection_type::unknown);
// Constructs and sets a perspective projection matrix with the given parameters
camera& set_perspective_projection(float aFov, float aAspect, float aNear, float aFar);
// Constructs and sets an orthographic projection matrix with the given parameters
Expand Down
14 changes: 14 additions & 0 deletions auto_vk_toolkit/include/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,19 @@ namespace avk
* @param aMeshIndices Vector of mesh indices to meshes which shall be included in the animation.
*/
animation prepare_animation(uint32_t aAnimationIndex, const std::vector<mesh_index_t>& aMeshIndices);

/** Calculates the tangent space with Auto-Vk-Toolkit's implementation,
* possibly overwriting ASSIMPs tangents/bitangents.
* @param aMeshIndex Mesh which the tangent space shall be computed for
* @param aConfigSourceUV The set of UV coordinates to be used for tangent space calculation
*/
void calculate_tangent_space_for_mesh(mesh_index_t aMeshIndex, uint32_t aConfigSourceUV = 0);

/** Calculates the tangent space with Auto-Vk-Toolkit's implementation for all meshes,
* possibly overwriting ASSIMPs tangents/bitangents.
* @param aConfigSourceUV The set of UV coordinates to be used for tangent space calculation
*/
void calculate_tangent_space_for_all_meshes(uint32_t aConfigSourceUV = 0);

private:
void initialize_materials();
Expand Down Expand Up @@ -418,6 +431,7 @@ namespace avk
std::string mModelPath;
const aiScene* mScene;
std::vector<std::optional<material_config>> mMaterialConfigPerMesh;
std::unordered_map<mesh_index_t, std::tuple<std::vector<glm::vec3>, std::vector<glm::vec3>>> mTangentsAndBitangents;
};

using model = avk::owning_resource<model_t>;
Expand Down
4 changes: 2 additions & 2 deletions auto_vk_toolkit/src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace avk
, mBottom{ 0 }
{}

camera& camera::set_projection_matrix(const glm::mat4& aMatrix)
camera& camera::set_projection_matrix(const glm::mat4& aMatrix, avk::projection_type aProjectionType)
{
mProjectionType = projection_type::unknown;
mProjectionType = aProjectionType;
mProjectionMatrix = aMatrix;
return *this;
}
Expand Down
4 changes: 3 additions & 1 deletion auto_vk_toolkit/src/context_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ namespace avk
void context_vulkan::check_vk_result(VkResult err)
{
const auto& inst = context().vulkan_instance();
#if VK_HEADER_VERSION >= 216
#if VK_HEADER_VERSION >= 290
vk::detail::createResultValueType(static_cast<vk::Result>(err), "check_vk_result");
#elif VK_HEADER_VERSION >= 216
vk::createResultValueType(static_cast<vk::Result>(err), "check_vk_result");
#else
createResultValue(static_cast<vk::Result>(err), inst, "check_vk_result");
Expand Down
186 changes: 164 additions & 22 deletions auto_vk_toolkit/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <sstream>

#include "model.hpp"
#include <assimp/qnan.h>

namespace avk
{
Expand Down Expand Up @@ -600,43 +601,57 @@ namespace avk

std::vector<glm::vec3> model_t::tangents_for_mesh(mesh_index_t aMeshIndex) const
{
const aiMesh* paiMesh = mScene->mMeshes[aMeshIndex];
auto n = paiMesh->mNumVertices;
std::vector<glm::vec3> result;
result.reserve(n);
if (nullptr == paiMesh->mTangents) {
LOG_WARNING(std::format("The mesh at index {} does not contain tangents. Will return (1,0,0) tangents for each vertex.", aMeshIndex));
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(1.f, 0.f, 0.f);
}

if (mTangentsAndBitangents.contains(aMeshIndex)) {
result = std::get<0>(mTangentsAndBitangents.at(aMeshIndex));
}
else {
// We've got tangents. Proceed as planned.
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(paiMesh->mTangents[i][0], paiMesh->mTangents[i][1], paiMesh->mTangents[i][2]);
const aiMesh* paiMesh = mScene->mMeshes[aMeshIndex];
auto n = paiMesh->mNumVertices;
result.reserve(n);
if (nullptr == paiMesh->mTangents) {
LOG_WARNING(std::format("The mesh at index {} does not contain tangents. Will return (1,0,0) tangents for each vertex.", aMeshIndex));
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(1.f, 0.f, 0.f);
}
}
else {
// We've got tangents. Proceed as planned.
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(paiMesh->mTangents[i][0], paiMesh->mTangents[i][1], paiMesh->mTangents[i][2]);
}
}
}

return result;
}

std::vector<glm::vec3> model_t::bitangents_for_mesh(mesh_index_t aMeshIndex) const
{
const aiMesh* paiMesh = mScene->mMeshes[aMeshIndex];
auto n = paiMesh->mNumVertices;
std::vector<glm::vec3> result;
result.reserve(n);
if (nullptr == paiMesh->mBitangents) {
LOG_WARNING(std::format("The mesh at index {} does not contain bitangents. Will return (0,1,0) bitangents for each vertex.", aMeshIndex));
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(0.f, 1.f, 0.f);
}

if (mTangentsAndBitangents.contains(aMeshIndex)) {
result = std::get<1>(mTangentsAndBitangents.at(aMeshIndex));
}
else {
// We've got bitangents. Proceed as planned.
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(paiMesh->mBitangents[i][0], paiMesh->mBitangents[i][1], paiMesh->mBitangents[i][2]);
const aiMesh* paiMesh = mScene->mMeshes[aMeshIndex];
auto n = paiMesh->mNumVertices;
result.reserve(n);
if (nullptr == paiMesh->mBitangents) {
LOG_WARNING(std::format("The mesh at index {} does not contain bitangents. Will return (0,1,0) bitangents for each vertex.", aMeshIndex));
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(0.f, 1.f, 0.f);
}
}
else {
// We've got bitangents. Proceed as planned.
for (decltype(n) i = 0; i < n; ++i) {
result.emplace_back(paiMesh->mBitangents[i][0], paiMesh->mBitangents[i][1], paiMesh->mBitangents[i][2]);
}
}
}

return result;
}

Expand Down Expand Up @@ -1388,4 +1403,131 @@ namespace avk
add_all_to_node_map(aNodeMap, aNode->mChildren[i]);
}
}

void model_t::calculate_tangent_space_for_mesh(mesh_index_t aMeshIndex, uint32_t aConfigSourceUV)
{
mTangentsAndBitangents[aMeshIndex] = std::make_tuple(std::vector<glm::vec3>{}, std::vector<glm::vec3>{});
auto& [meshTang, meshBitang] = mTangentsAndBitangents[aMeshIndex];
auto numVerts = number_of_vertices_for_mesh(aMeshIndex);
// create space for the tangents and bitangents
meshTang.resize(numVerts);
meshBitang.resize(numVerts);

// The following is mostly a copy&paste from ASSIMP's code (but not necessarily from the latest version,
// since at some point, incorrect tangents/bitangents calculation has been introduced, namely s.t.
// the bitangents would always be orthogonal to the tangents. This is wrong.)

const aiMesh* pMesh = mScene->mMeshes[aMeshIndex];

// If the mesh consists of lines and/or points but not of
// triangles or higher-order polygons the normal vectors
// are undefined.
if (!(pMesh->mPrimitiveTypes & (aiPrimitiveType_TRIANGLE | aiPrimitiveType_POLYGON))) {
LOG_INFO("Tangents are undefined for line and point meshes");
return;
}

// what we can check, though, is if the mesh has normals and texture coordinates. That's a requirement
if (pMesh->mNormals == nullptr) {
LOG_ERROR("Failed to compute tangents; need normals");
return;
}
if (aConfigSourceUV >= AI_MAX_NUMBER_OF_TEXTURECOORDS || !pMesh->mTextureCoords[aConfigSourceUV]) {
LOG_ERROR(std::format("Failed to compute tangents; need UV data in channel[{}]", aConfigSourceUV));
return;
}

const float angleEpsilon = 0.9999f;

std::vector<bool> vertexDone(pMesh->mNumVertices, false);
const float qnan = std::numeric_limits<ai_real>::quiet_NaN();

const aiVector3D *meshPos = pMesh->mVertices;
const aiVector3D *meshNorm = pMesh->mNormals;
const aiVector3D *meshTex = pMesh->mTextureCoords[aConfigSourceUV];

// calculate the tangent and bitangent for every face
for (unsigned int a = 0; a < pMesh->mNumFaces; a++) {
const aiFace &face = pMesh->mFaces[a];
if (face.mNumIndices < 3) {
// There are less than three indices, thus the tangent vector
// is not defined. We are finished with these vertices now,
// their tangent vectors are set to qnan.
for (unsigned int i = 0; i < face.mNumIndices; ++i) {
unsigned int idx = face.mIndices[i];
vertexDone[idx] = true;
meshTang[idx] = to_vec3(aiVector3D(qnan));
meshBitang[idx] = to_vec3(aiVector3D(qnan));
}

continue;
}

// triangle or polygon... we always use only the first three indices. A polygon
// is supposed to be planar anyways....
// FIXME: (thom) create correct calculation for multi-vertex polygons maybe?
const unsigned int p0 = face.mIndices[0], p1 = face.mIndices[1], p2 = face.mIndices[2];

// position differences p1->p2 and p1->p3
aiVector3D v = meshPos[p1] - meshPos[p0], w = meshPos[p2] - meshPos[p0];

// texture offset p1->p2 and p1->p3
float sx = meshTex[p1].x - meshTex[p0].x, sy = meshTex[p1].y - meshTex[p0].y;
float tx = meshTex[p2].x - meshTex[p0].x, ty = meshTex[p2].y - meshTex[p0].y;
float dirCorrection = (tx * sy - ty * sx) < 0.0f ? -1.0f : 1.0f;
// when t1, t2, t3 in same position in UV space, just use default UV direction.
if (sx * ty == sy * tx) {
sx = 0.0;
sy = 1.0;
tx = 1.0;
ty = 0.0;
}

// tangent points in the direction where to positive X axis of the texture coord's would point in model space
// bitangent's points along the positive Y axis of the texture coord's, respectively
aiVector3D tangent, bitangent;
tangent.x = (w.x * sy - v.x * ty) * dirCorrection;
tangent.y = (w.y * sy - v.y * ty) * dirCorrection;
tangent.z = (w.z * sy - v.z * ty) * dirCorrection;
bitangent.x = (w.x * sx - v.x * tx) * dirCorrection;
bitangent.y = (w.y * sx - v.y * tx) * dirCorrection;
bitangent.z = (w.z * sx - v.z * tx) * dirCorrection;

// store for every vertex of that face
for (unsigned int b = 0; b < face.mNumIndices; ++b) {
unsigned int p = face.mIndices[b];

// project tangent and bitangent into the plane formed by the vertex' normal
aiVector3D localTangent = tangent - meshNorm[p] * (tangent * meshNorm[p]);
aiVector3D localBitangent = bitangent - meshNorm[p] * (bitangent * meshNorm[p]);
localTangent.NormalizeSafe();
localBitangent.NormalizeSafe();

// reconstruct tangent/bitangent according to normal and bitangent/tangent when it's infinite or NaN.
bool invalid_tangent = is_special_float(localTangent.x) || is_special_float(localTangent.y) || is_special_float(localTangent.z);
bool invalid_bitangent = is_special_float(localBitangent.x) || is_special_float(localBitangent.y) || is_special_float(localBitangent.z);
if (invalid_tangent != invalid_bitangent) {
if (invalid_tangent) {
localTangent = meshNorm[p] ^ localBitangent;
localTangent.NormalizeSafe();
} else {
localBitangent = localTangent ^ meshNorm[p];
localBitangent.NormalizeSafe();
}
}

// and write it into the mesh.
meshTang[p] = to_vec3(localTangent);
meshBitang[p] = to_vec3(localBitangent);
}
}
}

void model_t::calculate_tangent_space_for_all_meshes(uint32_t aConfigSourceUV)
{
auto n = mScene->mNumMeshes;
for (decltype(n) i = 0; i < n; ++i) {
calculate_tangent_space_for_mesh(i, aConfigSourceUV);
}
}
}
8 changes: 4 additions & 4 deletions cmake/assimp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ if(UNIX)
endif()
endif (NOT assimp_FOUND OR avk_toolkit_ForceAssimpBuild)
else()
set(avk_toolkit_AssimpReleaseDLLPath "${PROJECT_SOURCE_DIR}/external/release/bin/x64/assimp-vc140-mt.dll")
set(avk_toolkit_AssimpDebugDLLPath "${PROJECT_SOURCE_DIR}/external/debug/bin/x64/assimp-vc140-mt.dll")
set(avk_toolkit_AssimpReleaseLIBPath "${PROJECT_SOURCE_DIR}/external/release/lib/x64/assimp-vc140-mt.lib")
set(avk_toolkit_AssimpDebugLIBPath "${PROJECT_SOURCE_DIR}/external/debug/lib/x64/assimp-vc140-mt.lib")
set(avk_toolkit_AssimpReleaseDLLPath "${PROJECT_SOURCE_DIR}/external/release/bin/x64/assimp-vc143-mt.dll")
set(avk_toolkit_AssimpDebugDLLPath "${PROJECT_SOURCE_DIR}/external/debug/bin/x64/assimp-vc143-mt.dll")
set(avk_toolkit_AssimpReleaseLIBPath "${PROJECT_SOURCE_DIR}/external/release/lib/x64/assimp-vc143-mt.lib")
set(avk_toolkit_AssimpDebugLIBPath "${PROJECT_SOURCE_DIR}/external/debug/lib/x64/assimp-vc143-mt.lib")

add_library(assimp::assimp SHARED IMPORTED)
set_target_properties(assimp::assimp PROPERTIES
Expand Down
Loading

0 comments on commit 2922ccf

Please sign in to comment.