Skip to content

Commit

Permalink
Merge branch 'dev' into dev-tracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentalimbed committed Aug 4, 2024
2 parents a5b2ebb + 1cbcc82 commit c9ef61e
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 318 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
submodules: recursive

- uses: ilammy/msvc-dev-cmd@v1.10.0

Expand All @@ -28,7 +28,7 @@ jobs:
run: cmake -S . --preset=ALL --check-stamp-file "build\CMakeFiles\generate.stamp"

- name: cmake build
run: cmake --build build --config Release
run: cmake --build build/ALL --config Release

- name: create a tagged release and upload the archive
uses: ncipollo/release-action@v1
Expand Down
4 changes: 2 additions & 2 deletions BuildRelease.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ if NOT "%1" == "" (

echo Running preset %preset%

cmake -S . --preset=%preset% --check-stamp-file "build\CMakeFiles\generate.stamp"
cmake -S . --preset=%preset% --check-stamp-file "build\%preset%\CMakeFiles\generate.stamp"
if %ERRORLEVEL% NEQ 0 exit 1
cmake --build build --config Release
cmake --build build/%preset% --config Release
if %ERRORLEVEL% NEQ 0 exit 1

pause
64 changes: 19 additions & 45 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
"cacheVariables": {
"SKSE_SUPPORT_XBYAK": "ON"
},
"binaryDir": "${sourceDir}/build"
"binaryDir": "${sourceDir}/build/${presetName}"
},
{
"name": "vcpkg",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "STRING",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
},
"VCPKG_OVERLAY_PORTS": {
"type": "STRING",
"value": "${sourceDir}/cmake/ports/"
},
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/ports/",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
}
},
Expand Down Expand Up @@ -53,7 +47,8 @@
}
},
{
"name": "AE",
"name": "skyrim",
"hidden": true,
"cacheVariables": {
"BUILD_SKYRIM": true,
"ENABLE_SKYRIM_AE": "ON",
Expand All @@ -68,85 +63,64 @@
"msvc"
]
},
{
"name": "AE",
"cacheVariables": {
"ENABLE_SKYRIM_AE": "ON",
"ENABLE_SKYRIM_SE": "OFF",
"ENABLE_SKYRIM_VR": "OFF"
},
"inherits": "skyrim"
},
{
"name": "SE",
"cacheVariables": {
"BUILD_SKYRIM": true,
"ENABLE_SKYRIM_AE": "OFF",
"ENABLE_SKYRIM_SE": "ON",
"ENABLE_SKYRIM_VR": "OFF",
"BUILD_TESTS": "OFF"
},
"inherits": [
"common",
"vcpkg",
"win64",
"msvc"
]
"inherits": "skyrim"
},
{
"name": "VR",
"cacheVariables": {
"BUILD_SKYRIM": true,
"ENABLE_SKYRIM_AE": "OFF",
"ENABLE_SKYRIM_SE": "OFF",
"ENABLE_SKYRIM_VR": "ON",
"BUILD_TESTS": "OFF"
},
"inherits": [
"common",
"vcpkg",
"win64",
"msvc"
]
"inherits": "skyrim"
},
{
"name": "ALL",
"cacheVariables": {
"BUILD_SKYRIM": true,
"ENABLE_SKYRIM_AE": "ON",
"ENABLE_SKYRIM_SE": "ON",
"ENABLE_SKYRIM_VR": "ON",
"BUILD_TESTS": "OFF"
},
"inherits": [
"common",
"vcpkg",
"win64",
"msvc"
]
"inherits": "skyrim"
},
{
"name": "PRE-AE",
"cacheVariables": {
"BUILD_SKYRIM": true,
"ENABLE_SKYRIM_AE": "OFF",
"ENABLE_SKYRIM_SE": "ON",
"ENABLE_SKYRIM_VR": "ON",
"BUILD_TESTS": "OFF"
},
"inherits": [
"common",
"vcpkg",
"win64",
"msvc"
]
"inherits": "skyrim"
},
{
"name": "FLATRIM",
"cacheVariables": {
"BUILD_SKYRIM": true,
"ENABLE_SKYRIM_AE": "ON",
"ENABLE_SKYRIM_SE": "ON",
"ENABLE_SKYRIM_VR": "OFF",
"BUILD_TESTS": "OFF"
},
"inherits": [
"common",
"vcpkg",
"win64",
"msvc"
]
"inherits": "skyrim"
}
]
}
2 changes: 1 addition & 1 deletion extern/CommonLibSSE-NG
Submodule CommonLibSSE-NG updated 823 files
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ cbuffer PerFrame : register(b0)
StructuredBuffer<ClusterAABB> clusters : register(t0);
StructuredBuffer<StructuredLight> lights : register(t1);

RWStructuredBuffer<uint> lightIndexCounter : register(u0); //1
RWStructuredBuffer<uint> lightIndexList : register(u1); //MAX_CLUSTER_LIGHTS * 16^3
RWStructuredBuffer<LightGrid> lightGrid : register(u2); //16^3
RWStructuredBuffer<uint> lightIndexCounter : register(u0);
RWStructuredBuffer<uint> lightIndexList : register(u1);
RWStructuredBuffer<LightGrid> lightGrid : register(u2);

