Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sa2urami committed Dec 19, 2024
1 parent 43cdd21 commit afd4c4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
25 changes: 11 additions & 14 deletions prismarine-viewer/examples/Cube.vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct Chunk{
length: i32
}


struct CubePointer {
ptr: u32
}
Expand Down Expand Up @@ -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<f32>;

var textureIndex : u32;
var Uv = vec2(uv.x, (1.0 - uv.y));
normal = rotatations[normalIndex];
let normal = rotatations[normalIndex];

switch (normalIndex) {
case 0:
{
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions prismarine-viewer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
}

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')
Expand Down

0 comments on commit afd4c4c

Please sign in to comment.