0

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

vincent911001
  • 523
  • 1
  • 6
  • 20
  • Generally OpenGL likes to have images in powers of 2 (especially for mipmap generation). I don't know much about TexImage3D but can you resize it to like 512x512x256? – new Objekt Apr 06 '15 at 15:03
  • Ya sure, will try it later to see whether the artifacts go away or not, thanks btw – vincent911001 Apr 07 '15 at 00:04
  • @newObjekt, Hi, i have try to pad the images into POT size (512x512x256) but the artifacts remain... – vincent911001 Apr 07 '15 at 02:00
  • Set your 3D texture's GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_CLAMP_TO_EDGE. Seems like you have a wrapping problem. – Dimo Markov Apr 08 '15 at 12:02
  • i have changed it to GL_CLAMP_TO_EDGE but nothing happens while the edges still remain, so i went to try to tweak the parameter of mipmapping and fortunately, it solves the problem. Thanks a lot for your help – vincent911001 Apr 09 '15 at 00:17

1 Answers1

0

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);
vincent911001
  • 523
  • 1
  • 6
  • 20