playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
3 lines (2 loc) • 1.97 kB
TypeScript
declare const _default: "\n\nattribute vertex_position: vec2f;\n\n// Sub-draw data texture: RGBA32U\n// R = rowStart | (numRows << 16)\n// G = colStart\n// B = colEnd\n// A = sourceBase\nvar uSubDrawData: texture_2d<u32>;\nuniform uTextureSize: vec2i; // (width, height)\nuniform uSubDrawBase: i32;\n\n// packed sub-draw params: (sourceBase, colStart, rowWidth, rowStart)\nvarying @interpolate(flat) vSubDraw: vec4i;\n\n@vertex\nfn vertexMain(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n\n // Read sub-draw parameters from 2D data texture\n let subDrawWidth = i32(textureDimensions(uSubDrawData, 0).x);\n let instIdx = i32(input.instanceIndex) + uniform.uSubDrawBase;\n let data = textureLoad(uSubDrawData, vec2i(instIdx % subDrawWidth, instIdx / subDrawWidth), 0);\n let rowStart = i32(data.r & 0xFFFFu);\n let numRows = i32(data.r >> 16u);\n let colStart = i32(data.g);\n let colEnd = i32(data.b);\n let sourceBase = i32(data.a);\n\n // Quad corner from vertexIndex (0-3 via index buffer [0,1,2, 2,1,3])\n let u = f32(i32(input.vertexIndex) & 1); // 0 or 1 (left or right)\n let v = f32(i32(input.vertexIndex) >> 1u); // 0 or 1 (bottom or top)\n\n // Map to NDC within the viewport\n // WebGPU viewport transform inverts Y: y_pixel = viewport.y + viewport.h * (1 - y_ndc) / 2\n // so we negate Y compared to the GLSL version to get correct row positioning\n let ndc = vec4f(f32(colStart), f32(colEnd), f32(rowStart), f32(rowStart + numRows)) / vec4f(f32(uniform.uTextureSize.x), f32(uniform.uTextureSize.x), f32(uniform.uTextureSize.y), f32(uniform.uTextureSize.y)) * 2.0 - 1.0;\n\n output.position = vec4f(mix(ndc.x, ndc.y, u), mix(-ndc.z, -ndc.w, v), 0.5, 1.0);\n\n // Output packed flat varying: (sourceBase, colStart, rowWidth, rowStart)\n output.vSubDraw = vec4i(sourceBase, colStart, colEnd - colStart, rowStart);\n\n return output;\n}\n";
export default _default;