matrix-engine-wgpu
Version:
Networking implemented - based on kurento openvidu server. fix arcball camera,instanced draws added also effect pipeline blend with instancing option.Normalmap added, Fixed shadows casting vs camera/video texture, webGPU powered pwa application. Crazy fas
78 lines (70 loc) • 2.13 kB
JavaScript
export let vertexWGSL = `const MAX_BONES = 100u;
struct Scene {
lightViewProjMatrix: mat4x4f,
cameraViewProjMatrix: mat4x4f,
lightPos: vec3f,
}
struct Model {
modelMatrix: mat4x4f,
}
struct Bones {
boneMatrices : array<mat4x4f, MAX_BONES>
}
struct SkinResult {
position : vec4f,
normal : vec3f,
};
var<uniform> scene : Scene;
var<uniform> model : Model;
var<uniform> bones : Bones;
struct VertexOutput {
shadowPos: vec4f,
fragPos: vec3f,
fragNorm: vec3f,
uv: vec2f,
Position: vec4f,
}
fn skinVertex(pos: vec4f, nrm: vec3f, joints: vec4<u32>, weights: vec4f) -> SkinResult {
var skinnedPos = vec4f(0.0);
var skinnedNorm = vec3f(0.0);
for (var i: u32 = 0u; i < 4u; i = i + 1u) {
let jointIndex = joints[i];
let w = weights[i];
if (w > 0.0) {
let boneMat = bones.boneMatrices[jointIndex];
skinnedPos += (boneMat * pos) * w;
let boneMat3 = mat3x3f(
boneMat[0].xyz,
boneMat[1].xyz,
boneMat[2].xyz
);
skinnedNorm += (boneMat3 * nrm) * w;
}
}
return SkinResult(skinnedPos, skinnedNorm);
}
fn main(
position: vec3f,
normal: vec3f,
uv: vec2f,
joints: vec4<u32>,
weights: vec4<f32>
) -> VertexOutput {
var output : VertexOutput;
var pos = vec4(position, 1.0);
var nrm = normal;
let skinned = skinVertex(pos, nrm, joints, weights);
let worldPos = model.modelMatrix * skinned.position;
let normalMatrix = mat3x3f(
model.modelMatrix[0].xyz,
model.modelMatrix[1].xyz,
model.modelMatrix[2].xyz
);
output.Position = scene.cameraViewProjMatrix * worldPos;
output.fragPos = worldPos.xyz;
output.shadowPos = scene.lightViewProjMatrix * worldPos;
output.fragNorm = normalize(normalMatrix * skinned.normal);
output.uv = uv;
return output;
}`;