Slide 18
Slide 18 text
Copyright (C) 2024 Toranoana Lab Inc. All Rights Reserved.
Denoの概要 - Denoの主要な機能と利点
18
const vertexShaderSource = `
struct Uniforms {
modelViewProjectionMatrix : mat4x4,
}
@binding(0) @group(0) var uniforms : Uniforms;
struct VertexOutput {
@builtin(position) Position : vec4,
@location(0) fragUV : vec2,
@location(1) fragPosition: vec4,
}
@vertex
fn main(
@location(0) position : vec4,
@location(1) uv : vec2
) -> VertexOutput {
var output : VertexOutput;
output.Position = uniforms.modelViewProjectionMatrix * position;
output.fragUV = uv;
output.fragPosition = 0.5 * (position + vec4(1.0, 1.0, 1.0, 1.0));
return output;
}`;
const fragmentShaderSource = `
@fragment
fn main(
@location(0) fragUV: vec2,
@location(1) fragPosition: vec4
) -> @location(0) vec4 {
return fragPosition;
}`;
// Create a vertex buffer from the cube data.
const verticesBuffer = device.createBuffer({
size: cubeVertexArray.byteLength,
usage: GPUBufferUsage.VERTEX,
mappedAtCreation: true,
});
new Float32Array(verticesBuffer.getMappedRange()).set(cubeVertexArray);
verticesBuffer.unmap();
// シェーダーモジュールの作成
const vertexShaderModule = device.createShaderModule({
code: vertexShaderSource,
});
const fragmentShaderModule = device.createShaderModule({
code: fragmentShaderSource,
});