-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setting up mesh for triangle, trying to get transformations
- Loading branch information
1 parent
7a0ac23
commit a01a833
Showing
6 changed files
with
156 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const makeBuffer = (device: GPUDevice) => { | ||
// each row contains 3 position values, 3 color values, 3 full points here | ||
const vertices = new Float32Array([ | ||
0.0, 0.5, 1.0, 0.0, 0.0, | ||
-0.5, -0.5, 0.0, 1.0, 0.0, | ||
0.5, -0.5, 0.0, 0.0, 1.0 | ||
]); | ||
|
||
const descriptor: GPUBufferDescriptor = { | ||
size: vertices.byteLength, | ||
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST, | ||
mappedAtCreation: true | ||
}; | ||
|
||
const buffer = device.createBuffer(descriptor); | ||
new Float32Array(buffer.getMappedRange()).set(vertices); | ||
buffer.unmap(); | ||
|
||
const bufferLayout: GPUVertexBufferLayout = { | ||
arrayStride: 20, | ||
attributes: [ | ||
{ | ||
shaderLocation: 0, | ||
format: "float32x2", | ||
offset: 0 | ||
}, | ||
{ | ||
shaderLocation: 1, | ||
format: "float32x3", | ||
offset: 8 | ||
} | ||
] | ||
} | ||
|
||
return { | ||
buffer, | ||
bufferLayout | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
struct Transform { | ||
model: mat4x4<f32>, | ||
view: mat4x4<f32>, | ||
projection: mat4x4<f32> | ||
} | ||
@binding(0) @group(0) var<uniform> transformUBO: Transform; | ||
|
||
struct Fragment { | ||
@builtin(position) Position : vec4<f32>, | ||
@location(0) Color : vec4<f32> | ||
} | ||
|
||
@vertex | ||
fn vs_main( | ||
@location(0) vertexPos: vec2<f32>, | ||
@location(1) vertexCol: vec3<f32>) -> Fragment { | ||
|
||
var output: Fragment; | ||
output.Position = vec4<f32>(vertexPos, 0.0, 1.0); | ||
output.Color = vec4<f32>(vertexCol, 1.0); | ||
|
||
return output; | ||
} | ||
|
||
@fragment | ||
fn fs_main(@location(0) Color: vec4<f32>) -> @location(0) vec4<f32> { | ||
return Color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.