import tgpu, { d } from 'typegpu';
const root = await tgpu.init();
const Vertex = d.struct({
position: d.vec3f,
roughness: d.f32,
});
const vertexLayout = tgpu.vertexLayout(d.arrayOf(Vertex));
const fragment = tgpu.fragmentFn({
in: { roughness: d.f32 },
out: d.vec4f,
})(({ roughness }) => {
'use gpu';
return d.vec4f(roughness, 0, 0, 1);
});
root.createRenderPipeline({
attribs: vertexLayout.attrib,
// Shell-less vertex: roughness is inferred as value type `number`
vertex: ({ position, roughness }) => {
'use gpu';
return {
$position: d.vec4f(position, 1),
roughness,
};
},
// Typed fragment: roughness requires schema type `d.F32`
fragment,
targets: { format: 'rgba8unorm' },
});