轻量封装WebGPU渲染系统示例<1>-彩色三角形(源码)

当前示例源码github地址 : https://github.com/vilyLei/voxwebgpu/blob/version-1.01/src/voxgpu/sample/VertColorTriangle.ts

此示例渲染系统实现的特性:

  1. 用户态与系统态隔离。

  2. 高频调用与低频调用隔离。

  3. 面向用户的易用性封装。

  4. 渲染数据和渲染机制分离。

  5. 用户操作和渲染系统调度并行机制。

当前示例运行效果:

此示例基于此渲染系统实现,当前示例TypeScript源码如下

javascript 复制代码
const positions = new Float32Array([-1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, 0.0]);
const colors = new Float32Array([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]);

export class VertColorTriangle {

	renderer = new WGRenderer();

	initialize(): void {
		console.log("VertColorTriangle::initialize() ...");
		this.createEntity();
	}
	private createEntity(): void {
		const renderer = this.renderer;

		const shdSrc = {
			vertShaderSrc: { code: vertWGSL, uuid: "vtxShdCode" },
			fragShaderSrc: { code: fragWGSL, uuid: "fragShdCode" }
		};
		const material = new WGMaterial({
			shadinguuid: "shapeMaterial",
			shaderCodeSrc: shdSrc
		});

		const geometry = new WGGeometry().addAttributes([
			{ shdVarName: "position", data: positions, strides: [3] },
			{ shdVarName: "color", data: colors, strides: [3] }
		]);

		const entity = new Entity3D(false);
		entity.materials = [material];
		entity.geometry = geometry;
		entity.applyCamera(this.renderer.camera);

		renderer.addEntity(entity);
	}
	run(): void {
		this.renderer.run();
	}
}
相关推荐
多恩Stone19 小时前
【3D AICG 系列-6】OmniPart 训练流程梳理
人工智能·pytorch·算法·3d·aigc
晚霞的不甘1 天前
揭秘 CANN 内存管理:如何让大模型在小设备上“轻装上阵”?
前端·数据库·经验分享·flutter·3d
哈__2 天前
CANN加速3D目标检测推理:点云处理与特征金字塔优化
目标检测·3d·目标跟踪
心疼你的一切2 天前
三维创世:CANN加速的实时3D内容生成
数据仓库·深度学习·3d·aigc·cann
3DVisionary2 天前
掌控发动机“心脏”精度:蓝光3D扫描在凸轮轴全尺寸检测中的应用
3d·图形渲染·汽车发动机·精密测量·蓝光3d扫描·凸轮轴检测·形位公差
coder攻城狮2 天前
VTK系列1:在屏幕绘制多边形
c++·3d
PHOSKEY3 天前
3D工业相机如何“读透”每一个字符?快速识别、高精度3D测量
数码相机·3d
XX風3 天前
7.2 harris 3d
3d
多恩Stone3 天前
【3D-AICG 系列-3】Trellis 2 的O-voxel (下) Material: Volumetric Surface Attributes
人工智能·3d·aigc
多恩Stone3 天前
【3D-AICG 系列-1】Trellis v1 和 Trellis v2 的区别和改进
人工智能·pytorch·python·算法·3d·aigc