Skip to content

Commit

Permalink
Merge pull request #221 from doodlum/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Mar 15, 2024
2 parents 22b95fe + 2e707e4 commit 72b2adf
Show file tree
Hide file tree
Showing 129 changed files with 6,220 additions and 2,071 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
contents: write

env:
VCPKG_COMMIT_ID: 417119555f155f6044dec7a379cd25466e339873
VCPKG_COMMIT_ID: e6aabd1415a1fc9f5e76deb3c5a40e27300aef2a

jobs:
compile:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
dist/
.vs*/
CMakeUserPresets.json
CMakeUserPresets.json
shadertoolsconfig.json
9 changes: 8 additions & 1 deletion BuildRelease.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@echo off

cmake -S . --preset=ALL --check-stamp-file "build\CMakeFiles\generate.stamp"
set preset="ALL"
if NOT "%1" == "" (
set preset=%1
)

echo Running preset %preset%

cmake -S . --preset=%preset% --check-stamp-file "build\CMakeFiles\generate.stamp"
if %ERRORLEVEL% NEQ 0 exit 1
cmake --build build --config Release
if %ERRORLEVEL% NEQ 0 exit 1
Expand Down
99 changes: 83 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21)

project(
CommunityShaders
VERSION 0.7.4
VERSION 0.8.0
LANGUAGES CXX
)

Expand All @@ -14,8 +14,10 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
message("Options:")
option(AUTO_PLUGIN_DEPLOYMENT "Copy the build output and addons to env:CommunityShadersOutputDir." OFF)
option(ZIP_TO_DIST "Zip the base mod and addons to their own 7z file in dist." ON)
option(AIO_ZIP_TO_DIST "Zip the base mod and addons to a AIO 7z file in dist." ON)
message("\tAuto plugin deployment: ${AUTO_PLUGIN_DEPLOYMENT}")
message("\tZip to dist: ${ZIP_TO_DIST}")
message("\tAIO Zip to dist: ${AIO_ZIP_TO_DIST}")

# #######################################################################################################################
# # Add CMake features
Expand All @@ -32,10 +34,12 @@ find_package(nlohmann_json CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(EASTL CONFIG REQUIRED)
find_package(directxtk CONFIG REQUIRED)
find_package(directxtex CONFIG REQUIRED)
find_path(CLIB_UTIL_INCLUDE_DIRS "ClibUtil/utils.hpp")
find_package(pystring CONFIG REQUIRED)
find_package(cppwinrt CONFIG REQUIRED)

find_package(unordered_dense CONFIG REQUIRED)
find_package(efsw CONFIG REQUIRED)
target_include_directories(
${PROJECT_NAME}
PRIVATE
Expand All @@ -55,7 +59,10 @@ target_link_libraries(
imgui::imgui
EASTL
Microsoft::DirectXTK
Microsoft::DirectXTex
pystring::pystring
unordered_dense::unordered_dense
efsw::efsw
)

# https://gitlab.kitware.com/cmake/cmake/-/issues/24922#note_1371990
Expand All @@ -78,26 +85,70 @@ if(MSVC_VERSION GREATER_EQUAL 1936 AND MSVC_IDE) # 17.6+
]==] @ONLY)
endif()

# #######################################################################################################################
# # Feature version detection
# #######################################################################################################################
file(GLOB_RECURSE FEATURE_CONFIG_FILES
LIST_DIRECTORIES false
CONFIGURE_DEPENDS
"features/*/Shaders/Features/*.ini"
)

