首页 > 解决方案 > Load float array with 3D texture?

问题描述

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,
   ..................,
   ..................

标签: openglglsltextures

解决方案


要加载这样的纹理,您可以使用输入格式GL_RED和类型GL_FLOAT。适当大小的内部格式是GL_R16F. 见glTexImage3D

glTexImage3D(GL_TEXTURE_3D, 0, GL_R16F, 256, 256, 256, 0, GL_RED, GL_FLOAT, dataPtr)

内部格式GL_R16F是浮点格式。这意味着当您从片段着色器中的纹理读取红色通道 ( .r) 时,值仍在 [0.0, 256.0] 范围内。


推荐阅读