2020-06-02 11:46:18 +02:00
|
|
|
import Common;
|
2023-11-08 23:27:21 +01:00
|
|
|
import BRDF;
|
|
|
|
|
import MaterialParameter;
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
interface ILightEnv
|
|
|
|
|
{
|
2023-11-13 09:07:23 +01:00
|
|
|
float3 illuminate<B:IBRDF>(LightingParameter input, B brdf);
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DirectionalLight : ILightEnv
|
|
|
|
|
{
|
2022-03-19 22:45:30 +01:00
|
|
|
float4 color;
|
|
|
|
|
float4 direction;
|
2020-06-02 11:46:18 +02:00
|
|
|
|
2023-11-13 09:07:23 +01:00
|
|
|
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
2022-03-19 22:45:30 +01:00
|
|
|
{
|
2024-12-30 23:47:24 +01:00
|
|
|
float3 dir_WS = -normalize(direction.xyz);
|
2025-03-13 08:23:00 +01:00
|
|
|
return brdf.evaluate(params.viewDir_WS, dir_WS, color.xyz * color.w);
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PointLight : ILightEnv
|
|
|
|
|
{
|
2023-02-27 13:52:57 +01:00
|
|
|
float4 position_WS;
|
2020-10-03 11:00:10 +02:00
|
|
|
float4 colorRange;
|
|
|
|
|
|
2023-11-13 09:07:23 +01:00
|
|
|
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
2022-03-19 22:45:30 +01:00
|
|
|
{
|
2024-12-27 17:06:43 +01:00
|
|
|
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
|
|
|
|
float d = length(lightDir_WS);
|
2020-10-03 11:00:10 +02:00
|
|
|
float illuminance = max(1 - d / colorRange.w, 0);
|
2025-03-13 08:23:00 +01:00
|
|
|
return illuminance * brdf.evaluate(params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz * position_WS.w);
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|
2024-02-02 11:39:40 +01:00
|
|
|
|
2024-05-06 18:36:16 +02:00
|
|
|
bool insidePlane(Plane plane, float3 position)
|
2024-02-02 11:39:40 +01:00
|
|
|
{
|
2025-02-14 00:39:53 +01:00
|
|
|
return dot(plane.getNormal(), position) - plane.getDistance() < -colorRange.w;
|
2022-03-19 22:45:30 +01:00
|
|
|
}
|
2020-06-02 11:46:18 +02:00
|
|
|
|
2024-05-06 18:36:16 +02:00
|
|
|
bool insideFrustum(Frustum frustum, float3 position, float minDepth, float maxDepth)
|
2022-03-19 22:45:30 +01:00
|
|
|
{
|
2024-02-20 21:07:17 +01:00
|
|
|
bool result = true;
|
2024-05-06 18:36:16 +02:00
|
|
|
if(position.z - colorRange.w > minDepth || position.z + colorRange.w < maxDepth)
|
2024-02-02 09:42:47 +01:00
|
|
|
{
|
2024-02-20 21:07:17 +01:00
|
|
|
result = false;
|
2024-02-02 09:42:47 +01:00
|
|
|
}
|
2024-02-20 21:07:17 +01:00
|
|
|
for(int i = 0; i < 4 && result; ++i)
|
2024-02-01 22:54:20 +01:00
|
|
|
{
|
2024-05-06 18:36:16 +02:00
|
|
|
if(insidePlane(frustum.sides[i], position))
|
2024-02-02 09:42:47 +01:00
|
|
|
{
|
2024-02-20 21:07:17 +01:00
|
|
|
result = false;
|
2024-02-02 09:42:47 +01:00
|
|
|
}
|
2024-02-01 22:54:20 +01:00
|
|
|
}
|
2024-02-20 21:07:17 +01:00
|
|
|
return result;
|
2022-03-19 22:45:30 +01:00
|
|
|
}
|
2024-05-29 10:40:35 +02:00
|
|
|
float3 getPosition()
|
|
|
|
|
{
|
|
|
|
|
return position_WS.xyz;
|
|
|
|
|
}
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
|
|
|
|
|
2023-10-07 19:29:53 +02:00
|
|
|
struct LightEnv
|
|
|
|
|
{
|
|
|
|
|
StructuredBuffer<DirectionalLight> directionalLights;
|
|
|
|
|
uint numDirectionalLights;
|
2023-10-26 18:37:29 +02:00
|
|
|
StructuredBuffer<PointLight> pointLights;
|
2023-10-07 19:29:53 +02:00
|
|
|
uint numPointLights;
|
|
|
|
|
};
|
2024-04-24 23:25:34 +02:00
|
|
|
layout(set=3)
|
2023-11-08 23:27:21 +01:00
|
|
|
ParameterBlock<LightEnv> pLightEnv;
|