从不同角度观看时,3D纹理隐藏

时间:2015-04-08 02:21:16

标签: opengl volume-rendering

我遇到了渲染3D纹理瑕疵的问题,如下所示:

Rendering artifacts(texture get hidden when viewed from certain angle)

我在网上搜索过找到这个问题的解决方案,大多数答案都指出了深度缓冲位的问题。 虽然我尝试将深度缓冲位更改为从GL_DEPTHGL_STENCIL in GLUT的24位,但结果仍然与从某个角度查看时隐藏的纹理(或几何 - 不确定)相同。

那么,我能知道导致这种伪影的究竟是什么问题吗?

下面是片段着色器代码片段(OpenGL Development Cookbook)

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;
}

仅供参考,以下是顶点着色器片段:

#version 330 core

layout(location = 0) in vec3 vVertex; //object space vertex position

//uniform
uniform mat4 MVP;   //combined modelview projection matrix

smooth out vec3 vUV; //3D texture coordinates for texture lookup in the    fragment shader

void main()
{  
//get the clipspace position 
gl_Position = MVP*vec4(vVertex.xyz,1);

//get the 3D texture coordinates by adding (0.5,0.5,0.5) to the object space 
//vertex position. Since the unit cube is at origin (min: (-0.5,-0.5,-0.5) and max: (0.5,0.5,0.5))
//adding (0.5,0.5,0.5) to the unit cube object space position gives us values from (0,0,0) to 
//(1,1,1)
//vUV = (vVertex + vec3(0.278,0.307,0.1005))/vec3(0.556,0.614,0.201);
vUV = vVertex/vec3(0.556,0.614,0.201);//after moving the cube to coordinates range of 0-1

}

已编辑:特别是在边缘相对观看时出现的工件。

仅供参考,glm::perspective(45.0f,(float)w/h, 1.0f,10.0f);

0 个答案:

没有答案