gpt4 book ai didi

glsl - WebGL:如何在 GLSL 中使用整数属性

转载 作者:行者123 更新时间:2023-12-01 21:58:06 24 4
gpt4 key购买 nike

是否可以在 WebGL 顶点着色器中使用整数属性?我的顶点数据包含整数,我想像这样定义顶点属性:

attribute vec3 POSITION;
attribute int INDEX[8];
attribute float WEIGHT[8];

如果这是可能的,我如何使用 gl.bufferData 将混合顶点数据从 js 传递到着色器?

如果这是不可能的,实现相同结果的最佳方法是什么(将索引从 CPU 传递到着色器并在着色器中将它们用作整数)?

最佳答案

WebGL 不支持整数属性。除了规范 ( https://www.khronos.org/registry/webgl/specs/1.0/ ) 中列出的一些异常(exception)情况外,WebGL 使用与 OpenGL ES 2.0 基本相同的 GLSL 功能集。

OpenGL ES 着色语言 1.00(这是用于 ES 2.0 的 GLSL 版本)的规范文档在第 30 页的“4.3.3 属性”部分中说道:

The attribute qualifier can be used only with the data types float, vec2, vec3, vec4, mat2, mat3, and mat4. Attribute variables cannot be declared as arrays or structures.

您能做的最好的可能就是简单地使用没有小数部分的 float 。使用相同的存储空间,可以精确表示的值的范围将比整数更有限。例如16位 float (半 float )有11位精度,可以精确表示0到2048之间的整数。

关于glsl - WebGL:如何在 GLSL 中使用整数属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com