opengl - 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,
..................,
..................
解决方案
要加载这样的纹理,您可以使用输入格式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] 范围内。
推荐阅读
- javascript - 如何针对 URL 字符串测试 URL 匹配模式
- angular - “承诺”类型上不存在属性“订阅”
'。ngx-soap 包 - html - 点击可编辑
- java - @PostConstruct 与 Spring Batch 读取器结合时调用失败
- typescript - Typescript 接口通用属性名称
- mybatis - 为什么 #{params.property} 在 mybatis 中不能取值?
- r - Google 开发者控制台 - 从命令行更改授权 URI
- .htaccess - 重定向 301 丢弃一组动态参数中的特定参数
- android - textView 在第一次更改时不显示
- spring-boot - 如何在 User -Role-Permission 中配置 oneToMany 映射