From afd4c4cf74860ec237d94b92f19c8a3569ac89f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=91=D0=B5=D0=BB=D0=BE=D0=B2?= Date: Fri, 20 Dec 2024 01:26:24 +0300 Subject: [PATCH] Small fixes --- prismarine-viewer/examples/Cube.vert.wgsl | 25 ++++++++----------- .../viewer/lib/worldrendererCommon.ts | 18 ++++++------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/prismarine-viewer/examples/Cube.vert.wgsl b/prismarine-viewer/examples/Cube.vert.wgsl index 764411217..9717e8a94 100644 --- a/prismarine-viewer/examples/Cube.vert.wgsl +++ b/prismarine-viewer/examples/Cube.vert.wgsl @@ -11,7 +11,6 @@ struct Chunk{ length: i32 } - struct CubePointer { ptr: u32 } @@ -43,27 +42,25 @@ fn main( ) -> VertexOutput { let normalIndex = visibleCubes[instanceIndex].ptr & 7; let cube = cubes[visibleCubes[instanceIndex].ptr >> 3]; - //let chunkIndex = (cube.cube[1] >> 24) + ((cube.cube[0] >> 27) << 8); + let chunk = chunks[cube.cube[2]]; - var positionX : f32 = f32(i32(cube.cube[0] & 15) + chunk.x * 16); //4 bytes - var positionY : f32 = f32((cube.cube[0] >> 4) & 1023); //10 bytes - var positionZ : f32 = f32(i32((cube.cube[0] >> 14) & 15) + chunk.z * 16); // 4 bytes - let modelIndex : u32 = ((cube.cube[0] >> 18) & 16383); ///14 bits - var textureIndex : u32; + let modelIndex : u32 = extractBits(cube.cube[0], 18, 14); ///14 bits - positionX += 0.5; - positionZ += 0.5; - positionY += 0.5; + var cube_position = vec3f(f32(i32(extractBits(cube.cube[0], 0, 4)) + chunk.x * 16), + f32(extractBits(cube.cube[0], 4, 10)), + f32(i32(extractBits(cube.cube[0], 14, 4)) + chunk.z * 16)); - let cube_position = vec4f(positionX, positionY, positionZ, 0.0); + cube_position += 0.5; var colorBlend = vec4f(unpack4xU8(cube.cube[1])); colorBlend.a = f32(chunk.opacity); colorBlend /= 255; - var normal : mat4x4; + + var textureIndex : u32; var Uv = vec2(uv.x, (1.0 - uv.y)); - normal = rotatations[normalIndex]; + let normal = rotatations[normalIndex]; + switch (normalIndex) { case 0: { @@ -97,7 +94,7 @@ fn main( Uv = vec2(Uv / tilesPerTexture + vec2f(trunc(f32(textureIndex) % tilesPerTexture.y), trunc(f32(textureIndex) / tilesPerTexture.x)) / tilesPerTexture); var output: VertexOutput; - output.Position = ViewProjectionMatrix * (position * normal + cube_position); + output.Position = ViewProjectionMatrix * (position * normal + vec4(cube_position, 0.0)); output.fragUV = Uv; output.ColorBlend = colorBlend; return output; diff --git a/prismarine-viewer/viewer/lib/worldrendererCommon.ts b/prismarine-viewer/viewer/lib/worldrendererCommon.ts index f9d402c15..9d42e1f67 100644 --- a/prismarine-viewer/viewer/lib/worldrendererCommon.ts +++ b/prismarine-viewer/viewer/lib/worldrendererCommon.ts @@ -201,15 +201,15 @@ export abstract class WorldRendererCommon } const chunkCoords = data.key.split(',').map(Number) - if (this.loadedChunks[`${chunkCoords[0]},${chunkCoords[2]}`]) { // ensure chunk data was added, not a neighbor chunk update - const loadingKeys = [...this.sectionsWaiting.keys()] - if (!loadingKeys.some(key => { - const [x, y, z] = key.split(',').map(Number) - return x === chunkCoords[0] && z === chunkCoords[2] - })) { - this.finishedChunks[`${chunkCoords[0]},${chunkCoords[2]}`] = true - } - } + // if (this.loadedChunks[`${chunkCoords[0]},${chunkCoords[2]}`]) { // ensure chunk data was added, not a neighbor chunk update + // const loadingKeys = [...this.sectionsWaiting.keys()] + // if (!loadingKeys.some(key => { + // const [x, y, z] = key.split(',').map(Number) + // return x === chunkCoords[0] && z === chunkCoords[2] + // })) { + // this.finishedChunks[`${chunkCoords[0]},${chunkCoords[2]}`] = true + // } + // } this.checkAllFinished() this.renderUpdateEmitter.emit('update')