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
50 lines (43 loc) • 1.47 kB
JavaScript
export const geoInstancedEffect = `struct Camera {
viewProjMatrix : mat4x4<f32>,
};
var<uniform> camera : Camera;
// --- INSTANCE STORAGE BUFFER ----------------------------------------------
struct InstanceData {
model : mat4x4<f32>,
color : vec4<f32>,
};
var<storage, read> instances : array<InstanceData>;
struct VertexInput {
position : vec3<f32>,
uv : vec2<f32>,
};
struct VSOut {
Position : vec4<f32>,
v_uv : vec2<f32>,
v_color : vec4<f32>,
};
fn vsMain(input : VertexInput, instanceIndex: u32) -> VSOut {
var out : VSOut;
// Use per-instance model matrix & color
let modelMatrix = instances[instanceIndex].model;
let color = instances[instanceIndex].color;
let worldPos = modelMatrix * vec4<f32>(input.position,1.0);
out.Position = camera.viewProjMatrix * worldPos;
out.v_uv = input.uv;
out.v_color = color;
return out;
}
fn fsMain(input : VSOut) -> vec4<f32> {
let uv = input.v_uv * 2.0 - vec2<f32>(1.0, 1.0);
let dist = length(uv);
let glow = exp(-dist * 1.0);
let baseColor = vec3<f32>(0.2, 0.7, 1.0);
let glowColor = vec3<f32>(0.7, 0.9, 1.0);
let color = mix(baseColor, glowColor, glow) * glow * input.v_color.rgb;
let alpha = input.v_color.a;
return vec4<f32>(color, alpha);
}
`;