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
80 lines (62 loc) • 2.7 kB
JavaScript
export const geoInstancedTexEffect = `
// === CAMERA & INSTANCE BUFFERS ============================================
struct Camera {
viewProjMatrix : mat4x4<f32>,
};
var<uniform> camera : Camera;
struct InstanceData {
model : mat4x4<f32>,
color : vec4<f32>,
};
var<storage, read> instances : array<InstanceData>;
// === TEXTURE & SAMPLER ====================================================
var mySampler : sampler;
var myTexture : texture_2d<f32>;
// === VERTEX STAGE =========================================================
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;
let inst = instances[instanceIndex];
let worldPos = inst.model * vec4<f32>(input.position, 1.0);
out.Position = camera.viewProjMatrix * worldPos;
out.v_uv = input.uv;
out.v_color = inst.color;
return out;
}
// === FRAGMENT STAGE =======================================================
fn fsMain(input : VSOut) -> vec4<f32> {
// Adjust UV scaling and offset here
let uvScale = vec2<f32>(1.3, 1.3); // < 1.0 = zoom out (more texture visible)
let uvOffset = vec2<f32>(0.01, 0.01); // move the texture slightly
let adjustedUV = input.v_uv; // * uvScale + uvOffset; // make it like ring !
let texColor = textureSample(myTexture, mySampler, adjustedUV);
let uv = input.v_uv * 2.0 - vec2<f32>(1.0, 1.0);
let dist = length(uv);
let glow = exp(-dist * 1.2);
let glowColor = mix(vec3<f32>(0.2, 0.7, 1.0), vec3<f32>(0.8, 0.95, 1.0), glow);
let baseRGB = texColor.rgb * glowColor;
let tintedRGB = mix(baseRGB, input.v_color.rgb, 0.8);
let finalAlpha = texColor.a * input.v_color.a * glow;
return vec4<f32>(tintedRGB, finalAlpha);
// let texColor = textureSample(myTexture, mySampler, input.v_uv);
// let uv = input.v_uv * 2.0 - vec2<f32>(1.0, 1.0);
// let dist = length(uv);
// let glow = exp(-dist * 1.2);
// let glowColor = mix(vec3<f32>(0.2, 0.7, 1.0), vec3<f32>(0.8, 0.95, 1.0), glow);
// // More balanced color blending:
// let baseRGB = texColor.rgb * glowColor;
// let tintedRGB = mix(baseRGB, input.v_color.rgb, 0.8); // 0.8 gives strong tint influence
// let finalAlpha = texColor.a * input.v_color.a * glow;
// return vec4<f32>(tintedRGB, finalAlpha);
}
`;