方差阴影贴图深度问题

时间:2015-01-03 23:25:44

标签: opengl glsl webgl shadow-mapping

我一直在尝试让方差阴影映射在我的webgl应用程序中工作,但我似乎遇到了一个问题,我可以使用它。简而言之,我的阴影似乎比我在那里看到的例子的距离要小得多。即阴影范围从0到500个单位,但阴影是黑色5个单位距离,几乎不存在10个单位。我所遵循的示例基于以下两个链接:

VSM from Florian Boesch

VSM from Fabian Sanglard

在这两个例子中,作者都​​使用聚光透视投影将方差值映射到浮点纹理。在我的引擎中,我到目前为止尝试使用相同的逻辑,除了我使用定向光和正交投影。我尝试了两种技术,结果对我来说似乎总是一样的。我不确定是不是因为我使用正交矩阵进行投影 - 我怀疑它可能是。这是问题的图片:

VSM problem

注意盒子距离圆圈只有几个单位,但即使相机阴影为0.1到500个单位,阴影也会更暗。

在光影传递中,我的代码如下所示:

// viewMatrix is a uniform of the inverse world matrix of the camera
// vWorldPosition is the varying vec4 of the vertex position x world matrix
vec3 lightPos = (viewMatrix * vWorldPosition).xyz; 
depth = clamp(length(lightPos) / 40.0, 0.0, 1.0);

float moment1 = depth;
float moment2 = depth * depth;

// Adjusting moments (this is sort of bias per pixel) using partial derivative
float dx = dFdx(depth);
float dy = dFdy(depth);
moment2 += pow(depth, 2.0) + 0.25 * (dx * dx + dy * dy) ;
gl_FragColor = vec4(moment1, moment2, 0.0, 1.0);

然后在我的影子传递中:

// lightViewMatrix is the light camera's inverse world matrix
// vertWorldPosition is the attribute position x world matrix

vec3 lightViewPos = lightViewMatrix * vertWorldPosition;
float lightDepth2 = clamp(length(lightViewPos) / 40.0, 0.0, 1.0);
float illuminated = vsm( shadowMap[i], shadowCoord.xy, lightDepth2, shadowBias[i] );
shadowColor = shadowColor * illuminated

首先,我应该对正射投影采取不同的做法(它可能不是这个,但我不知道它可能是什么,因为它发生在上面使用两种技术:()?如果没有,我可能是什么能够做到更均匀的影子传播吗?

非常感谢

0 个答案:

没有答案