feat: add spot light shadows with a tilled buffer
This commit is contained in:
@@ -34,6 +34,32 @@ vec3 calculateNormal(MaterialData material, uint samplerID)
|
||||
return normalize(mat3(t, b, n) * tangentNormal);
|
||||
}
|
||||
|
||||
float calculateShadow(Light light, vec3 fragPos, vec3 geometryNormal)
|
||||
{
|
||||
if (light.shadowIndex == NO_SHADOW) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
if (light.type == TYPE_DIRECTIONAL_LIGHT) {
|
||||
return calculateDirectionalShadow(
|
||||
fragPos, geometryNormal,
|
||||
pcs.sceneData.lightViewProj,
|
||||
pcs.sceneData.shadowMapId,
|
||||
pcs.sceneData.shadowNormalOffset);
|
||||
}
|
||||
|
||||
if (light.type == TYPE_SPOT_LIGHT) {
|
||||
return calculateSpotShadow(
|
||||
fragPos, geometryNormal, light.position,
|
||||
pcs.sceneData.spotShadows[light.shadowIndex],
|
||||
light.shadowIndex,
|
||||
pcs.sceneData.spotShadowAtlasId,
|
||||
pcs.sceneData.spotShadowTilesPerRow);
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialData material = pcs.sceneData.materials.data[pcs.materialID];
|
||||
@@ -73,19 +99,13 @@ void main()
|
||||
uint tileOffset = (tileID.y * pcs.sceneData.tileCountX + tileID.x) * LIGHT_TILE_STRIDE;
|
||||
uint tileLightCount = pcs.sceneData.tileLightIndices.data[tileOffset];
|
||||
|
||||
vec3 geometryNormal = normalize(inNormal);
|
||||
vec3 fragColor = vec3(0.0);
|
||||
for (uint i = 0; i < tileLightCount; i++) {
|
||||
uint lightIndex = pcs.sceneData.tileLightIndices.data[tileOffset + 1 + i];
|
||||
Light light = pcs.sceneData.lights.data[lightIndex];
|
||||
|
||||
float shadow = 1.0;
|
||||
if (light.castShadows != 0) {
|
||||
shadow = calculateDirectionalShadow(
|
||||
fragPos, normalize(inNormal),
|
||||
pcs.sceneData.lightViewProj,
|
||||
pcs.sceneData.shadowMapId,
|
||||
pcs.sceneData.shadowNormalOffset);
|
||||
}
|
||||
float shadow = calculateShadow(light, fragPos, geometryNormal);
|
||||
|
||||
fragColor += calculateLight(light, fragPos, n, v,
|
||||
diffuseColor, roughness, metallic, f0, shadow);
|
||||
|
||||
Reference in New Issue
Block a user