UNPKG

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.

52 lines (41 loc) 1.42 kB
/** * @description * UNIT Texures - * Good for performance */ export const UNLIT_SHADER = `struct Uniforms { viewProjectionMatrix : mat4x4f } @group(0) @binding(0) var<uniform> uniforms : Uniforms; @group(1) @binding(0) var<uniform> modelMatrix : mat4x4f; struct VertexInput { @location(0) position : vec4f, @location(1) normal : vec3f, @location(2) uv : vec2f } struct VertexOutput { @builtin(position) position : vec4f, @location(0) normal: vec3f, @location(1) uv : vec2f, } @vertex fn vertexMain(input: VertexInput) -> VertexOutput { var output : VertexOutput; output.position = uniforms.viewProjectionMatrix * modelMatrix * input.position; output.normal = normalize((modelMatrix * vec4(input.normal, 0)).xyz); output.uv = input.uv; return output; } @group(1) @binding(1) var meshSampler: sampler; @group(1) @binding(2) var meshTexture: texture_2d<f32>; // Static directional lighting const lightDir = vec3f(0, 1, 0); const dirColor = vec3(1); const ambientColor = vec3f(0.05); @fragment fn fragmentMain(input: VertexOutput) -> @location(0) vec4f { let textureColor = textureSample(meshTexture, meshSampler, input.uv); // Very simplified lighting algorithm. let lightColor = saturate(ambientColor + max(dot(input.normal, lightDir), 0.0) * dirColor); return vec4f(textureColor.rgb * lightColor, textureColor.a); }`;