block search 的实现:
`
float findBlocker( sampler2D shadowMap, vec2 uv, float zReceiver ) {
float searchWidth = LIGHT_UV_SIZE * (zReceiver – NEAR_PLANE) / zReceiver;
float blockSum = 0.0;
float blockNum = 0.0;
poissonDiskSamples(uv);
for (int i = 0; i < NUM_SAMPLES; i++)
{
float closestDepth = unpack(texture2D(shadowMap, uv + poissonDisk[i] * searchWidth));
if(zReceiver > closestDepth)
{
blockSum += closestDepth;
blockNum += 1.0;
}
}
return blockSum / blockNum;
}
光照宽度的定义和NearPlane的定义:
、
#define LIGHT_UV_SIZE 0.1
#define NEAR_PLANE 0.001
NearPlane 我是定义在 [0 , 1] 这个区间的,而且 NearPlane 的定义与光照投影矩阵的设置是否有关?
这是光照正交投影的设置:
mat4.ortho(projectionMatrix, -100, 100, -100, 100, -100, 1000);
PCSS 的实现
float PCSS(sampler2D shadowMap, vec4 coords){
vec3 projCoords = coords.xyz / coords.w;
projCoords = projCoords * 0.5 + 0.5;
// STEP 1: avgblocker depth
float avgBlockerDepth = findBlocker(shadowMap, projCoords.xy, projCoords.z);
// STEP 2: penumbra size
float filterSize = LIGHT_UV_SIZE * (projCoords.z – avgBlockerDepth) / avgBlockerDepth;
// STEP 3: filtering
float visibility = PCF(shadowMap, coords, filterSize);
return visibility;
}
-
This topic was modified 3 years ago by wuzhou.
-
This topic was modified 3 years ago by wuzhou.
Attachments:
You must be
logged in to view attached files.