【问题标题】:Strange Voxel Cone Tracing Results奇怪的体素锥追踪结果
【发布时间】:2019-01-12 07:24:29
【问题描述】:

我目前正在使用 C++ 和 OpenGL 编写体素锥追踪渲染引擎。一切都很顺利,除了我在更宽的锥角上得到了相当奇怪的结果。

现在,为了测试的目的,我所做的只是射出一个垂直于片段法线的奇异圆锥。我只是在计算“间接光”。作为参考,这是我正在使用的相当简单的片段着色器:

#version 450 core

out vec4 FragColor;

in vec3 pos_fs;
in vec3 nrm_fs;

uniform sampler3D tex3D;

vec3 indirectDiffuse();

vec3 voxelTraceCone(const vec3 from, vec3 direction);

void main()
{
    FragColor = vec4(0, 0, 0, 1);
    FragColor.rgb += indirectDiffuse();
}

vec3 indirectDiffuse(){
    // singular cone in direction of the normal
    vec3 ret = voxelTraceCone(pos_fs, nrm);

    return ret;
}

vec3 voxelTraceCone(const vec3 origin, vec3 dir) {
    float max_dist = 1f;
    dir = normalize(dir);

    float current_dist = 0.01f;

    float apperture_angle = 0.01f; //Angle in Radians.

    vec3 color = vec3(0.0f);
    float occlusion = 0.0f;

    float vox_size = 128.0f; //voxel map size

    while(current_dist < max_dist && occlusion < 1) {
        //Get cone diameter (tan = cathetus / cathetus)
        float current_coneDiameter = 2.0f * current_dist * tan(apperture_angle * 0.5f);

        //Get mipmap level which should be sampled according to the cone diameter
        float vlevel = log2(current_coneDiameter * vox_size);

        vec3 pos_worldspace = origin + dir * current_dist;
        vec3 pos_texturespace = (pos_worldspace + vec3(1.0f)) * 0.5f; //[-1,1] Coordinates to [0,1]

        vec4 voxel = textureLod(tex3D, pos_texturespace, vlevel); //get voxel

        vec3 color_read = voxel.rgb;
        float occlusion_read = voxel.a;

        color = occlusion*color + (1 - occlusion) * occlusion_read * color_read;
        occlusion = occlusion + (1 - occlusion) * occlusion_read;

        float dist_factor = 0.3f; //Lower = better results but higher performance hit
        current_dist += current_coneDiameter * dist_factor; 
    }

    return color;
}

tex3D 制服是体素 3d 纹理。

在常规的 Phong 着色器下(计算体素值),场景如下所示:

作为参考,这是体素贴图 (tex3D) (128x128x128) 可视化时的样子:

现在我们来解决我遇到的实际问题。如果我将上面的着色器应用到场景中,我会得到以下结果:

对于非常小的锥角 (apperture_angle=0.01),我大致得到了您可能期望的结果:体素化场景基本上垂直“反射”在每个表面上:

现在,如果我将孔径角度增加到例如 30 度 (apperture_angle=0.52),我会得到这个看起来很奇怪的“波浪形”结果:

我预计会得到与之前的结果更相似的结果,只是不那么高光。相反,我得到的主要是每个对象的轮廓以镜面反射的方式反射,轮廓内偶尔会有一些像素。考虑到这是场景中的“间接照明”,即使我添加了直接照明,它看起来也不会很好。

我尝试了 max_dist、current_dist 等不同的值,并拍摄了几个圆锥而不是一个。结果保持相似,如果不是更糟的话。

有人知道我在这里做错了什么,以及如何获得实际的远程逼真的间接光吗?

我怀疑 textureLod 函数会以某种方式对任何高于 0 的 LOD 级别产生错误的结果,但我无法确认这一点。

【问题讨论】:

  • 首先要检查的是纹理是否有合适的 MIP 贴图。通过使用一些 OpenGL 调试器或通过渲染预定义的 lod。顺便说一句,为什么vox_sizevlevel 的公式中?

标签: c++ opengl glsl shader voxel


【解决方案1】:

3D 纹理的 Mipmap 未正确生成。 此外,在 vlevel 上没有硬帽,导致所有 textureLod 调用返回 #000000 颜色,访问任何高于 1 的 mipmaplevel。

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 2013-01-03
    • 1970-01-01
    • 2013-02-01
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多