gpu-curtains
Version:
gpu-curtains is a 3D WebGPU rendering engine. It can be used as a standalone 3D engine, but also includes extra classes focused on mapping 3d objects to DOM elements; It allows users to synchronize values such as position, sizing, or scale between them.
27 lines (26 loc) • 1.04 kB
JavaScript
//#region src/core/shaders/chunks/vertex/body/declare-attributes-vars.ts
/**
* Declare all the provided {@link Geometry} attributes as variables.
* @param parameters - Parameters used to declare the attributes variables.
* @param parameters.geometry - {@link Geometry} used to declare the attributes variables.
* @returns - A string with all the attributes variables declared.
*/
const declareAttributesVars = ({ geometry }) => {
let attributeVars = geometry.vertexBuffers.map((vertexBuffer) => vertexBuffer.attributes.map((attribute) => {
let { name, type } = attribute;
let swizzle = "";
if (name === "position" || name === "normal") {
type = "vec3f";
swizzle = ".xyz";
} else if (name === "tangent") type = "vec4f";
else if (name.indexOf("uv") !== -1) type = "vec2f";
return `
var ${name}: ${type} = ${type}(attributes.${name}${swizzle});`;
}).join("")).join("\n");
attributeVars += `
var instanceIndex: u32 = attributes.instanceIndex;
`;
return attributeVars;
};
//#endregion
export { declareAttributesVars };