[ad_1]
If I am rendering quads, but all the quads will be axis-aligned (that is, their plane is always parallel to either the X Y or Z plane), I thought I could cut vertex video memory usage in half by passing opposite corners (6 floats) instead of all corners (12 floats) to the vertex shader per instance. Provided to the shader would be a buffer of these opposing corners and a per-instance vertex ID which would be from [0, 4)
.
There are 3 orderings for vertices in a quad, which I call C, Z, and X, where C is the most standard. This determine which vertex ID corresponds to which corner. Here are some graphs to illustrate the relationship between the vertex ID and the corresponding corner:
C:
3----2
|
|
0----1
Z:
2----3
\
\
\
\
0----1
X:
2----1
\ /
\/
/\
/ \
0 3
I would like to be able to, given only the ID and 2 vertices, determine the location in 3D space of the vertex corresponding to ID. If the planes are axis-aligned, I could pass a normal ID and use a switch
statement or so in the shader but I would prefer to be able to do this implicitly. Since the planes are axis-aligned one of the coordinates in one of the points will equal the corresponding coordinate in the other plane.
I have thought about how I can arrange the data into a new vertex given only vertex-ID and 2 opposite points but I ran into a difficulty. For each of the 4 points, I either use an XYZ value from the low or high corner. I know that if I go with C, for example, if vertex ID is 0 the result will just be the lower vertex and if the ID is 2 the result will be the higher one.
But for the other 2, I will need to grab some values from the lower vertex and some from the higher vertex. But given only vertex ID, no matter what I try, I cannot seem to be able to produce a quad whose vertex order (C/Z/X) is consistent. For example if I make a table (l
or h
means the resulting vertex will have the corresponding coordinate from the low or high vertex respectively):
VID 0 1 2 3
Dim
0 l l h h
1 l h h l
2 l h l h
This does create squares with correct coordinates given the vertex ID and only 2 opposite corners corresponding to the square, but the issue is, if the square is X-aligned, the resulting vertex ordering is X-style, Y-aligned gives Z-style ordering, and Z-aligned gives C-style ordering. I need them to have consistent ordering.
I have thought about all these tables I could make about which (low/high) vertex we pick an XYZ coordinate from given the vertex ID, and there are only 4096 possibilities, and none of them seem to satisfy the requirements of giving a consistent vertex-ordering style. So this alone cannot solve the problem. I will need some other strategy.
This question is more theoretical than programmatic, but how can I, given only 2 opposing vertices and a vertex ID, get the Nth vertex corresponding of 4 vertices of a square described by the opposite vertices, where the resulting vertex-ordering is correct and consistent?
[ad_2]