groupshared StructuredLight sharedLights[GROUP_SIZE];

Expand All @@ -25,22 +25,25 @@ bool LightIntersectsCluster(StructuredLight light, ClusterAABB cluster, int eyeI
return dot(dist, dist) <= (light.radius * light.radius);
}

[numthreads(16, 8, 8)] void main(uint3 groupId
: SV_GroupID,
uint3 dispatchThreadId
: SV_DispatchThreadID,
uint3 groupThreadId
: SV_GroupThreadID,
uint groupIndex
: SV_GroupIndex) {
[numthreads(NUMTHREAD_X, NUMTHREAD_Y, NUMTHREAD_Z)] void main(
uint3 groupId
: SV_GroupID, uint3 dispatchThreadId
: SV_DispatchThreadID, uint3 groupThreadId
: SV_GroupThreadID, uint groupIndex
: SV_GroupIndex) {
if (any(dispatchThreadId >= uint3(CLUSTER_BUILDING_DISPATCH_SIZE_X, CLUSTER_BUILDING_DISPATCH_SIZE_Y, CLUSTER_BUILDING_DISPATCH_SIZE_Z)))
return;

if (all(dispatchThreadId == 0)) {
lightIndexCounter[0] = 0;
}

uint visibleLightCount = 0;
uint visibleLightIndices[MAX_CLUSTER_LIGHTS];

uint clusterIndex = groupIndex + GROUP_SIZE * groupId.z;
uint clusterIndex = dispatchThreadId.x +
dispatchThreadId.y * CLUSTER_BUILDING_DISPATCH_SIZE_X +
dispatchThreadId.z * (CLUSTER_BUILDING_DISPATCH_SIZE_X * CLUSTER_BUILDING_DISPATCH_SIZE_Y);

ClusterAABB cluster = clusters[clusterIndex];

Expand All @@ -61,11 +64,13 @@ bool LightIntersectsCluster(StructuredLight light, ClusterAABB cluster, int eyeI
for (uint i = 0; i < batchSize; i++) {
StructuredLight light = lights[i];

if (visibleLightCount < MAX_CLUSTER_LIGHTS && (LightIntersectsCluster(light, cluster)
bool updateCluster = LightIntersectsCluster(light, cluster);
#ifdef VR
|| LightIntersectsCluster(light, cluster, 1)
updateCluster = updateCluster || LightIntersectsCluster(light, cluster, 1);
#endif // VR
)) {
updateCluster = updateCluster && (visibleLightCount < MAX_CLUSTER_LIGHTS);

if (updateCluster) {
visibleLightIndices[visibleLightCount] = lightOffset + i;
visibleLightCount++;
}
Expand All @@ -83,8 +88,11 @@ bool LightIntersectsCluster(StructuredLight light, ClusterAABB cluster, int eyeI
lightIndexList[offset + i] = visibleLightIndices[i];
}

lightGrid[clusterIndex].offset = offset;
lightGrid[clusterIndex].lightCount = visibleLightCount;
LightGrid output = {
offset, visibleLightCount, 0, 0
};

lightGrid[clusterIndex] = output;
}

//https://www.3dgep.com/forward-plus/#Grid_Frustums_Compute_Shader
Expand Down
9 changes: 4 additions & 5 deletions features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

#define GROUP_SIZE (16 * 16 * 4)
#define NUMTHREAD_X 16
#define NUMTHREAD_Y 16
#define NUMTHREAD_Z 4
#define GROUP_SIZE (NUMTHREAD_X * NUMTHREAD_Y * NUMTHREAD_Z)
#define MAX_CLUSTER_LIGHTS 128

#define CLUSTER_BUILDING_DISPATCH_SIZE_X 16
#define CLUSTER_BUILDING_DISPATCH_SIZE_Y 16
#define CLUSTER_BUILDING_DISPATCH_SIZE_Z 16

struct ClusterAABB
{
float4 minPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ StructuredBuffer<StrictLightData> strictLights : register(t53);

bool GetClusterIndex(in float2 uv, in float z, out uint clusterIndex)
{
const uint3 clusterSize = lightLimitFixSettings.ClusterSize.xyz;

if (z < strictLights[0].LightsNear || z > strictLights[0].LightsFar)
return false;

float clampedZ = clamp(z, strictLights[0].LightsNear, strictLights[0].LightsFar);
uint clusterZ = uint(max((log2(z) - log2(strictLights[0].LightsNear)) * 16.0 / log2(strictLights[0].LightsFar / strictLights[0].LightsNear), 0.0));
uint2 clusterDim = ceil(BufferDim / float2(16, 16));
uint3 cluster = uint3(uint2((uv * BufferDim) / clusterDim), clusterZ);
uint clusterZ = uint(max((log2(z) - log2(strictLights[0].LightsNear)) * clusterSize.z / log2(strictLights[0].LightsFar / strictLights[0].LightsNear), 0.0));
uint3 cluster = uint3(uint2(uv * clusterSize.xy), clusterZ);

clusterIndex = cluster.x + (16 * cluster.y) + (16 * 16 * cluster.z);
clusterIndex = cluster.x + (clusterSize.x * cluster.y) + (clusterSize.x * clusterSize.y * cluster.z);
return true;
}

Expand Down
23 changes: 0 additions & 23 deletions features/Skylighting/Shaders/Skylighting/Skylighting.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,6 @@ namespace Skylighting
return vl * step;
}

// http://torust.me/ZH3.pdf
// ZH hallucination that makes skylighting more directional
// skipped luminance because it's single channel
float hallucinateZH3(sh2 sh, float3 normal)
{
const static float factor = sqrt(5.0f / (16.0f * 3.1415926f));

float result = shFuncProductIntegral(sh, shEvaluateCosineLobe(normal)) / shPI; // cosine lobe integral -> pi
if (all(abs(sh.yzw) < 1e-10))
return result;

float3 zonalAxis = normalize(sh.wyz);
float ratio = abs(dot(sh.wyz * float3(-1, -1, 0), zonalAxis)) / sh.x;
float zonalL2Coeff = sh.x * (0.08f * ratio + 0.6f * ratio * ratio);

float fZ = dot(zonalAxis, normal);
float zhDir = factor * (3.0f * fZ * fZ - 1.0f);

result += 0.25f * zonalL2Coeff * zhDir;

return saturate(result);
}

sh2 fauxSpecularLobeSH(float3 N, float3 V, float roughness)
{
// https://www.gdcvault.com/play/1026701/Fast-Denoising-With-Self-Stabilizing
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/AmbientCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ RWTexture2D<half3> DiffuseAmbientRW : register(u1);
# endif

sh2 skylighting = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMS.xyz, normalWS);
half skylightingDiffuse = Skylighting::hallucinateZH3(skylighting, skylightingSettings.DirectionalDiffuse ? normalWS : float3(0, 0, 1));
half skylightingDiffuse = shFuncProductIntegral(skylighting, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? normalWS : float3(0, 0, 1)));
skylightingDiffuse = Skylighting::mixDiffuse(skylightingSettings, skylightingDiffuse);

visibility = skylightingDiffuse;
Expand Down
2 changes: 2 additions & 0 deletions package/Shaders/Common/SharedData.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ struct LightLimitFixSettings
uint EnableLightsVisualisation;
uint LightsVisualisationMode;
uint pad0;

uint4 ClusterSize;
};

# define SL_INCL_STRUCT
Expand Down
4 changes: 2 additions & 2 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ VS_OUTPUT main(VS_INPUT input)
vsout.ScreenNormalTransform1.xyz = ScreenNormalTransform[1];
vsout.ScreenNormalTransform2.xyz = ScreenNormalTransform[2];
# else
float3x4 transMat = mul((float4x3)(ScreenProj[eyeIndex]), World[eyeIndex]);
float3x4 transMat = mul(ScreenProj[eyeIndex], World[eyeIndex]);

# if defined(MODELSPACENORMALS)
vsout.ScreenNormalTransform0.xyz = transMat[0].xyz;
Expand Down Expand Up @@ -2207,7 +2207,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float3 reflectionDiffuseColor = diffuseColor + directionalAmbientColor;

# if defined(SKYLIGHTING)
float skylightingDiffuse = Skylighting::hallucinateZH3(skylightingSH, skylightingSettings.DirectionalDiffuse ? worldSpaceNormal : float3(0, 0, 1));
float skylightingDiffuse = shFuncProductIntegral(skylightingSH, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? worldSpaceNormal : float3(0, 0, 1)));
skylightingDiffuse = Skylighting::mixDiffuse(skylightingSettings, skylightingDiffuse);
directionalAmbientColor = sRGB2Lin(directionalAmbientColor);
directionalAmbientColor *= skylightingDiffuse;
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif

sh2 skylightingSH = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMSSkylight, normal);
float skylighting = Skylighting::hallucinateZH3(skylightingSH, skylightingSettings.DirectionalDiffuse ? normal : float3(0, 0, 1));
float skylighting = shFuncProductIntegral(skylightingSH, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? normal : float3(0, 0, 1)));
skylighting = Skylighting::mixDiffuse(skylightingSettings, skylighting);

directionalAmbientColor = sRGB2Lin(directionalAmbientColor);
Expand Down
6 changes: 4 additions & 2 deletions src/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ class ConstantBuffer
};

template <typename T>
D3D11_BUFFER_DESC StructuredBufferDesc(UINT a_count = 1)
D3D11_BUFFER_DESC StructuredBufferDesc(UINT a_count = 1, bool cpu_access = true)
{
D3D11_BUFFER_DESC desc{};
ZeroMemory(&desc, sizeof(desc));
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.Usage = cpu_access ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
if (!cpu_access)
desc.BindFlags = desc.BindFlags | D3D11_BIND_UNORDERED_ACCESS;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
desc.StructureByteStride = sizeof(T);
Expand Down
Loading

0 comments on commit c9ef61e

Please sign in to comment.