Skip to content

Commit

Permalink
Merge pull request #4 from hakasapl/main
Browse files Browse the repository at this point in the history
Catch up txst patching
  • Loading branch information
hakasapl authored Jul 22, 2024
2 parents f674a4b + 2e7f251 commit f69f899
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.4.2] - 2024-07-22

- ParallaxGen no longer patches LOD
- Added dynamic cubemaps support

## [0.4.1] - 2024-07-18

- Fixed already generated complex parallax maps regenerating if a heightmap was also included
Expand Down
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(PROJECT_NAME "ParallaxGen")
set(PROJECT_URI "com.github.hakasapl.ParallaxGen")

# Initialize Project
set(PARALLAXGEN_VERSION 0.4.1)
set(PARALLAXGEN_VERSION 0.4.2)
project(${PROJECT_NAME} VERSION ${PARALLAXGEN_VERSION})

# Define preprocessor macro with the version number
Expand Down Expand Up @@ -82,7 +82,7 @@ endfunction()
find_package(spdlog REQUIRED CONFIG)
find_package(bsa REQUIRED CONFIG)
find_package(CLI11 REQUIRED CONFIG)
find_package(Boost REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem)
find_package(directxtk REQUIRED)
find_package(directxtex REQUIRED CONFIG)
find_package(miniz REQUIRED CONFIG)
Expand All @@ -107,7 +107,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
spdlog::spdlog
bsa::bsa
CLI11::CLI11
Boost::boost
${Boost_LIBRARIES}
nifly
miniz::miniz
Microsoft::DirectXTex
Expand Down Expand Up @@ -139,6 +139,9 @@ endforeach(FILE)

add_dependencies(${PROJECT_NAME} shaders)

# Copy assets
file(COPY ${CMAKE_SOURCE_DIR}/assets DESTINATION ${CMAKE_BINARY_DIR})

# Install the executable and DLLs
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION . )
install(FILES $<TARGET_RUNTIME_DLLS:${PROJECT_NAME}> DESTINATION . )
Expand All @@ -149,3 +152,6 @@ install(FILES ${CMAKE_BINARY_DIR}/zlib1.dll DESTINATION . )

# Copy compiled shaders to install
install(FILES ${CMAKE_BINARY_DIR}/MergeToComplexMaterial.cso DESTINATION . )

# Copy assets to install
install(DIRECTORY ${CMAKE_BINARY_DIR}/assets DESTINATION . )
Binary file added assets/dynamic1pxcubemap_black_CS.dds
Binary file not shown.
Binary file added assets/dynamic1pxcubemap_black_ENB.dds
Binary file not shown.
1 change: 1 addition & 0 deletions include/BethesdaDirectory/BethesdaDirectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class BethesdaDirectory {
// Helpers
static std::filesystem::path getPathLower(const std::filesystem::path path);
static bool pathEqualityIgnoreCase(const std::filesystem::path path1, const std::filesystem::path path2);
static bool checkIfAnyComponentIs(const std::filesystem::path path, const std::vector<std::wstring>& components);

private:
// Adds BSA files to the file map
Expand Down
4 changes: 3 additions & 1 deletion include/ParallaxGen/ParallaxGen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ParallaxGen
// which texture indices to search when mapping mesh shapes to parallax maps
static inline const std::array<uint32_t, 2> texture_maps_idx_search = { 0, 1 };

static inline const std::vector<std::wstring> dynCubemap_ignore_list = { L"armor", L"weapons" };

// bools to ignore parallax and/or complex material
bool ignore_parallax;
bool ignore_complex_material;
Expand Down Expand Up @@ -63,7 +65,7 @@ class ParallaxGen
// processes a NIF file (enable parallax if needed)
void processNIF(const std::filesystem::path& nif_file, std::vector<std::filesystem::path>& heightMaps, std::vector<std::filesystem::path>& complexMaterialMaps);
// enables complex material on a shape in a NIF
bool enableComplexMaterialOnShape(nifly::NifFile& nif, nifly::NiShape* shape, nifly::NiShader* shader, const std::string& search_prefix);
bool enableComplexMaterialOnShape(nifly::NifFile& nif, nifly::NiShape* shape, nifly::NiShader* shader, const std::string& search_prefix, bool dynCubemaps);
// enables parallax on a shape in a NIF
bool enableParallaxOnShape(nifly::NifFile& nif, nifly::NiShape* shape, nifly::NiShader* shader, const std::string& search_prefix);
// checks aspectRatio of two DDS files
Expand Down
6 changes: 5 additions & 1 deletion include/ParallaxGenDirectory/ParallaxGenDirectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ParallaxGenDirectory : public BethesdaDirectory {
L"effects",
L"interface",
L"loadscreenart",
L"lod",
L"lod",
L"magic",
L"markers",
L"mps",
Expand All @@ -30,6 +30,8 @@ class ParallaxGenDirectory : public BethesdaDirectory {
std::vector<std::filesystem::path> meshes;

public:
static inline const std::filesystem::path default_cubemap_path = "textures\\cubemaps\\dynamic1pxcubemap_black.dds";

// constructor - calls the BethesdaDirectory constructor
ParallaxGenDirectory(BethesdaGame bg);

Expand All @@ -50,6 +52,8 @@ class ParallaxGenDirectory : public BethesdaDirectory {
bool isComplexMaterialMap(std::filesystem::path path) const;
bool isMesh(std::filesystem::path) const;

bool defCubemapExists();

// get methods
const std::vector<std::filesystem::path> getHeightMaps() const;
const std::vector<std::filesystem::path> getComplexMaterialMaps() const;
Expand Down
31 changes: 16 additions & 15 deletions src/BethesdaDirectory/BethesdaDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,9 @@ vector<fs::path> BethesdaDirectory::findFilesBySuffix(const string_view suffix,

if (boost::algorithm::ends_with(key.wstring(), suffix)) {
// check if any component of the path is in the blocklist
bool block = false;
for (wstring block_path : path_blocklist) {
for (const auto& component : key) {
if (block_path == component.wstring()) {
block = true;
break;
}
}

if (block) {
break;
}
}

if (block) {
bool blocked = checkIfAnyComponentIs(cur_file_path, path_blocklist);
if (blocked)
{
continue;
}

Expand Down Expand Up @@ -558,3 +546,16 @@ void BethesdaDirectory::updateFileMap(const fs::path& file_path, shared_ptr<Beth

fileMap[lower_path] = new_bfile;
}

bool BethesdaDirectory::checkIfAnyComponentIs(const fs::path path, const vector<wstring>& components)
{
for (const auto& component : path) {
for (wstring comp : components) {
if (boost::iequals(component.wstring(), comp)) {
return true;
}
}
}

return false;
}
27 changes: 25 additions & 2 deletions src/ParallaxGen/ParallaxGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void ParallaxGen::upgradeShaders()

// add newly created file to complexMaterialMaps for later processing
pgd->addComplexMaterialMap(complex_map_path);

spdlog::debug(L"Added complex material map: {}", complex_map_path.wstring());
}

finished_task++;
Expand Down Expand Up @@ -310,8 +312,14 @@ void ParallaxGen::processNIF(const fs::path& nif_file, vector<fs::path>& heightM
continue;
}

// check if this is weapon or armor
bool dynCubemaps = true;
if (pgd->checkIfAnyComponentIs(nif_file, dynCubemap_ignore_list) || pgd->checkIfAnyComponentIs(search_prefix, dynCubemap_ignore_list)) {
dynCubemaps = false;
}

// Enable complex parallax for this shape!
nif_modified |= enableComplexMaterialOnShape(nif, shape, shader, search_prefix);
nif_modified |= enableComplexMaterialOnShape(nif, shape, shader, search_prefix, dynCubemaps);
break; // don't check anything else
}

Expand Down Expand Up @@ -357,7 +365,7 @@ void ParallaxGen::processNIF(const fs::path& nif_file, vector<fs::path>& heightM
}
}

bool ParallaxGen::enableComplexMaterialOnShape(NifFile& nif, NiShape* shape, NiShader* shader, const string& search_prefix)
bool ParallaxGen::enableComplexMaterialOnShape(NifFile& nif, NiShape* shape, NiShader* shader, const string& search_prefix, bool dynCubemaps)
{
// enable complex material on shape
bool changed = false;
Expand Down Expand Up @@ -396,6 +404,21 @@ bool ParallaxGen::enableComplexMaterialOnShape(NifFile& nif, NiShape* shape, NiS
nif.SetTextureSlot(shape, new_env_map, 5);
changed = true;
}

// Dynamic cubemaps (if enabled)
if (dynCubemaps) {
// add cubemap to slot
string cubemap;
uint32_t cubemap_result = nif.GetTextureSlot(shape, cubemap, 4);
// TODO figure out a better way to do this
if (cubemap.empty()) {
// only fill if cubemap is empty, otherwise just carry it forward
string new_cubemap = ParallaxGenDirectory::default_cubemap_path.string();
nif.SetTextureSlot(shape, new_cubemap, 4);
changed = true;
}
}

return changed;
}

Expand Down
5 changes: 5 additions & 0 deletions src/ParallaxGenDirectory/ParallaxGenDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ bool ParallaxGenDirectory::isMesh(filesystem::path path) const
return find(meshes.begin(), meshes.end(), getPathLower(path)) != meshes.end();
}

bool ParallaxGenDirectory::defCubemapExists()
{
return isFile(default_cubemap_path);
}

const vector<filesystem::path> ParallaxGenDirectory::getHeightMaps() const
{
return heightMaps;
Expand Down
19 changes: 19 additions & 0 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>

#include "BethesdaGame/BethesdaGame.hpp"
#include "ParallaxGen/ParallaxGen.hpp"
Expand Down Expand Up @@ -230,6 +231,24 @@ int main(int argc, char** argv) {
// Populate file map from data directory
pgd.populateFileMap();

// Install default cubemap file if needed
if (!ignore_complex_material) {
// install default cubemap file if needed
if (!pgd.defCubemapExists()) {
spdlog::info("Installing default cubemap file");

// Create Directory
filesystem::path output_cubemap_dir = output_dir / ParallaxGenDirectory::default_cubemap_path.parent_path();
filesystem::create_directories(output_cubemap_dir);

boost::filesystem::path asset_path = boost::filesystem::path(EXE_PATH) / L"assets/dynamic1pxcubemap_black_ENB.dds";
boost::filesystem::path output_path = boost::filesystem::path(output_dir) / ParallaxGenDirectory::default_cubemap_path;

// Move File
boost::filesystem::copy_file(asset_path, output_path, boost::filesystem::copy_options::overwrite_existing);
}
}

// Build file vectors
if (!ignore_parallax || (ignore_parallax && upgrade_shaders)) {
pgd.findHeightMaps();
Expand Down

0 comments on commit f69f899

Please sign in to comment.