Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float visibility = 1.0f;
- float searchTexelSpread = 1.0f;
- float oneTexelSize = lightsData[lightInput.id].shadowScale;
- float halfTexelSize = oneTexelSize * 0.5f;
- float2 ndcCurrentFragmentLightmapTexel = lNDC.xy;
- float lightSizeScale = 1.0f / lightsData[lightInput.id].data3.x;
- float near_plane = spotLight.shadowNear;
- float far_plane = spotLight.shadowFar;
- float lightmapFarPlaneSize = tan(spotLight.spotAngle * 0.5f) * 2.0f * far_plane;
- float oneFarPlaneTexelSize = lightmapFarPlaneSize * lightsData[lightInput.id].shadowScale;
- float z = lNDC.z;
- for (int i = -KERNEL_SEARCH_SIZE; i < KERNEL_SEARCH_SIZE; i++)
- {
- for (int j = -KERNEL_SEARCH_SIZE; j < KERNEL_SEARCH_SIZE; j++)
- {
- float sampleTexX = lNDC.x + oneTexelSize * searchTexelSpread * float(i);
- float sampleTexY = lNDC.y + oneTexelSize * searchTexelSpread * float(j);
- float2 sampleCoords = float2(sampleTexX, sampleTexY);
- float zs = shadowMap.SampleLevel(shadowSampler, sampleCoords.xy, 0.0f).x;
- if (zs > z)
- {
- continue;
- }
- float thisSampleZPlaneSize = lightmapFarPlaneSize * zs;
- float2 ndcNextFragmentLightmapTexel = sampleCoords;
- float scaleFactor = z / (z - zs);
- float left = (ndcNextFragmentLightmapTexel.x - ndcCurrentFragmentLightmapTexel.x - halfTexelSize) * thisSampleZPlaneSize * scaleFactor * lightSizeScale;
- float right = (ndcNextFragmentLightmapTexel.x - ndcCurrentFragmentLightmapTexel.x + halfTexelSize) * thisSampleZPlaneSize * scaleFactor * lightSizeScale;
- float top = (ndcNextFragmentLightmapTexel.y - ndcCurrentFragmentLightmapTexel.y + halfTexelSize) * thisSampleZPlaneSize * scaleFactor * lightSizeScale;
- float bottom = (ndcNextFragmentLightmapTexel.y - ndcCurrentFragmentLightmapTexel.y - halfTexelSize) * thisSampleZPlaneSize * scaleFactor * lightSizeScale;
- left = clamp(left, -0.5f, 0.5f);
- right = clamp(right, -0.5f, 0.5f);
- top = clamp(top, -0.5f, 0.5f);
- bottom = clamp(bottom, -0.5f, 0.5f);
- float width = right - left;
- float height = top - bottom;
- float area = width * height;
- visibility -= area * 1.0f;
- }
- }
- if (visibility < 0.0f)
- {
- visibility = 0.0f;
- }
- shadowMask *= visibility;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement