add plane model by hand

This commit is contained in:
41666 2023-10-07 23:29:53 -04:00
parent 96e992467f
commit 22e9cb094d
5 changed files with 24 additions and 43 deletions

File diff suppressed because one or more lines are too long

View file

@ -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();

View file

@ -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

View file

@ -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,
});

View file

@ -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: {