foreach(FEATURE_PATH ${FEATURE_CONFIG_FILES})
get_filename_component(FEATURE ${FEATURE_PATH} NAME_WE)
file(READ "${FEATURE_PATH}" CONFIG_VALUE)
string(REGEX MATCH "Version = ([0-9]*)-([0-9]*)-([0-9]*)" _ ${CONFIG_VALUE})
set(ver_major ${CMAKE_MATCH_1})
set(ver_minor ${CMAKE_MATCH_2})
set(ver_patch ${CMAKE_MATCH_3})
list(APPEND FEATURE_VERSIONS \t\t{\ \"${FEATURE}\"sv,\ {${ver_major},${ver_minor},${ver_patch}}\ })
endforeach()

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${FEATURE_CONFIG_FILES}")

string(REPLACE ";" ",\n" FEATURE_VERSIONS "${FEATURE_VERSIONS}")

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FeatureVersions.h.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/FeatureVersions.h
@ONLY
)

target_sources(
"${PROJECT_NAME}"
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/cmake/FeatureVersions.h
)

# #######################################################################################################################
# # Automatic deployment
# #######################################################################################################################
file(GLOB FEATURE_PATHS LIST_DIRECTORIES true ${CMAKE_SOURCE_DIR}/features/*)
string(TIMESTAMP UTC_NOW "%Y-%m-%dT%H-%MZ" UTC)

if(AUTO_PLUGIN_DEPLOYMENT OR AIO_ZIP_TO_DIST)
set(AIO_DIR "${CMAKE_CURRENT_BINARY_DIR}/aio")
message("Copying package folder with dll/pdb with all features to ${AIO_DIR}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${AIO_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${AIO_DIR}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${AIO_DIR}/SKSE/Plugins/"
)

foreach(FEATURE_PATH ${FEATURE_PATHS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATH} "${AIO_DIR}"
)
endforeach()
endif()

# Automatic deployment to CommunityShaders output directory.
if(AUTO_PLUGIN_DEPLOYMENT)
foreach(DEPLOY_TARGET $ENV{CommunityShadersOutputDir})
message("Copying package folder with dll/pdb with all features to ${DEPLOY_TARGET}")
message("Copying AIO to ${DEPLOY_TARGET}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/package "${DEPLOY_TARGET}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${DEPLOY_TARGET}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${DEPLOY_TARGET}/SKSE/Plugins/"
COMMAND ${CMAKE_COMMAND} -E copy_directory ${AIO_DIR} "${DEPLOY_TARGET}"
)

foreach(FEATURE_PATH ${FEATURE_PATHS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FEATURE_PATH} "${DEPLOY_TARGET}"
)
endforeach()
endforeach()

if(NOT DEFINED ENV{CommunityShadersOutputDir})
Expand All @@ -108,7 +159,6 @@ endif()
# Zip base CommunityShaders and all addons as their own 7z in dist folder
if(ZIP_TO_DIST)
set(ZIP_DIR "${CMAKE_CURRENT_BINARY_DIR}/zip")
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/test/)
add_custom_target(build-time-make-directory ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
Expand All @@ -121,7 +171,7 @@ if(ZIP_TO_DIST)
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:${PROJECT_NAME}> "${ZIP_DIR}/SKSE/Plugins/"
)

set(TARGET_ZIP "${PROJECT_NAME}.7z")
set(TARGET_ZIP "${PROJECT_NAME}-${UTC_NOW}.7z")
message("Zipping ${ZIP_DIR} to ${CMAKE_SOURCE_DIR}/dist/${TARGET_ZIP}")
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${TARGET_ZIP} --format=7zip -- .
Expand All @@ -130,10 +180,27 @@ if(ZIP_TO_DIST)

foreach(FEATURE_PATH ${FEATURE_PATHS})
get_filename_component(FEATURE ${FEATURE_PATH} NAME)
message("Zipping ${FEATURE_PATH} to ${CMAKE_SOURCE_DIR}/dist/${FEATURE}.7z")
message("Zipping ${FEATURE_PATH} to ${CMAKE_SOURCE_DIR}/dist/${FEATURE}-${UTC_NOW}.7z")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${FEATURE}.7z --format=7zip -- .
COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${FEATURE}-${UTC_NOW}.7z --format=7zip -- .
WORKING_DIRECTORY ${FEATURE_PATH}
)
endforeach()
endif()

# Create a AIO zip for easier testing
if(AIO_ZIP_TO_DIST)
if(NOT ZIP_TO_DIST)
add_custom_target(build-time-make-directory ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_DIR}" ${CMAKE_SOURCE_DIR}/dist
)
endif()

set(TARGET_AIO_ZIP "${PROJECT_NAME}_AIO-${UTC_NOW}.7z")
message("Zipping ${AIO_DIR} to ${CMAKE_SOURCE_DIR}/dist/${TARGET_AIO_ZIP}")
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar cf ${CMAKE_SOURCE_DIR}/dist/${TARGET_AIO_ZIP} --format=7zip -- .
WORKING_DIRECTORY ${AIO_DIR}
)
endif()
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ cd skyrim-community-shaders
.\BuildRelease.bat
```

### CMAKE Options (optional)
If you want an example CMakeUserPreset to start off with you can copy the `CMakeUserPresets.json.template` -> `CMakeUserPresets.json`
#### AUTO_PLUGIN_DEPLOYMENT
* This option is default `"OFF"`
* Make sure `"AUTO_PLUGIN_DEPLOYMENT"` is set to `"ON"` in `CMakeUserPresets.json`
* Change the `"CommunityShadersOutputDir"` value to match your desired outputs, if you want multiple folders you can separate them by `;` is shown in the template example
#### AIO_ZIP_TO_DIST
* This option is default `"OFF"`
* Make sure `"AIO_ZIP_TO_DIST"` is set to `"ON"` in `CMakeUserPresets.json`
* This will create a `CommunityShaders_AIO.7z` archive in /dist containing all features and base mod
#### ZIP_TO_DIST
* This option is default `"ON"`
* Make sure `"ZIP_TO_DIST"` is set to `"ON"` in `CMakeUserPresets.json`
* This will create a zip for each feature and one for the base Community shaders in /dist containing

When using custom preset you can call BuildRelease.bat with an parameter to specify which preset to configure eg:
`.\BuildRelease.bat ALL-WITH-AUTO-DEPLOYMENT`

When switching between different presets you might need to remove the build folder

## License

### Default
Expand Down
11 changes: 11 additions & 0 deletions cmake/FeatureVersions.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace FeatureVersions
{
using namespace std::literals::string_view_literals;

static const std::map<std::string_view, REL::Version> FEATURE_MINIMAL_VERSIONS
{
@FEATURE_VERSIONS@
};
}
2 changes: 1 addition & 1 deletion extern/CommonLibSSE-NG
Submodule CommonLibSSE-NG updated 126 files
50 changes: 50 additions & 0 deletions features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
struct PerPassCloudShadow
{
uint EnableCloudShadows;

float CloudHeight;
float PlanetRadius;

float EffectMix;

float TransparencyPower;
float AbsorptionAmbient;

float RcpHPlusR;
};

StructuredBuffer<PerPassCloudShadow> perPassCloudShadow : register(t23);
TextureCube<float4> cloudShadows : register(t40);

float3 getCloudShadowSampleDir(float3 rel_pos, float3 eye_to_sun)
{
float r = perPassCloudShadow[0].PlanetRadius;
float3 p = (rel_pos + float3(0, 0, r)) * perPassCloudShadow[0].RcpHPlusR;
float dotprod = dot(p, eye_to_sun);
float lengthsqr = dot(p, p);
float t = -dotprod + sqrt(dotprod * dotprod - dot(p, p) + 1);
float3 v = (p + eye_to_sun * t) * (r + perPassCloudShadow[0].CloudHeight) - float3(0, 0, r);
v = normalize(v);
return v;
}

float3 getCloudShadowSampleDirFlatEarth(float3 rel_pos, float3 eye_to_sun)
{
float3 p = rel_pos / perPassCloudShadow[0].CloudHeight;
float dotprod = dot(p, eye_to_sun);
float t = -dotprod + sqrt(dotprod * dotprod - dot(p, p) + 1);
float3 v = p + eye_to_sun * t;
v = normalize(v); // optional
return v;
}

float3 getCloudShadowMult(float3 rel_pos, float3 eye_to_sun, SamplerState samp)
{
// float3 cloudSampleDir = getCloudShadowSampleDirFlatEarth(rel_pos, eye_to_sun).xyz;
float3 cloudSampleDir = getCloudShadowSampleDir(rel_pos, eye_to_sun).xyz;

float4 cloudCubeSample = cloudShadows.Sample(samp, cloudSampleDir);
float alpha = pow(saturate(cloudCubeSample.w), perPassCloudShadow[0].TransparencyPower);

return lerp(1.0, 1.0 - alpha, perPassCloudShadow[0].EffectMix);
}
2 changes: 2 additions & 0 deletions features/Cloud Shadows/Shaders/Features/CloudShadows.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Info]
Version = 1-1-0
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ float GetMipLevel(float2 coords, Texture2D<float4> tex)
}

#if defined(LANDSCAPE)
float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 viewDir, float3x3 tbn, Texture2D<float4> tex, SamplerState texSampler, uint channel, float blend)
float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 viewDir, float3x3 tbn, Texture2D<float4> tex, SamplerState texSampler, uint channel, float blend, out float pixelOffset)
#else
float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 viewDir, float3x3 tbn, Texture2D<float4> tex, SamplerState texSampler, uint channel)
float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 viewDir, float3x3 tbn, Texture2D<float4> tex, SamplerState texSampler, uint channel, out float pixelOffset)
#endif
{
float3 viewDirTS = mul(tbn, viewDir);
pixelOffset = 0.5;

float3 viewDirTS = normalize(mul(tbn, viewDir));
distance /= (float)perPassParallax[0].MaxDistance;

viewDirTS.z = ((viewDirTS.z * 0.5) + 0.5);
viewDirTS.xy /= viewDirTS.z;

float nearQuality = smoothstep(0.0, perPassParallax[0].CRPMRange, distance);
float nearBlendToMid = smoothstep(perPassParallax[0].CRPMRange - perPassParallax[0].BlendRange, perPassParallax[0].CRPMRange, distance);
float midBlendToFar = smoothstep(1.0 - perPassParallax[0].BlendRange, 1.0, distance);
Expand All @@ -65,24 +70,22 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v
# if defined(LANDSCAPE)
float quality = min(1.0 - nearQuality, pow(saturate(blend), 0.5));
if (perPassParallax[0].EnableHighQuality) {
numSteps = round(lerp(4, 32, quality));
numSteps = max(1, round(32 * quality));
numSteps = clamp((numSteps + 3) & ~0x03, 4, 32);
} else {
numSteps = round(lerp(4, 16, quality));
numSteps = max(1, round(16 * quality));
numSteps = clamp((numSteps + 3) & ~0x03, 4, 16);
}
# else
if (perPassParallax[0].EnableHighQuality) {
numSteps = round(lerp(4, 32, 1.0 - nearQuality));
numSteps = max(1, round(32 * (1.0 - nearQuality)));
numSteps = clamp((numSteps + 3) & ~0x03, 4, 32);
} else {
numSteps = round(lerp(4, 16, 1.0 - nearQuality));
numSteps = max(1, round(16 * (1.0 - nearQuality)));
numSteps = clamp((numSteps + 3) & ~0x03, 4, 16);
}
# endif
#endif
float heightCorrectionScale = ((-1.0 * viewDirTS.z) + 2.0);

float stepSize = 1.0 / ((float)numSteps + 1.0);

float2 offsetPerStep = viewDirTS.xy * float2(maxHeight, maxHeight) * stepSize.xx;
Expand Down Expand Up @@ -113,9 +116,6 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v
currHeight.z = tex.SampleLevel(texSampler, currentOffset[1].xy, mipLevel)[channel];
currHeight.w = tex.SampleLevel(texSampler, currentOffset[1].zw, mipLevel)[channel];

currHeight.xyzw -= 0.5;
currHeight.xyzw = heightCorrectionScale * currHeight.xyzw + 0.5;

bool4 testResult = currHeight >= currentBound;
[branch] if (any(testResult))
{
Expand Down Expand Up @@ -191,15 +191,18 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v
}

float offset = (1.0 - parallaxAmount) * -maxHeight + minHeight;
pixelOffset = parallaxAmount;
output = viewDirTS.xy * offset + coords.xy;
} else {
float offset = (1.0 - pt1.x) * -maxHeight + minHeight;
pixelOffset = pt1.x;
output = viewDirTS.xy * offset + coords.xy;
}

if (nearBlendToMid > 0.0) {
float height = tex.Sample(texSampler, coords.xy)[channel];
height = height * maxHeight - minHeight;
pixelOffset = lerp(pt1.x, height, nearBlendToMid);
output = lerp(output, viewDirTS.xy * height.xx + coords.xy, nearBlendToMid);
}
} else if (midBlendToFar < 1.0) {
Expand All @@ -208,6 +211,7 @@ float2 GetParallaxCoords(float distance, float2 coords, float mipLevel, float3 v
maxHeight *= (1 - midBlendToFar);
minHeight *= (1 - midBlendToFar);
}
pixelOffset = height;
height = height * maxHeight - minHeight;
output = viewDirTS.xy * height.xx + coords.xy;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[Info]
Version = 1-0-2
Version = 1-0-3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 72b2adf

Please sign in to comment.