@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
55 lines (44 loc) • 1.3 kB
text/typescript
import { FullscreenPass, type FullscreenPassOptions } from './FullscreenPass.js';
const FULLSCREEN_BLIT_SHADER = `
struct MotionGPUVertexOut {
position: vec4f,
uv: vec2f,
};
var motiongpuBlitSampler: sampler;
var motiongpuBlitTexture: texture_2d<f32>;
fn motiongpuBlitVertex( index: u32) -> MotionGPUVertexOut {
var positions = array<vec2f, 3>(
vec2f(-1.0, -3.0),
vec2f(-1.0, 1.0),
vec2f(3.0, 1.0)
);
let position = positions[index];
var out: MotionGPUVertexOut;
out.position = vec4f(position, 0.0, 1.0);
out.uv = (position + vec2f(1.0, 1.0)) * 0.5;
return out;
}
fn motiongpuBlitFragment(in: MotionGPUVertexOut) -> vec4f {
return textureSample(motiongpuBlitTexture, motiongpuBlitSampler, in.uv);
}
`;
export type BlitPassOptions = FullscreenPassOptions;
/**
* Fullscreen texture blit pass.
*/
export class BlitPass extends FullscreenPass {
protected getProgram(): string {
return FULLSCREEN_BLIT_SHADER;
}
constructor(options: BlitPassOptions = {}) {
super(options);
}
protected getVertexEntryPoint(): string {
return 'motiongpuBlitVertex';
}
protected getFragmentEntryPoint(): string {
return 'motiongpuBlitFragment';
}
}