Visible edges from Opengl 3d texture

661 Views Asked by At

I have encountered visible edges of cube from volume rendering of volume data, it happens when viewing is done at the edges of the cube.

FYI, the artifacts are as below:

Rendering artifacts 2

Rendering artifacts 2

FYI, the fragment shader snippet is as below(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;
    }

FYI, the texture is loaded using glTexImage3D with format of GL_RED and a dimension of 556x614x201

1

There are 1 best solutions below

0
On

FYI, the problem is solved by changing the interpolation parameter of mipmapping to GL_LINEAR from GL_LINEAR_MIPMAP_LINEAR.

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);