Access to 3D array in fragment shader

后端 未结 2 911
长发绾君心
长发绾君心 2021-01-20 15:45

I\'m trying to provide access to a 3-dimensional array of scalar data to a fragment shader, from a Python program using PyOpenGL.

In the fragment shader, I declare t

相关标签:
2条回答
  • 2021-01-20 16:14

    I figured out the problem: Apparently GL_TEXTURE_3D is by default mipmapped, I only provided level 0, and (how I'm not clear about) another level is selected. The problem is solved by glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0).

    0 讨论(0)
  • 2021-01-20 16:15

    That is because your GL_RED texture format is clamped to range <0,1> !!!

    To remedy you need to use non clamped texture format or disable clamping ... Here examples that are working on my GL implementations:

    • GPU ray casting (single pass) with 3d textures in spherical coordinates
    • GLSL back raytrace through 3D volume

    here formats extracted from both:

    glTexImage3D(GL_TEXTURE_3D, 0, GL_R16F, xs,ys,zs, 0, GL_RED, GL_FLOAT, dat);
    
    glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, size, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, pdata);
    

    For scalar data I would use the first option. There are more formats that are not clamped just try and see...

    I have never used the disabling of clamping feature but saw this code somewhere while researching similar issues (not sure if it works):

    glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE);
    glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE);
    glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);
    

    With that theoretically you could use any texture format...

    To verify you can use this:

    • GLSL debug prints

    Also I do not see any parameters of the texture set. I would expect something like this:

    glBindTexture(GL_TEXTURE_3D,txrvol);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);
    

    to avoid interpolation messing your data for non exact texture coordinates ...

    0 讨论(0)
提交回复
热议问题