阴影映射中具有汇总面积表的数值稳定性

|| 我在SAVSM设置中失去精度问题。 当您看到光线四处移动时,效果非常惊人;有很多噪音,碎片一直在黑白相间。通过使用最小方差可以略微减小这种影响(因此忽略了低于某个阈值的任何东西),但是如果不正确的衰减,我们会得到更差的效果(请参阅我的其他文章)。 我使用GLSL 1.2是因为我在Mac上,因此我无法访问modf函数,无法按照GPU Gems 3第8章中的描述在两个通道之间分配精度。 我将GL_RGBA32F_ARB纹理与Framebuffer对象一起使用,并且对两个纹理进行ping操作以生成一个总面积表,并将其与VSM算法一起使用。 Moments / Depth Shader创建表格的基础
varying vec4 v_position;
varying float tDepth;


float g_DistributeFactor = 1024.0;  


void main()
{
    // Is this linear depth? I would say yes but one can\'t be utterly sure.
    // Could try a divide by the far plane?

    float depth = v_position.z / v_position.w ;
    depth = depth * 0.5 + 0.5;          //Don\'t forget to move away from unit cube ([-1,1]) to [0,1] coordinate system

    vec2 moments = vec2(depth, depth * depth);


    // Adjusting moments (this is sort of bias per pixel) using derivative
    float dx = dFdx(depth);
    float dy = dFdy(depth);
    moments.y += 0.25 * (dx*dx+dy*dy);

    // Subtract 0.5 off now so we can get this into our summed area table calc

    //moments -= 0.5;

    // Split the moments into rg and ba for EVEN MORE PRECISION

//  float FactorInv = 1.0 / g_DistributeFactor;

//  gl_FragColor = vec4(floor(moments.x) * FactorInv, fract(moments.x ) * g_DistributeFactor, 
//                  floor(moments.y)  * FactorInv, fract(moments.y)  * g_DistributeFactor);


    gl_FragColor = vec4(moments,0.0,0.0);
}
阴影贴图着色器
varying vec4 v_position;
varying float tDepth;


float g_DistributeFactor = 1024.0;  


void main()
{
    // Is this linear depth? I would say yes but one can\'t be utterly sure.
    // Could try a divide by the far plane?

    float depth = v_position.z / v_position.w ;
    depth = depth * 0.5 + 0.5;          //Don\'t forget to move away from unit cube ([-1,1]) to [0,1] coordinate system

    vec2 moments = vec2(depth, depth * depth);


    // Adjusting moments (this is sort of bias per pixel) using derivative
    float dx = dFdx(depth);
    float dy = dFdy(depth);
    moments.y += 0.25 * (dx*dx+dy*dy);

    // Subtract 0.5 off now so we can get this into our summed area table calc

    //moments -= 0.5;

    // Split the moments into rg and ba for EVEN MORE PRECISION

//  float FactorInv = 1.0 / g_DistributeFactor;

//  gl_FragColor = vec4(floor(moments.x) * FactorInv, fract(moments.x ) * g_DistributeFactor, 
//                  floor(moments.y)  * FactorInv, fract(moments.y)  * g_DistributeFactor);


    gl_FragColor = vec4(moments,0.0,0.0);
}
汇总表似乎确实有效。我知道这一点是因为我有一个将汇总表转换回原始深度图的函数,并且两个图像看起来几乎相同。我还使用-0.5 + 0.5技巧来获得更高的精度,但这似乎无济于事 我的问题是,鉴于im在仅具有GLSL 1.2的Mac上,如何将精度分成两个通道?如果我可以将这些额外的通道用于汇总表中的空间,那可能行得通吗?我已经看过一些使用modf的东西,但是对我来说不可用。 另外,人们建议使用32位整数缓冲区,但我认为我的macbook pro上不支持这些缓冲区。     
已邀请:

要回复问题请先登录注册