Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Sampling float from texture(rect)

  1. #1
    Intern Newbie
    Join Date
    Jan 2013

    Sampling float from texture(rect)

    Hi there,

    I wanted to use a texture/buffer to access my heightfield on my vertex shader. However, the heights are floats and it seems like all methods that sample 2dtextures return vec4, which has 4 bytes.
    Any idea how i can sample floats? Can i combine the four ints/bytes back into the original floats? Or did i miss some other functions that can help me with this?

    For clarity: the texture/buffer is a simple array of floats.

    Thanks for any help!

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Texture fetch functions always return vec4s (or ivec4s or uvec4s for integer textures), but that shouldn't confuse you.

    In case you have a one, two, or three channel texture, e.g. R32F, RG16F or RGB8, you still get a vec4 at fetch time, just the unavailable channels get default data, thus in case of a single channel R texture you get the result (r,0,0,1), where r is the actual component from the texture.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog:

  3. #3
    Intern Newbie
    Join Date
    Jan 2013
    Ahh i understand now, thank you very much! I though it would always read 4 values per texel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts