render: pack HardwareVertex from 88 to 48 bytes

Colour as UBYTE4_NORM, normals as SHORT4_NORM (unit direction, the
shader renormalises), bones as UBYTE4 and weights as USHORT4_NORM.
Shader inputs keep their float/uint types, so the shaders are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 16:33:19 +09:00
co-authored by Claude Opus 5.5
parent 545cbb1e5d
commit aaee4c8f70
3 changed files with 28 additions and 15 deletions
+3 -3
View File
@@ -29,7 +29,7 @@ int main() {
std::vector<ava2::HardwareVertex> vertices;
auto triangle=[&](float z,float r,float g,float b,float alpha) {
for(auto p: {std::pair{-0.9f,-0.9f},std::pair{0.9f,-0.9f},std::pair{0.f,0.9f}})
vertices.push_back({{p.first,p.second,z,1},{r,g,b,alpha},{0,0}});
vertices.push_back({{p.first,p.second,z,1},{uint8_t(r*255),uint8_t(g*255),uint8_t(b*255),uint8_t(alpha*255)},{0,0}});
};
triangle(.2,1,0,0,1);triangle(.8,0,1,0,1);triangle(.1,0,0,1,.2);
std::vector<uint32_t> indices{0,1,2,3,4,5,6,7,8};
@@ -59,7 +59,7 @@ int main() {
// Perspective-correct color interpolation: top W=2 doubles its reciprocal denominator.
auto saved=vertices;
vertices[2].position[1]*=2;vertices[2].position[2]*=2;vertices[2].position[3]=2;
vertices[0].color[0]=vertices[1].color[0]=0;vertices[2].color[0]=1;
vertices[0].color[0]=vertices[1].color[0]=0;vertices[2].color[0]=255;
near.cull=1;color=center({near});assert(color[0]>65&&color[0]<100);
vertices=saved;
// Newly uploaded textures must be usable on their first frame, even
@@ -167,7 +167,7 @@ int main() {
left.geometry=skinned;pixels=frame({left});
std::vector<ava2::HardwareVertex> reference;
for(size_t v=0;v<3;++v){auto vertex=ava2::MakeHardwareVertex(*skinned,v);float pos[4]{};
for(size_t b=0;b<2;++b){const auto* matrix=left.palette->data()+b*16;float w=vertex.weights[b];
for(size_t b=0;b<2;++b){const auto* matrix=left.palette->data()+b*16;float w=vertex.weights[b]/65535.f;
for(int k=0;k<4;++k)pos[k]+=(vertex.position[0]*matrix[k]+vertex.position[1]*matrix[k+4]+vertex.position[2]*matrix[k+8]+matrix[k+12])*w;}
std::copy_n(pos,4,vertex.position);vertex.position[0]-=.5f;reference.push_back(vertex);}
ava2::HardwareBatch cpu{};cpu.indexCount=3;cpu.cull=1;cpu.depth=true;cpu.depthWrite=true;cpu.alphaRef=-1;