2023-10-09 17:20:30 +02:00
|
|
|
import Common;
|
2023-11-05 10:36:01 +01:00
|
|
|
import LightEnv;
|
|
|
|
|
import MaterialParameter;
|
2024-04-26 19:32:38 +02:00
|
|
|
import MATERIAL_FILE_NAME;
|
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-10 22:26:47 +01:00
|
|
|
layout(set=5)
|
2023-11-08 23:27:21 +01:00
|
|
|
ParameterBlock<LightCullingData> pLightCullingData;
|
2023-10-09 17:20:30 +02:00
|
|
|
|
2024-05-09 08:41:46 +02:00
|
|
|
struct FragmentOutput
|
|
|
|
|
{
|
|
|
|
|
float4 color : SV_Target0;
|
|
|
|
|
uint meshletId : SV_Target1;
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-09 17:20:30 +02:00
|
|
|
[shader("pixel")]
|
2024-05-09 08:41:46 +02:00
|
|
|
FragmentOutput fragmentMain(in FragmentParameter params)
|
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();
|
|
|
|
|
let brdf = pMaterial.prepare(materialParams);
|
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
|
|
|
{
|
2023-11-13 09:07:23 +01:00
|
|
|
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
2023-11-05 10:36:01 +01:00
|
|
|
}
|
2024-05-08 10:51:59 +02:00
|
|
|
for(uint i = 0; i < pLightEnv.numPointLights; ++i)
|
2023-11-05 10:36:01 +01:00
|
|
|
{
|
2024-05-08 10:51:59 +02:00
|
|
|
//uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
|
|
|
|
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
2023-11-05 10:36:01 +01:00
|
|
|
}
|
2024-05-08 10:51:59 +02:00
|
|
|
//result += brdf.evaluateAmbient();
|
2024-05-06 18:36:16 +02:00
|
|
|
// gamma correction
|
2024-05-04 09:25:13 +02:00
|
|
|
result = result / (result + float3(1.0));
|
2024-05-06 18:36:16 +02:00
|
|
|
result = pow(result, float3(1.0/2.2));
|
2024-05-09 08:41:46 +02:00
|
|
|
FragmentOutput output;
|
|
|
|
|
output.color = float4(result, 1.0f);
|
|
|
|
|
output.meshletId = params.meshletId;
|
|
|
|
|
return output;
|
2023-10-09 17:20:30 +02:00
|
|
|
}
|