Skip to content

Commit

Permalink
fix: update latest device api
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Jan 2, 2024
1 parent 773f861 commit 02c228d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 43 deletions.
24 changes: 12 additions & 12 deletions examples/demos/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ export async function render($canvas: HTMLCanvasElement, gui: lil.GUI) {
}),
);

// const mesh2 = Mesh.from(Plane.from_size(10));
// const material2 = new Material({
// base_color: Color.WHITE,
// perceptual_roughness: 1.0,
// });
// this.commands.spawn(
// new PbrBundle({
// mesh: mesh2,
// material: material2,
// transform: Transform.from_xyz(0, 0, 0),
// }),
// );
const mesh2 = Mesh.from(Plane.from_size(10));
const material2 = new Material({
base_color: Color.WHITE,
perceptual_roughness: 1.0,
});
this.commands.spawn(
new PbrBundle({
mesh: mesh2,
material: material2,
transform: Transform.from_xyz(0, 0, 0),
}),
);

this.commands.execute();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"homepage": "https://github.com/xiaoiver/renderer#readme",
"dependencies": {
"@antv/g-device-api": "^1.4.8",
"@antv/g-device-api": "^1.4.14",
"@lastolivegames/becsy": "^0.15.9",
"gl-matrix": "^3.4.3",
"hammerjs": "^2.0.8",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/shaders/fxaa.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

#import fullscreen_vertex_shader::FullscreenVertexOutput

@group(0) @binding(0) var screenTexture: texture_2d<f32>;
@group(0) @binding(1) var samp: sampler;

@group(1) @binding(0) var screenTexture: texture_2d<f32>;
@group(1) @binding(1) var samp: sampler;

// Trims the algorithm from processing darks.
#ifdef EDGE_THRESH_MIN_LOW
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/mesh/mesh_bindings.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// #ifdef PER_OBJECT_BUFFER_BATCH_SIZE
// @group(2) @binding(0) var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
// #else
@group(0) @binding(30) var<storage> mesh: array<Mesh>;
@group(2) @binding(0) var<storage> mesh: array<Mesh>;
// #endif // PER_OBJECT_BUFFER_BATCH_SIZE

// #endif // MESH_BINDGROUP_1
19 changes: 10 additions & 9 deletions src/systems/ExtractMeshes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Mesh } from '../meshes';
import { GlobalTransform } from '../components';

/**
* Since we can only use `@group(0)` in device api for now,
* just use no.`30` binding.
* We use `@group(2)` in device api for now.
*/
export const MESH_BINDING = 30;
export const MESH_BINDING = 0;

/**
* Extract meshes and generate a storage buffer.
Expand All @@ -32,7 +31,7 @@ export class ExtractMeshes extends System {

initialize(): void {
this.meshStorageBuffer = this.device.createBuffer({
viewOrSize: new Float32Array(100),
viewOrSize: new Float32Array(1000),
usage: BufferUsage.STORAGE,
});
}
Expand Down Expand Up @@ -70,10 +69,12 @@ export class ExtractMeshes extends System {
// flags: mesh_transforms.flags,
}

// Set mesh storage buffer
this.meshStorageBuffer.setSubData(
0,
new Uint8Array(new Float32Array(meshStorageBufferData).buffer),
);
if (this.renderables.addedOrChanged.length) {
// Set mesh storage buffer
this.meshStorageBuffer.setSubData(
0,
new Uint8Array(new Float32Array(meshStorageBufferData).buffer),
);
}
}
}
23 changes: 10 additions & 13 deletions src/systems/PrepareLights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ export class PrepareLights extends System {
private pipeline = this.attach(MeshPipeline);

private ambient_lights = this.query(
(q) =>
q.addedOrChanged.with(AmbientLight).trackWrites.and.with(AmbientLight)
.current,
(q) => q.addedOrChanged.with(AmbientLight).trackWrites,
);
private ambient_lights_query = this.query(
(q) => q.current.with(AmbientLight).read,
);
private directional_lights = this.query(
(q) =>
q.addedOrChanged
.with(ExtractedDirectionalLight)
.trackWrites.and.with(ExtractedDirectionalLight).current,
(q) => q.addedOrChanged.with(ExtractedDirectionalLight).trackWrites,
);
private directional_lights_query = this.query((q) =>
q.current.with(ExtractedDirectionalLight),
);
// private ambient_lights = this.query((q) => q.current.with(AmbientLight).read);
// private directional_lights = this.query(
// (q) => q.current.with(ExtractedDirectionalLight).read,
// );

async prepare() {
this.prepareUniforms = (template, binding) => {
Expand All @@ -61,7 +58,7 @@ export class PrepareLights extends System {

if (updated) {
let ambient_color = Vec4.ZERO;
this.ambient_lights.addedOrChanged.forEach((entity) => {
this.ambient_lights_query.current.forEach((entity) => {
this.pipeline.passesChanged = true;
const ambient_light = entity.read(AmbientLight);
ambient_color = new Vec4(
Expand Down Expand Up @@ -93,7 +90,7 @@ export class PrepareLights extends System {
.map(() => new Array(96).fill(0));
let num_directional_cascades_enabled = 0;

this.directional_lights.addedOrChanged.forEach((entity, index) => {
this.directional_lights_query.current.forEach((entity, index) => {
const light = entity.read(ExtractedDirectionalLight);
this.pipeline.passesChanged = true;

Expand Down

0 comments on commit 02c228d

Please sign in to comment.