forked from FrictionalGames/AmnesiaTheDarkDescent
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dissolve back and started on light clusters
Signed-off-by: Michael Pollind <[email protected]>
- Loading branch information
Showing
11 changed files
with
377 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "scene_resource.h.fsl" | ||
|
||
NUM_THREADS(LIGHT_CLUSTER_WIDTH, LIGHT_CLUSTER_HEIGHT, 1) | ||
void CS_MAIN(SV_GroupThreadID(uint3) threadInGroupId, SV_GroupID(uint3) groupId) | ||
{ | ||
INIT_MAIN; | ||
const float invClusterWidth = 1.0f / float(LIGHT_CLUSTER_WIDTH); | ||
const float invClusterHeight = 1.0f / float(LIGHT_CLUSTER_HEIGHT); | ||
ViewportInfo viewInfo = Get(viewports)[PRIMARY_VIEWPORT_INDEX]; | ||
float2 size = viewInfo.rect.zw; | ||
float4x4 viewProjMat = mul(viewInfo.projMat, viewInfo.viewMat); | ||
|
||
const float aspectRatio = size.x / size.y; | ||
|
||
PointLight lightData = Get(pointLights)[groupId.x]; | ||
|
||
float4 lightPosWorldSpace = float4(lightData.lightPos.xyz, 1.0f); | ||
float4 lightPosClipSpace = mul(viewProjMat, lightPosWorldSpace); | ||
float invLightPosW = 1.0f / lightPosClipSpace.w; | ||
float3 lightPos = lightPosClipSpace.xyz * invLightPosW; | ||
|
||
float fov = 2.0 * atan(1.0/viewInfo.projMat[1][1]); | ||
float projRadius = 2.0f * lightData.lightRadius * (1 / tan(fov * 0.5f)) * invLightPosW; | ||
projRadius *= size.x > size.y ? aspectRatio : 1 / aspectRatio; | ||
|
||
// Early exit light if it's behind the camera | ||
if (lightPosClipSpace.w < 0.0f && -lightPosClipSpace.w > lightData.lightRadius) { | ||
RETURN(); | ||
} | ||
|
||
lightPos.x *= aspectRatio; | ||
|
||
// Cluster coordinates in post perspective clip space | ||
float clusterLeft = float(threadInGroupId.x) * invClusterWidth; | ||
float clusterTop = float(threadInGroupId.y) * invClusterHeight; | ||
float clusterRight = clusterLeft + invClusterWidth; | ||
float clusterBottom = clusterTop + invClusterHeight; | ||
|
||
// Transform coordinates from range [0..1] to range [-1..1] | ||
clusterLeft = clusterLeft * 2.0f - 1.0f; | ||
clusterTop = clusterTop * 2.0f - 1.0f; | ||
clusterRight = clusterRight * 2.0f - 1.0f; | ||
clusterBottom = clusterBottom * 2.0f - 1.0f; | ||
|
||
clusterLeft *= aspectRatio; | ||
clusterRight *= aspectRatio; | ||
|
||
float clusterCenterX = (clusterLeft + clusterRight) * 0.5f; | ||
float clusterCenterY = (clusterTop + clusterBottom) * 0.5f; | ||
float clusterRadius = distance(float2(clusterLeft, clusterTop), float2(clusterRight, clusterBottom)) * 0.5f; | ||
|
||
// Check if the light projection overlaps the cluster: add the light bit to this cluster coords | ||
float distanceToCenter = distance(float2(clusterCenterX, clusterCenterY), lightPos.xy); | ||
|
||
if (distanceToCenter - clusterRadius < abs(projRadius)) | ||
{ | ||
// Increase light count on this cluster | ||
uint lightArrayPos = 0; | ||
AtomicAdd(Get(lightClustersCount)[LIGHT_CLUSTER_COUNT_POS(threadInGroupId.x, threadInGroupId.y)], 1, lightArrayPos); | ||
|
||
// Add light id to cluster | ||
AtomicExchange(Get(lightClusters)[LIGHT_CLUSTER_DATA_POS(lightArrayPos, threadInGroupId.x, threadInGroupId.y)], groupId.x, lightArrayPos); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "scene_resource.h.fsl" | ||
|
||
NUM_THREADS(LIGHT_CLUSTER_WIDTH, LIGHT_CLUSTER_HEIGHT, 1) | ||
void CS_MAIN(SV_DispatchThreadID(uint3) threadID) | ||
{ | ||
INIT_MAIN; | ||
AtomicStore(Get(lightClustersCount)[LIGHT_CLUSTER_COUNT_POS(threadID.x, threadID.y)], 0); | ||
RETURN(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.