Opengl 3d纹理的可见边缘

时间:2015-04-06 08:51:47

标签: opengl volume-rendering 3d-texture

我在体积数据的体积渲染中遇到了立方体的可见边缘,当在立方体的边缘进行观察时会发生这种情况。

仅供参考,文物如下:

Rendering artifacts 2

Rendering artifacts 2

仅供参考,片段着色器片段如下(OpenGL开发手册):

    void main()
{ 
    //get the 3D texture coordinates for lookup into the volume dataset
    vec3 dataPos = vUV;

    vec3 geomDir = normalize((vec3(0.556,0.614,0.201)*vUV-vec3(0.278,0.307,0.1005)) - camPos); 

    vec3 dirStep = geomDir * step_size;     

    //flag to indicate if the raymarch loop should terminate
    bool stop = false; 

    //for all samples along the ray
    for (int i = 0; i < MAX_SAMPLES; i++) {
        // advance ray by dirstep
        dataPos = dataPos + dirStep;

        stop = dot(sign(dataPos-texMin),sign(texMax-dataPos)) < 3.0f;

        //if the stopping condition is true we brek out of the ray marching loop
        if (stop) 
            break;

        // data fetching from the red channel of volume texture
        float sample = texture(volume, dataPos).r;  


        float prev_alpha = sample - (sample * vFragColor.a);
        vFragColor.rgb = (prev_alpha) * vec3(sample) + vFragColor.rgb; 
        vFragColor.a += prev_alpha; 


        if( vFragColor.a>0.99)
            break;
    }

仅供参考,使用glTexImage3D加载纹理,格式为GL_RED,尺寸为556x614x201

1 个答案:

答案 0 :(得分:0)

仅供参考,通过从GL_LINEAR_MIPMAP_LINEAR将mipmapping的插值参数更改为GL_LINEAR来解决问题。

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);