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

69 lines
1.8 KiB
Plaintext
Raw Normal View History

import MaterialParameter;
2020-06-02 11:46:18 +02:00
import BRDF;
import Common;
interface ILightEnv
{
2020-09-19 14:36:50 +02:00
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 wo);
2020-06-02 11:46:18 +02:00
};
struct DirectionalLight : ILightEnv
{
float4 color;
float4 direction;
float4 intensity;
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 wo)
2020-06-02 11:46:18 +02:00
{
2021-05-06 17:02:10 +02:00
return intensity.xyz * brdf.evaluate(wo, normalize(direction.xyz), input.worldNormal, input.worldTangent, input.worldBiTangent, color.xyz);
2020-06-02 11:46:18 +02:00
}
};
struct PointLight : ILightEnv
{
float4 positionWS;
float4 positionVS;
2020-10-03 11:00:10 +02:00
float4 colorRange;
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 viewDir)
2020-06-02 11:46:18 +02:00
{
float3 lightVec = positionWS.xyz - input.worldPosition;
2020-06-02 11:46:18 +02:00
float d = length(lightVec);
float3 direction = normalize(lightVec);
2020-10-03 11:00:10 +02:00
float illuminance = max(1 - d / colorRange.w, 0);
return illuminance * brdf.evaluate(viewDir, direction, input.worldNormal, input.worldTangent, input.worldBiTangent, colorRange.xyz);
2020-06-02 11:46:18 +02:00
}
bool insidePlane(Plane plane)
{
2020-10-03 11:00:10 +02:00
return dot(plane.n, positionVS.xyz) - plane.d < -colorRange.w;
2020-06-02 11:46:18 +02:00
}
bool insideFrustum(Frustum frustum, float zNear, float zFar)
{
bool result = true;
2020-10-03 11:00:10 +02:00
//if(positionVS.z - range > zNear || positionVS.z + colorRange.w < zFar)
2020-06-02 11:46:18 +02:00
{
// result = false;
}
for(int i = 0; i < 4 && result; ++i)
{
if(insidePlane(frustum.planes[i]))
{
result = false;
}
}
return result;
}
};
2021-05-06 17:02:10 +02:00
layout(set = INDEX_LIGHT_ENV, binding = 0, std430)
2021-06-12 18:51:29 +02:00
StructuredBuffer<DirectionalLight> directionalLights;
layout(set = INDEX_LIGHT_ENV, binding = 1, std430)
ConstantBuffer<uint> numDirectionalLights;
layout(set = INDEX_LIGHT_ENV, binding = 2, std430)
StructuredBuffer<PointLight> pointLights;
layout(set = INDEX_LIGHT_ENV, binding = 3, std430)
ConstantBuffer<uint> numPointLights;