OpenGL: Ein Vertex-Attribut für mehrere Vertices?
Ich habe einen Vertex-Shader, der die folgenden Attribute akzeptiert:
a_posCoord
: Scheitelpunktpositiona_texCoord
: Texturkoordinate (an den Fragment-Shader übergeben)a_alpha
: Transparenzfaktor (an den Fragment-Shader übergeben)Die Objekte, die ich rendere, sind alle "Werbetafeln" (ein Paar rechtwinkliger Dreiecke, um ein Rechteck zu bilden).
Ich benutze einen einzigen Anruf anglDrawArrays
zu rendernviele Werbetafeln, von denen jede einen eindeutigen Alpha-Wert haben kann. Eine einzelne Plakatwand hat 6 Eckpunkte. Hier ist ein Pseudocode, um zu veranschaulichen, wie ich den Vertex-Attributpuffer für eine einzelne Werbetafel organisiere:
vertexAttributes = [
px1,py1,pz1, // vertex 1: a_posCoord
tx1,ty1, // vertex 1: a_texCoord
alpha, // vertex 1: a_alpha
px2,py2,pz2, // vertex 2: a_posCoord
tx2,ty2, // vertex 2: a_texCoord
alpha, // vertex 2: a_alpha
px3,py3,pz3, // vertex 3: a_posCoord
tx3,ty3, // vertex 3: a_texCoord
alpha, // vertex 3: a_alpha
px4,py4,pz4, // vertex 4: a_posCoord
tx4,ty4, // vertex 4: a_texCoord
alpha, // vertex 4: a_alpha
px5,py5,pz5, // vertex 5: a_posCoord
tx5,ty5, // vertex 5: a_texCoord
alpha, // vertex 5: a_alpha
px6,py6,pz6, // vertex 6: a_posCoord
tx6,ty6, // vertex 6: a_texCoord
alpha // vertex 6: a_alpha
// ... Many more billboards not shown ...
];
Beachten Sie, wie das gleichealpha
Der Wert wird sechsmal wiederholt, einmal für jeden Scheitelpunkt.
Gibt es eine Möglichkeit, ein Attribut für alle 6 Scheitelpunkte anzugeben, ohne es für jeden einzelnen Scheitelpunkt zu wiederholen?
Ich möchte, dass mein Vertex-Attributpuffer so aussieht, um die Größe des Puffers zu verringern:
vertexAttributes = [
px1,py1,pz1, // vertex 1: a_posCoord
tx1,ty1, // vertex 1: a_texCoord
px2,py2,pz2, // vertex 2: a_posCoord
tx2,ty2, // vertex 2: a_texCoord
px3,py3,pz3, // vertex 3: a_posCoord
tx3,ty3, // vertex 3: a_texCoord
px4,py4,pz4, // vertex 4: a_posCoord
tx4,ty4, // vertex 4: a_texCoord
px5,py5,pz5, // vertex 5: a_posCoord
tx5,ty5, // vertex 5: a_texCoord
px6,py6,pz6, // vertex 6: a_posCoord
tx6,ty6, // vertex 6: a_texCoord
alpha // vertex 1-6: a_alpha
// ... Many more billboards not shown ...
];
Für das, was es wert ist, funktioniert meine aktuelle Lösung einwandfrei, aber ich fühle mich schmutzig. Ich habe gerade erst angefangen, die Benutzung in den Griff zu bekommenglVertexAttribPointer
und fragte mich, ob es so etwas irgendwie unterstützt oder ob es eine andere Methode oder Technik gibt, mit der ich etwas weniger Brute-Force erreichen könnte.
Dies ist insbesondere eine WebGL-Frage, aber ich bin neugierig auf OpenGL im allgemeinen Sinne.
Ich bin mir bewusst, dass ein Geometrie-Shader genau das ist, was ich für dieses Beispiel benötige, aber es kommt nicht in Frage, da sie derzeit in WebGL nicht unterstützt werden.