add plane model by hand
This commit is contained in:
parent
96e992467f
commit
22e9cb094d
5 changed files with 24 additions and 43 deletions
File diff suppressed because one or more lines are too long
|
@ -1,14 +1,9 @@
|
||||||
import { WebGPUApp } from "../renderer/webgpu";
|
import { WebGPUApp } from "../renderer/webgpu";
|
||||||
import Torus from "../meshes/torus";
|
|
||||||
import { MeshRenderer } from "../renderer/mesh-renderer";
|
import { MeshRenderer } from "../renderer/mesh-renderer";
|
||||||
|
import plane from "../meshes/plane";
|
||||||
|
|
||||||
const app = new WebGPUApp({ fov: 20 });
|
const app = new WebGPUApp({ fov: 20 });
|
||||||
|
|
||||||
// TODO:
|
const renderer = new MeshRenderer(app, plane);
|
||||||
// - torus!
|
|
||||||
// - white shader
|
|
||||||
// - real shader with UVs and uniforms
|
|
||||||
|
|
||||||
const torusRenderer = new MeshRenderer(app, Torus);
|
|
||||||
|
|
||||||
app.start();
|
app.start();
|
||||||
|
|
|
@ -7,7 +7,8 @@ struct Uniforms {
|
||||||
|
|
||||||
struct v2f {
|
struct v2f {
|
||||||
@builtin(position) position : vec4f,
|
@builtin(position) position : vec4f,
|
||||||
@location(0) uv : vec2f,
|
@location(0) color : vec4f,
|
||||||
|
@location(1) uv : vec2f,
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { Mesh } from "../renderer/mesh";
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
const mesh = new Float32Array([
|
||||||
|
// f4 position, f4 color, f2 uv
|
||||||
|
-1, -1, 0, 1, 1, 1, 1, 1, 0, 0,
|
||||||
|
1, -1, 0, 1, 1, 1, 1, 1, 1, 0,
|
||||||
|
-1, 1, 0, 1, 1, 1, 1, 1, 0, 1,
|
||||||
|
1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export default new Mesh({
|
||||||
|
mesh,
|
||||||
|
positionSize: 4 * 4,
|
||||||
|
colorSize: 4 * 4,
|
||||||
|
uvSize: 2 * 4,
|
||||||
|
});
|
|
@ -9,15 +9,8 @@ export type MeshConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Mesh {
|
export class Mesh {
|
||||||
private _shader: Shader = Oops;
|
|
||||||
|
|
||||||
constructor(public config: MeshConfig) {}
|
constructor(public config: MeshConfig) {}
|
||||||
|
|
||||||
shader(shader: Shader) {
|
|
||||||
this._shader = shader;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer(app: WebGPUApp) {
|
buffer(app: WebGPUApp) {
|
||||||
const buffer = app.device.createBuffer({
|
const buffer = app.device.createBuffer({
|
||||||
size: this.config.mesh.byteLength,
|
size: this.config.mesh.byteLength,
|
||||||
|
@ -30,8 +23,8 @@ export class Mesh {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline(app: WebGPUApp, config: Record<string, any>) {
|
pipeline(app: WebGPUApp, shader: Shader, config: Record<string, any>) {
|
||||||
const module = this._shader.module(app);
|
const module = shader.module(app);
|
||||||
return app.device.createRenderPipeline({
|
return app.device.createRenderPipeline({
|
||||||
layout: "auto",
|
layout: "auto",
|
||||||
vertex: {
|
vertex: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue