gpt4 book ai didi

webgl2 - 在 WebGL 2 Instancing 中访问 gl_InstanceID

转载 作者:行者123 更新时间:2023-12-02 03:54:27 24 4
gpt4 key购买 nike

我正在尝试在 WebGL 2 中进行实例化。我想使用内置变量 gl_InstanceID 来索引一个统一的 float 组。

我收到以下错误:

glDrawElementsInstancedANGLE:尝试使用具有非零除数的所有属性进行绘制

在 WebGL 2 实例化中是否只允许使用顶点属性(实例化数组)?

此外,是 spec了解这些功能的唯一权威地点?

最佳答案

根据下面的错误报告,该问题似乎已得到修复。这是一个小的工作示例

function main() {
const gl = document.querySelector('canvas').getContext('webgl2');
if (!gl) {
return alert('need webgl2');
}
const vs = `#version 300 es
void main() {
float angle = float(gl_InstanceID) / 10.0 * 2.0 * radians(180.0);
float radius = float(gl_VertexID + 1) / 4.0 * 0.8;
gl_Position = vec4(vec2(sin(angle), cos(angle)) * radius, 0, 1);
gl_PointSize = mix(5.0, 20.0, float(gl_VertexID) / 3.0);
}
`;

const fs = `#version 300 es
precision highp float;
out vec4 foo;
void main() {
foo = vec4(1, 0, 0, 1);
}
`;

const prg = twgl.createProgram(gl, [vs, fs]);
gl.useProgram(prg);
gl.drawArraysInstanced(gl.POINTS, 0, 4, 10);
}

main();
<canvas></canvas>
<script src="https://twgljs.org/dist/4.x/twgl.min.js"></script>

---旧答案---

spec说它基于 OpenGL ES 3.0 spec

The remaining sections of this document are intended to be read in conjunction with the OpenGL ES 3.0 specification (3.0.4 at the time of this writing, available from the Khronos OpenGL ES API Registry). Unless otherwise specified, the behavior of each method is defined by the OpenGL ES 3.0 specification. This specification may diverge from OpenGL ES 3.0 in order to ensure interoperability or security, often defining areas that OpenGL ES 3.0 leaves implementation-defined. These differences are summarized in the Differences Between WebGL and OpenGL ES 3.0 section.

不幸的是,他们似乎忘记指定至少一个属性必须具有非零除数,这与 OpenGL ES 3.0 不同。 I filed a bug

需要补充的部分是

INVALID_OPERATION is generated by DrawArraysInstanced or DrawElementsInstanced if there is not at least one enabled vertex attribute array that has a divisor of zero and is bound to an active generic attribute value in the program used for the draw command.

关于webgl2 - 在 WebGL 2 Instancing 中访问 gl_InstanceID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44427286/

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