Skip to content

@blooper.gg/toodle


@blooper.gg/toodle / shaders/wgsl/helloInstanced.wgsl / default

Variable: default

default: "\n// const pos = array(vec2f(-0.5, -0.5), vec2f(0.5, -0.5), vec2f(-0.5, 0.5), vec2f(0.5, 0.5));\nconst pos = array(vec2f(-0.5, 0.5), vec2f(-0.5, -0.5), vec2f(0.5, 0.5), vec2f(0.5, -0.5));\n\nstruct InstanceData {\n @location(0) model0: vec4<f32>,\n @location(1) model1: vec4<f32>,\n @location(2) model2: vec4<f32>,\n @location(3) color: vec4<f32>,\n}\nstruct VertexOutput {\n @builtin(position) engine_clip_position : vec4<f32>,\n @location(0) @interpolate(flat) color: vec4<f32>,\n}\n\nstruct EngineUniform {\n viewProjection: mat3x3<f32>,\n};\n\n@group(0) @binding(0) var<uniform> engineUniform: EngineUniform;\n\n\n// this is the vertex shader\n@vertex\nfn vs(\n @builtin(vertex_index) VertexIndex : u32,\n @builtin(instance_index) InstanceIndex: u32, // Instance ID for each instance\n instanceData: InstanceData,\n) -> VertexOutput {\n var output : VertexOutput;\n let modelMatrix = mat3x3(instanceData.model0.xyz, instanceData.model1.xyz, instanceData.model2.xyz);\n let worldPosition = engineUniform.viewProjection * modelMatrix * vec3f(pos[VertexIndex], 1.0);\n\n output.engine_clip_position = vec4f(worldPosition, 1.0);\n output.color = instanceData.color;\n return output;\n}\n\n// this is the fragment shader\n@fragment\nfn fs(vertex: VertexOutput) -> @location(0) vec4<f32> {\n return vertex.color;\n}\n"

Defined in: shaders/wgsl/helloInstanced.wgsl.ts:3