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-05-15 15:27:13 +02:00
|
|
|
return brdf.evaluate(params.tbn, params.viewDir_WS, -normalize(direction.xyz), params.normal_WS, color.xyz);
|
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-05-15 15:27:13 +02: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);
|
2024-05-15 15:27:13 +02:00
|
|
|
return illuminance * brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), normalize(params.normal_WS), colorRange.xyz);
|
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
|
|
|
{
|
2024-05-06 18:36:16 +02:00
|
|
|
return dot(plane.n, position) - plane.d < -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
|
|
|
}
|
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;
|