matrix-engine-wgpu
Version:
obj sequence anim +HOTFIX raycast, webGPU powered pwa application. Crazy fast rendering with AmmoJS physics support. Simple raycaster hit object added.
49 lines (40 loc) • 1.19 kB
JavaScript
export let vertexWGSL = `struct Scene {
lightViewProjMatrix: mat4x4f,
cameraViewProjMatrix: mat4x4f,
lightPos: vec3f,
}
struct Model {
modelMatrix: mat4x4f,
}
var<uniform> scene : Scene;
var<uniform> model : Model;
struct VertexOutput {
shadowPos: vec3f,
fragPos: vec3f,
fragNorm: vec3f,
uv : vec2f,
Position: vec4f,
}
fn main(
position: vec3f,
normal: vec3f,
uv : vec2f
) -> VertexOutput {
var output : VertexOutput;
// XY is in (-1, 1) space, Z is in (0, 1) space
let posFromLight = scene.lightViewProjMatrix * model.modelMatrix * vec4(position, 1.0);
// Convert XY to (0, 1)
// Y is flipped because texture coords are Y-down.
output.shadowPos = vec3(
posFromLight.xy * vec2(0.5, -0.5) + vec2(0.5),
posFromLight.z
);
output.Position = scene.cameraViewProjMatrix * model.modelMatrix * vec4(position, 1.0);
output.fragPos = output.Position.xyz;
output.fragNorm = normal;
// nidza
output.uv = uv;
return output;
}
`;