Files
Seele/res/shaders/BasePass.slang
T

90 lines
3.2 KiB
Plaintext
Raw Normal View History

2023-10-09 17:20:30 +02:00
import Common;
2023-11-05 10:36:01 +01:00
import LightEnv;
import MaterialParameter;
2024-07-10 21:07:10 +02:00
import MATERIAL_FILE_NAME;
2023-11-05 10:36:01 +01:00
2025-07-14 21:10:07 +02:00
const static uint64_t NUM_CASCADES = 4;
2025-08-08 22:29:54 +02:00
struct ShadowMappingData
2025-07-14 21:10:07 +02:00
{
Texture2DArray shadowMaps[NUM_CASCADES];
2025-08-08 22:29:54 +02:00
StructuredBuffer<float4x4> lightSpaceMatrices[NUM_CASCADES];
SamplerState shadowSampler;
2025-07-14 21:10:07 +02:00
2025-08-14 11:06:43 +02:00
ConstantBuffer<float4> cascadeSplits;
2025-07-14 21:10:07 +02:00
};
ParameterBlock<ShadowMappingData> pShadowMapping;
2025-08-08 22:29:54 +02:00
2023-11-05 10:36:01 +01:00
struct LightCullingData
{
2024-02-21 10:30:04 +01:00
RWStructuredBuffer<uint> lightIndexList;
2023-11-05 10:36:01 +01:00
2024-02-21 10:30:04 +01:00
RWTexture2D<uint2> lightGrid;
2023-11-05 10:36:01 +01:00
};
2023-11-08 23:27:21 +01:00
ParameterBlock<LightCullingData> pLightCullingData;
2023-10-09 17:20:30 +02:00
2025-05-10 22:52:46 +02:00
static const float4x4 biasMat = float4x4(
0.5, 0.0, 0.0, 0.5,
2025-08-23 18:09:01 +02:00
0.0, 0.5, 0.0, 0.5,
2025-05-10 22:52:46 +02:00
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
2023-10-09 17:20:30 +02:00
[shader("pixel")]
float4 fragmentMain(in FragmentParameter params) : SV_Target
2023-10-09 17:20:30 +02:00
{
2023-11-13 09:07:23 +01:00
LightingParameter lightingParams = params.getLightingParameter();
2023-12-15 11:57:13 +01:00
MaterialParameter materialParams = params.getMaterialParameter();
2025-05-04 21:30:01 +02:00
var brdf = Material.prepare(materialParams);
2025-05-09 14:59:58 +02:00
brdf.setNormal(normalize(params.normal_WS));
2024-02-20 22:38:35 +01:00
uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE));
2024-02-21 10:30:04 +01:00
uint startOffset = pLightCullingData.lightGrid[tileIndex].x;
uint lightCount = pLightCullingData.lightGrid[tileIndex].y;
2023-11-05 10:36:01 +01:00
float3 result = float3(0, 0, 0);
2023-11-08 23:27:21 +01:00
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
2023-11-05 10:36:01 +01:00
{
2025-08-08 22:29:54 +02:00
uint cascadeIndex = 0;
2025-07-14 21:10:07 +02:00
for (uint c = 0; c < NUM_CASCADES - 1; ++c) {
2025-08-14 11:06:43 +02:00
if (params.position_VS.z > pShadowMapping.cascadeSplits[c]) {
//cascadeIndex = c + 1;
2025-07-14 21:10:07 +02:00
}
}
2025-08-14 11:06:43 +02:00
float4 lightSpacePos = mul(pShadowMapping.lightSpaceMatrices[cascadeIndex][i], float4(params.position_WS, 1));
2025-09-20 12:42:42 +02:00
lightSpacePos = mul(biasMat, lightSpacePos);
2025-08-23 18:09:01 +02:00
float4 shadowCoord = clipToScreen(lightSpacePos);
2025-09-20 12:42:42 +02:00
/*int3 texDim;
2025-08-08 22:29:54 +02:00
pShadowMapping.shadowMaps[cascadeIndex].GetDimensions(texDim.x, texDim.y, texDim.z);
2025-05-10 22:58:20 +02:00
float scale = 1.5f;
float dx = scale * 1.0 / float(texDim.x);
float dy = scale * 1.0 / float(texDim.y);
float shadowFactor = 0.0f;
int count = 0;
int range = 1;
for (int x = -range; x <= range; ++x) {
for (int y = -range; y <= range; ++y) {
float shadow = 1.0f;
if (shadowCoord.z > 0.0 && shadowCoord.z < 1.0)
{
2025-08-08 22:29:54 +02:00
float dist = pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy + float2(dx * x, dy * y), i)).r;
2025-09-20 12:42:42 +02:00
if (shadowCoord.w > 0 && dist < shadowCoord.z - 0.005f)
2025-05-10 22:58:20 +02:00
{
shadow = 0;
}
}
shadowFactor += shadow;
count++;
}
2025-09-20 12:42:42 +02:00
}*/
2025-05-09 14:59:58 +02:00
2025-09-20 12:42:42 +02:00
result = 1 - float3(pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy, i)).r, 0, 0);//(shadowFactor / count) * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
2023-11-05 10:36:01 +01:00
}
2025-05-10 22:52:46 +02:00
for (uint i = 0; i < pLightEnv.numPointLights; ++i)
2023-11-05 10:36:01 +01:00
{
2025-05-10 22:52:46 +02:00
//uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
2025-08-14 11:06:43 +02:00
//result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
2023-11-05 10:36:01 +01:00
}
2025-08-14 11:06:43 +02:00
//result += brdf.evaluateAmbient(lightingParams.viewDir_WS);
2024-08-07 21:52:45 +02:00
return float4(result, brdf.getAlpha());
2024-12-27 17:06:43 +01:00
}