44 lines
1.2 KiB
WebGPU Shading Language
44 lines
1.2 KiB
WebGPU Shading Language
// The `var` group() numbers match the ordering of the layouts in the
|
|
// `bindGroupLayouts` array, `0` being the 0th index of that array.
|
|
//
|
|
// The `var` binding() numbers match the numbers of the entries in
|
|
// each layout in `bindGroupLayouts`.
|
|
@group(0) @binding(0) var Sampler: sampler;
|
|
@group(0) @binding(1) var Texture: texture_2d<f32>;
|
|
|
|
// The `VertexInput` location numbers match the numbers in
|
|
// `vertexBufferLayouts`
|
|
struct VertexInput {
|
|
@location(0) position: vec3f,
|
|
@location(1) texture: vec2f,
|
|
@location(2) normal: vec3f,
|
|
};
|
|
|
|
// location numbers for passing values from the vertex stage to the
|
|
// fragment stage are arbitrary--they just need to match. Because
|
|
// fragmentMain uses the same VertexOutput struct that vertexMain
|
|
// returns, they do match.
|
|
struct VertexOutput {
|
|
@builtin(position) position: vec4f,
|
|
@location(0) texture: vec2f,
|
|
};
|
|
|
|
@vertex
|
|
fn vertexMain(input: VertexInput) -> VertexOutput
|
|
{
|
|
let position = vec4f(input.position * 0.5, 1.0);
|
|
|
|
var output: VertexOutput;
|
|
output.position = position;
|
|
output.texture = input.texture;
|
|
return output;
|
|
}
|
|
|
|
@fragment
|
|
fn fragmentMain(input: VertexOutput) -> @location(0) vec4f
|
|
{
|
|
let color = textureSample(Texture, Sampler, input.texture);
|
|
|
|
return vec4(color.xyz, 1.0);
|
|
}
|