Small fixes for mobile platform

This commit is contained in:
Илья Белов 2024-08-02 03:44:13 +03:00
commit aba18dc896
5 changed files with 19 additions and 10 deletions

View file

@ -21,7 +21,7 @@ struct IndirectDrawParams {
@group(0) @binding(2) var<storage, read_write> visibleCubes: array<Cube>; // Changed to @binding(4)
@group(0) @binding(3) var<storage, read_write> drawParams: IndirectDrawParams;
@compute @workgroup_size(64)
@compute @workgroup_size(256)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let index = global_id.x;
if (index >= arrayLength(&cubes)) {

View file

@ -22,8 +22,10 @@ import { renderPlayground } from './TouchControls2'
import { WorldRendererWebgpu } from '../viewer/lib/worldrendererWebgpu'
import { TextureAnimation } from './TextureAnimation'
import { BlockType } from './shared'
import { addNewStat } from './newStats'
const gui = new GUI()
const { updateText: updateTextEvent } = addNewStat('events', 90, 0, 40)
// initial values
const params = {
@ -214,9 +216,11 @@ async function main () {
// mouse
const mouse = { x: 0, y: 0 }
let mouseMoveCounter = 0
const mouseMove = (e: PointerEvent) => {
if ((e.target as HTMLElement).closest('.lil-gui')) return
if (e.buttons === 1 || e.pointerType === 'touch') {
mouseMoveCounter++
viewer.camera.rotation.x -= e.movementY / 100
//viewer.camera.
viewer.camera.rotation.y -= e.movementX / 100
@ -230,6 +234,10 @@ async function main () {
viewer.camera.position.set(0, 0, 0)
}
}
setInterval(() => {
updateTextEvent(`Mouse Events: ${mouseMoveCounter}`)
mouseMoveCounter = 0
}, 1000)
window.addEventListener('pointermove', mouseMove)
}
viewer.camera.position.set(0, 0, 8)

View file

@ -56,6 +56,7 @@ export class WebgpuRenderer {
this.device = await adapter.requestDevice();
const { device } = this;
this.maxBufferSize = device.limits.maxStorageBufferBindingSize;
this.renderedFrames = device.limits.maxComputeWorkgroupSizeX;
console.log('max buffer size', this.maxBufferSize / 1024 / 1024, 'MB')
const ctx = this.ctx = canvas.getContext('webgpu')!;
@ -461,9 +462,7 @@ export class WebgpuRenderer {
device.queue.writeBuffer(
uniformBuffer,
0,
ViewProjection.buffer,
ViewProjection.byteOffset,
ViewProjection.byteLength
ViewProjection
);
// const EmptyVisibleCubes = new Float32Array([36, 0, 0, 0]) ;
@ -483,7 +482,7 @@ export class WebgpuRenderer {
computePass.setPipeline(this.computePipeline);
//computePass.setBindGroup(0, this.uniformBindGroup);
computePass.setBindGroup(0, this.computeBindGroup);
computePass.dispatchWorkgroups(Math.ceil(this.NUMBER_OF_CUBES / 64));
computePass.dispatchWorkgroups(Math.ceil(this.NUMBER_OF_CUBES / 256));
computePass.end();
device.queue.submit([commandEncoder.finish()]);
commandEncoder = device.createCommandEncoder();

View file

@ -73,6 +73,7 @@ export const workerProxyType = createWorkerProxy({
},
generateRandom(count: number) {
const square = Math.sqrt(count)
if (square % 1 !== 0) throw new Error('square must be a whole number')
const blocks = {}
const getFace = (face: number) => {
return {
@ -159,12 +160,12 @@ export const workerProxyType = createWorkerProxy({
// }
},
camera (newCam) {
if (webgpuRenderer?.isPlayground) {
camera.rotation.order = 'ZYX'
new tweenJs.Tween(camera.rotation).to({ x: newCam.rotation.x, y: newCam.rotation.y, z: newCam.rotation.z }, 50).start()
} else {
// if (webgpuRenderer?.isPlayground) {
// camera.rotation.order = 'ZYX'
// new tweenJs.Tween(camera.rotation).to({ x: newCam.rotation.x, y: newCam.rotation.y, z: newCam.rotation.z }, 50).start()
// } else {
camera.rotation.set(newCam.rotation.x, newCam.rotation.y, newCam.rotation.z, 'ZYX')
}
// }
if (newCam.position.x === 0 && newCam.position.y === 0 && newCam.position.z === 0) {
// initial camera position
camera.position.set(newCam.position.x, newCam.position.y, newCam.position.z)

View file

@ -8,6 +8,7 @@
overflow: hidden;
background: black;
user-select: none;
touch-action: none;
}
html, body {