Files
Seele/res/shaders/lib/LightEnv.slang
T

69 lines
1.7 KiB
Plaintext
Raw Normal View History

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
{
2023-12-03 23:12:20 +01:00
float3 lightDir_TS = mul(params.tbn, direction.xyz);
return brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), 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
{
2023-11-30 11:51:53 +01:00
float3 lightDir_WS = position_WS.xyz - params.position_WS;
2023-12-03 23:12:20 +01:00
float3 lightDir_TS = mul(params.tbn, lightDir_WS);
float d = length(lightDir_TS);
2020-10-03 11:00:10 +02:00
float illuminance = max(1 - d / colorRange.w, 0);
2023-12-03 23:12:20 +01:00
return brdf.evaluate(params.tbn, params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
2020-06-02 11:46:18 +02:00
}
2022-03-19 22:45:30 +01:00
bool insidePlane(Plane plane)
{
2023-11-13 09:07:23 +01:00
return true;//dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w;
2022-03-19 22:45:30 +01:00
}
2020-06-02 11:46:18 +02:00
2022-03-19 22:45:30 +01:00
bool insideFrustum(Frustum frustum, float zNear, float zFar)
{
2020-06-02 11:46:18 +02:00
bool result = true;
2023-11-13 09:07:23 +01:00
//if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
//{
// //result = false;
//}
//for(int i = 0; i < 4 && result; ++i)
//{
// if(insidePlane(frustum.sides[i]))
// {
// //result = false;
// }
//}
2022-03-19 22:45:30 +01:00
return result;
}
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;
};
2023-11-10 22:26:47 +01:00
layout(set=3)
2023-11-08 23:27:21 +01:00
ParameterBlock<LightEnv> pLightEnv;