Results 1 to 6 of 6

Thread: R32F Textures

  1. #1
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    3

    R32F Textures

    I am trying to generate a height map with a compute shader. It works fine with the texture internal format set as GL_RGBA8, but it causing problems with GL_R32F.

    I generate the texture like this:
    glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RED, GL_FLOAT, 0);

    I bind it to the compute shader like this:
    glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F);

    Inside the computer shader I write to it:
    vec4 height = vec4(.008 ,0.0 ,0.0, 0.0);
    imageStore(destTex, c, height);

    No matter what the red component is the texture always looks the same when I render it with a full screen quad.

    Any thoughts?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675
    No matter what the red component is the texture always looks the same when I render it with a full screen quad.
    When you rendered that texture, did you follow all the rules needed to ensure visibility from your incoherent writes to that texture?

    Also, the difference between 0.008 and 0.0 is not particularly large. Indeed, you probably wouldn't be able to see it.

  3. #3
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    3
    Quote Originally Posted by Alfonse Reinheart View Post
    When you rendered that texture, did you follow all the rules needed to ensure visibility from your incoherent writes to that texture?

    Also, the difference between 0.008 and 0.0 is not particularly large. Indeed, you probably wouldn't be able to see it.
    I threw in a glMemoryBarrier(GL_ALL_BARRIER_BITS); after the dispatch to no avail.

    Changing just glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F); to
    glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA; makes it work. But I want the full 32 bits for red.

    I changed that r value from .3 to .8 with no difference.

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675
    Changing just glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F); to
    glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA; makes it work.
    Define "work". Assuming the texture's actual format is still R32F, all this will do is mess with the high 8 bits of a floating-point value. Or low 8 bits, depending on the hardware. The point is, it won't actually be storing a floating-point value; it'll just be poking at the bits of one.

    Or to put it another way, it's rather like this:

    Code :
    union
    {
      float f;
      unsigned char i[4];
    };

    You're writing four values via `i`, then reading from `f`.

    Equally importantly, it's not clear how you're reading from the texture in such a way that it "works".

  5. #5
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    3
    Quote Originally Posted by Alfonse Reinheart View Post
    Define "work". Assuming the texture's actual format is still R32F, all this will do is mess with the high 8 bits of a floating-point value. Or low 8 bits, depending on the hardware. The point is, it won't actually be storing a floating-point value; it'll just be poking at the bits of one.

    Or to put it another way, it's rather like this:

    [code]
    union
    {
    float f;
    unsigned char i[4];
    };
    [code]

    You're writing four values via `i`, then reading from `f`.

    Equally importantly, it's not clear how you're reading from the texture in such a way that it "works".
    When it's set to GL_RGBA8 (just when binding to the compute shader) and GL_R32F when generating the texture, changing that value in the compute shader from .3 to .8 makes it go from dark red to a bright red.
    When it's set to GL_R32F in both places it just doesn't seem to get brighter in the expected way.

    I read the texture in a shader gl_FragColor = vec4(texture2D(sampler, fuv.xy).r,0,0,1); just like that.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Have you tried adding a layout(r32f) qualifier to the image variable? It's not required for a write-only image, but it may help (if it does, that's an implementation bug).

    Also, I've had issues with compute shaders on AMD hardware which went away after putting glFlush() after the glMemoryBarrier() call (glFinish() also works, which is understandable, but glFlush() makes no sense)..

Similar Threads

  1. model textures being redirected to font textures
    By Tcll5850 in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 09-07-2014, 10:43 PM
  2. FBO Attached Textures Reused as Shader Source Textures
    By Rennie Johnson in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-22-2012, 09:43 PM
  3. Copy depth buffer to R32F texture ??
    By Dark Photon in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 04-26-2011, 04:13 PM
  4. Lots of small textures or fewer large textures?
    By jlamanna in forum OpenGL: Advanced Coding
    Replies: 30
    Last Post: 01-12-2004, 03:53 AM
  5. are GL_COLOR_INDEX textures converted to RGBA-Textures?
    By TB-Rex in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 12-18-2000, 06:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean