【发布时间】:2021-03-17 18:49:54
【问题描述】:
我正在遵循 Infinity Ward 的光线追踪阴影方法,他们从深度缓冲区重建世界位置并将光线从该位置投射到光线。我发现使用这种方法,每像素 1 条光线,我得到了非常糟糕的阴影痤疮,可能是因为数值错误。明显的解决方法是在法线方向上稍微移动世界位置,但我无法访问法线。我认为一旦我为每个像素拍摄多条光线,它可能会消失,但出于性能原因,我试图坚持使用 1。有任何选择,还是我注定无法访问法线?
void main() {
const vec2 pixelCenter = vec2(gl_LaunchIDNV.xy) + vec2(0.5);
const vec2 uv = pixelCenter/vec2(gl_LaunchSizeNV.xy);
uint rayFlags = gl_RayFlagsOpaqueNV | gl_RayFlagsSkipClosestHitShaderNV | gl_RayFlagsTerminateOnFirstHitNV;
float tMin = 0.001;
float tMax = 10000.0;
// sample the current depth
float depth = texture(depthTexture, uv).r;
// reconstruct world position of pixel
vec3 origin = reconstructPosition(uv, depth, pc.inverseViewProjection);
// ray direction is the inverse of the light direction
vec3 direction = normalize(-pc.light_direction.xyz);
// everything is considered in shadow until the miss shader is called
payload = vec3(0);
traceNV(AS, rayFlags, 0xFF, 0, 0, 0, origin, tMin, direction, tMax, 0);
// store either the original 0, or 1 if the miss shader executed
// if the miss shader executes it means it was able to 'reach' the light from the current pixel's position
imageStore(shadowTexture, ivec2(gl_LaunchIDNV.xy), vec4(payload, 1.0));
}
【问题讨论】:
标签: 3d glsl vulkan raytracing