i have a float array with intensity value, i need load this array as 3d texture in opengl, and in the fragment shader read this as red color (float sample= texture(cord,volumeText).r
).
the size of array is 256*256*256, and the intensity value are between 0.0 to 256.0.
this is a sample of intensity values:
75.839354473071637,
64.083049468866022,
65.253933716444365,
79.992431196592577,
84.411485976957096,
0.0000000000000000,
82.020319431382831,
76.808403454586994,
79.974774618246158,
0.0000000000000000,
91.127273013466336,
84.009956557448433,
90.221356094672814,
87.567422484025627,
71.940263118478072,
0.0000000000000000,
0.0000000000000000,
74.487058398181944,
..................,
..................
To load a texture like this you can use the input format GL_RED
and type GL_FLOAT
. A proper sized internal format for is GL_R16F
. See glTexImage3D
:
glTexImage3D(GL_TEXTURE_3D, 0, GL_R16F, 256, 256, 256, 0, GL_RED, GL_FLOAT, dataPtr)
The internal format GL_R16F
is a floating point format. This means when you read the red color channel (.r
) from the texture in the fragment shader, then the values are still in range [0.0, 256.0].