Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webgpu 2 #131

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
163290d
Stash
sa2urami Mar 1, 2024
1175d3f
Working texture bindings
sa2urami Mar 5, 2024
06b2f3b
degrees_to_radians
sa2urami Mar 6, 2024
b28f69c
nice work by ilya
zardoy Mar 18, 2024
6e84db0
make cubes
zardoy Mar 20, 2024
253fb8a
move code around, +export
zardoy Mar 21, 2024
dee63df
Merge branch 'next' into webgl
zardoy Mar 21, 2024
024891c
add
zardoy Mar 21, 2024
73a5e9d
up render
zardoy Mar 21, 2024
2ee0ef3
pus render
zardoy Mar 21, 2024
027f5c6
up package json
sa2urami Mar 21, 2024
a1db77a
Merge remote-tracking branch 'upstream/next' into webgl
sa2urami Mar 21, 2024
ad5a906
fix things
sa2urami Mar 21, 2024
70c9686
insane instace shading
zardoy Mar 21, 2024
a682d4b
Instanced mashing with indexed texturing
zardoy Mar 21, 2024
b403ed4
fix build
zardoy Mar 22, 2024
c6c4ca8
almost ok for the app
zardoy Mar 22, 2024
9e26f70
add touch
zardoy Mar 24, 2024
c8e6475
fix textures
zardoy Mar 24, 2024
4133eca
dynamic entrypoint
zardoy Mar 24, 2024
b35bc08
Merge remote-tracking branch 'origin/next' into webgl
zardoy Mar 25, 2024
51ba0ea
put renderer into worker! viewerWrapper & perf cypress test
zardoy Mar 25, 2024
a329006
restore singleplayer
zardoy Mar 25, 2024
ce19459
up world
zardoy Mar 25, 2024
00b9683
fix worker output!
zardoy Mar 25, 2024
d0a6941
build workers
zardoy Mar 25, 2024
f329559
build worker correctly
zardoy Mar 25, 2024
a19c9ad
fix cam
zardoy Mar 25, 2024
7d5f1c5
worker part 2
zardoy Mar 27, 2024
506706e
fixed camera, coords, cam, textures, controls
zardoy Mar 28, 2024
a7313b3
insane ilya work by working hard (harder than usual)
zardoy Mar 28, 2024
f168bdb
up tasks
zardoy Mar 29, 2024
61d0ff4
up playground impl
zardoy Mar 29, 2024
5b78000
a bit better performance on blocks update - new struct
zardoy Mar 29, 2024
6275d78
compute index in worker: less lags
zardoy Mar 31, 2024
dc625b5
implement correct cubes update via subdata (faster new chunks add)
zardoy Mar 31, 2024
7b61ff6
fix worker build on win
zardoy Apr 3, 2024
11c04fb
implement removal, small impr
zardoy Apr 3, 2024
61a8a97
Multi textures
sa2urami Apr 3, 2024
e9ae586
Super Performant Multi Textures
sa2urami Apr 3, 2024
a75aeb0
Addon to last commit
sa2urami Apr 3, 2024
86f1b5e
add animation, impl texture indexes, fix perf
zardoy Apr 4, 2024
5951e14
fix stone display
zardoy Apr 5, 2024
d0501d3
atlas now with animated blocks!
zardoy Apr 5, 2024
984a208
almost working texture switch in playground
zardoy Apr 5, 2024
349edd1
undo l
zardoy Apr 5, 2024
16fdd37
better render debug
zardoy Apr 5, 2024
97a9e92
impl basic debug animation
zardoy Apr 5, 2024
8b6e1d2
make worldrenderer extendable and customizable with your own render i…
zardoy Apr 6, 2024
12dfa9f
implement fully working animation in playground
zardoy Apr 6, 2024
4c58f45
copy webgl data!
zardoy Apr 6, 2024
9fe0e34
minor render tweaks
zardoy Apr 6, 2024
17cd4bf
fix critical texture index bug
zardoy Apr 6, 2024
183f8e4
Fix texture buffer data type and usage in webglRendererWorker.ts
sa2urami Apr 6, 2024
7777307
fix critical performance scene render
zardoy Apr 6, 2024
31b419c
add tint
zardoy Apr 6, 2024
9f89af6
Add biome color support to fragment shader
sa2urami Apr 6, 2024
db722db
fix vercel preview deploy
zardoy Mar 25, 2024
c4d65ee
fix warps display for greenfield & click action
zardoy Mar 25, 2024
889987d
three shake three.js (#94)
zardoy Mar 25, 2024
48d3bbe
feat: effects + system indicators in hud! (#95)
gguio Mar 26, 2024
029a717
fix page loadeding indicator showing sometimes
zardoy Mar 27, 2024
dc9f15e
naive transparent
zardoy Apr 9, 2024
5476b39
Merge branch 'next' into webgl
zardoy Apr 9, 2024
484844b
add playground scripts!
zardoy Apr 9, 2024
c5c8f27
allow to override
zardoy Apr 9, 2024
28d55f9
reload on worker change
zardoy Apr 9, 2024
0edf51a
better workarounds!
zardoy Apr 9, 2024
de227f0
Merge remote-tracking branch 'origin/next' into webgl
zardoy Apr 9, 2024
469ef49
[pick] allow to set 0 render distance for debug
zardoy Apr 9, 2024
ed74485
Quad instanced rendreing
sa2urami Apr 9, 2024
2bc8439
Merge branch 'webgl' of https://github.com/sa2urami/prismarine-web-cl…
sa2urami Apr 9, 2024
e3205ed
prev commit fixes, fix bg, add reset
zardoy Apr 9, 2024
ff5ca18
KAVOfasdfasdf
sa2urami Apr 9, 2024
f970397
Merge branch 'webgl' of https://github.com/sa2urami/prismarine-web-cl…
sa2urami Apr 9, 2024
a5f0af8
[deploy] fix singleplayer
zardoy Apr 9, 2024
50efd76
workaround and potential fix
zardoy Apr 10, 2024
33d563c
fix action
zardoy Apr 10, 2024
324f070
fix playground
zardoy Apr 10, 2024
0cebd53
Triangle Strip
sa2urami Apr 10, 2024
40cda86
Merge branch 'webgl' of https://github.com/sa2urami/prismarine-web-cl…
sa2urami Apr 10, 2024
890afee
[pick] creative gamemode for ?singleplayer=1
zardoy Apr 10, 2024
bb8a841
implement buffer extend
zardoy Apr 10, 2024
a313c5f
new stats!
zardoy Apr 10, 2024
a3c414e
commit stats
zardoy Apr 10, 2024
4f9efb4
[wip] fixture export / loading!
zardoy Apr 10, 2024
830424e
[to pick] customize gamemode from menu!
zardoy Apr 11, 2024
a12ab1c
clean fix for image.width is undefined!
zardoy Apr 11, 2024
662c823
[pick] fix alias set
zardoy Apr 11, 2024
e9ca5cf
fix playground and slow cam move in worker
zardoy Apr 12, 2024
4e1257c
fix cam fixtup
zardoy Apr 12, 2024
6c5fdbd
another fixup for cam pos
zardoy Apr 12, 2024
3c4996f
impl removal, fix cam
zardoy Apr 14, 2024
137666c
FIX waitForChunksToRender ! fix a lot of worker issues! implement all…
zardoy Apr 14, 2024
130daac
triangle
zardoy May 21, 2024
4abdead
working cube!
zardoy May 21, 2024
c831094
initial instance shading
zardoy May 21, 2024
fb6b965
use new insane workers api, cleanup webgpu constants
zardoy May 22, 2024
c33ab7a
fix crashes
zardoy May 22, 2024
208b026
instancing
zardoy May 24, 2024
bbe2a6b
blocks adding
zardoy May 24, 2024
560d5fb
up cube
zardoy May 24, 2024
6f0e238
reduce size
zardoy May 25, 2024
6d375d8
Refactor shader code for cube rendering
zardoy May 25, 2024
02a84b8
add textures
zardoy May 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
almost ok for the app
  • Loading branch information
zardoy committed Mar 22, 2024
commit c6c4ca841b795f49f27a803605ab70903b467fc7
4 changes: 2 additions & 2 deletions prismarine-viewer/examples/_FragmentShader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ uniform sampler2D texture2;
void main()
{
vec2 position = vec2(1, 1); // I assume gets tile at (1, 1) since the size of the tiles are 1/16
vec2 size = vec2(1.0/64.0f, 1.0/64.0f);
vec2 coord = size * vec2(int(TextureIndex)%64,int(TextureIndex)/64) + TexCoord * (1.0f/64.0f);
vec2 size = vec2(1.0/32.0f, 1.0/32.0f);
vec2 coord = size * vec2(int(TextureIndex)%64,int(TextureIndex)/64) + TexCoord * (1.0f/32.0f);

FragColor = mix(texture(texture1, coord), texture(texture2, coord), 1.0);
}
52 changes: 37 additions & 15 deletions prismarine-viewer/examples/webglRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ declare const viewer: Viewer

let renderLoop
export const makeRender = () => {
renderLoop()
renderLoop?.()
}

export const cubePositions = [] as [number, number, number, string | null][]
let cubePositions
let updateCubes
export const updateCubePositions = () => {
updateCubes()
}

export const cubePositionsRaw = [] as [number, number, number, string | null][]

export const initWeblRenderer = async (version) => {
export const initWebglRenderer = async (version) => {
const stats = new Stats()
const canvas = document.createElement('canvas')
const gl = canvas.getContext('webgl2')!
Expand Down Expand Up @@ -76,7 +82,7 @@ export const initWeblRenderer = async (version) => {

let NumberOfCube = 1_000_000

let cubePositions = new Float32Array(NumberOfCube * 3)
cubePositions = new Float32Array(NumberOfCube * 3)
let cubeTextureIndices = new Float32Array(NumberOfCube);


Expand All @@ -85,21 +91,40 @@ export const initWeblRenderer = async (version) => {
cubePositions[i] = Math.random() * 1000 - 500;
cubePositions[i + 1] = Math.random() * 1000 - 500;
cubePositions[i + 2] = Math.random() * 100 - 100;
cubeTextureIndices[i / 3] = Math.floor(Math.random() * 400 + 400);
// cubeTextureIndices[i / 3] = Math.floor(Math.random() * 400 + 400);
cubeTextureIndices[i / 3] = 0;
}
cubePositions[0] = 0;
cubePositions[1] = 0;
cubePositions[2] = 0;

let instanceVBO = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, instanceVBO);
gl.bufferData(gl.ARRAY_BUFFER, cubePositions, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);

let instanceTextureID = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, instanceTextureID);
gl.bufferData(gl.ARRAY_BUFFER, cubeTextureIndices, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
updateCubes = () => {
cubePositions = new Float32Array(cubePositionsRaw.length * 3)
cubeTextureIndices = new Float32Array(cubePositionsRaw.length);

cubePositionsRaw.forEach(([x, y, z, name], i) => {
cubePositions[i * 3] = x
cubePositions[i * 3 + 1] = y
cubePositions[i * 3 + 2] = z
// just set index to 0 for now
cubeTextureIndices[i] = 0
})


gl.bindBuffer(gl.ARRAY_BUFFER, instanceVBO);
gl.bufferData(gl.ARRAY_BUFFER, cubePositions, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);

gl.bindBuffer(gl.ARRAY_BUFFER, instanceTextureID);
gl.bufferData(gl.ARRAY_BUFFER, cubeTextureIndices, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
}

updateCubes()
globalThis.updateCubes = updateCubes


let VBO, VAO = gl.createVertexArray();
VBO = gl.createBuffer();
Expand Down Expand Up @@ -299,9 +324,6 @@ export const initWeblRenderer = async (version) => {
//gl.bindVertexArray(null)

//let i = 0
// CubePositions = [[
// 2, 90, 2
// ]]
// const cubePositions = Object.values(viewer.world.newChunks).map((chunk: any) => {
// return Object.entries(chunk.blocks).map(([pos, block]) => {
// return [...pos.split(',').map(Number), block] as [number, number, number, string]
Expand Down
4 changes: 2 additions & 2 deletions prismarine-viewer/viewer/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ export function getSectionGeometry (sx, sy, sz, world: World) {
}

for (const variant of block.variant) {
console.log(variant)
if (!variant || !variant.model) continue

if (block.name !== 'water' && block.name !== 'lava'/* && block.isCube */) {
Expand Down Expand Up @@ -455,7 +454,8 @@ export function getSectionGeometry (sx, sy, sz, world: World) {
}
}

attr.blocks[`${cursor.x},${cursor.y},${cursor.z}`] = block.name
const pos = block.position
attr.blocks[`${pos.x},${pos.y},${pos.z}`] = block.name
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions prismarine-viewer/viewer/lib/worldrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { toMajor } from './version.js'
import PrismarineChatLoader from 'prismarine-chat'
import { renderSign } from '../sign-renderer/'
import { chunkPos, sectionPos } from './simpleUtils'
import { addCubes, cubePositions } from '../../examples/webglRenderer'
import { cubePositionsRaw, updateCubePositions } from '../../examples/webglRenderer'

function mod (x, n) {
return ((x % n) + n) % n
Expand Down Expand Up @@ -90,10 +90,10 @@ export class WorldRenderer {
if (/* !this.loadedChunks[chunkCoords[0] + ',' + chunkCoords[2]] || */ !this.active) return

this.newChunks[data.key] = data.geometry
// cubePositions.push(...Object.entries(data.geometry.blocks).map(([pos, block]) => {
// return [...pos.split(',').map(Number), block] as [number, number, number, string]
// }))

cubePositionsRaw.push(...Object.entries(data.geometry.blocks).map(([pos, block]) => {
return [...pos.split(',').map(Number), block] as [number, number, number, string]
}))
updateCubePositions()

// if (!this.initialChunksLoad && this.enableChunksLoadDelay) {
// const newPromise = new Promise(resolve => {
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { handleMovementStickDelta, joystickPointer } from './react/TouchAreasCon
import { possiblyHandleStateVariable } from './googledrive'
import flyingSquidEvents from './flyingSquidEvents'
import { hideNotification, notificationProxy } from './react/NotificationProvider'
import { initWebglRenderer } from 'prismarine-viewer/examples/webglRenderer'

window.debug = debug
window.THREE = THREE
Expand Down Expand Up @@ -178,11 +179,18 @@ let previousWindowWidth = window.innerWidth
let previousWindowHeight = window.innerHeight
let max = 0
let rendered = 0
let windowFocused = true
window.addEventListener('focus', () => {
windowFocused = true
})
window.addEventListener('blur', () => {
windowFocused = false
})
const renderFrame = (time: DOMHighResTimeStamp) => {
if (window.stopLoop) return
for (const fn of beforeRenderFrame) fn()
window.requestAnimationFrame(renderFrame)
if (window.stopRender || renderer.xr.isPresenting) return
if (window.stopRender || renderer.xr.isPresenting || !windowFocused) return
if (renderInterval) {
delta += time - lastTime
lastTime = time
Expand Down Expand Up @@ -228,6 +236,7 @@ const resizeHandler = () => {
}
}

initWebglRenderer('1.14.4')
const hud = document.getElementById('hud')
const pauseMenu = document.getElementById('pause-screen')

Expand Down Expand Up @@ -440,6 +449,7 @@ async function connect (connectOptions: {
viewer.setVersion(version)
}

serverOptions.version = '1.14.4'
const downloadVersion = connectOptions.botVersion || (singleplayer ? serverOptions.version : undefined)
if (downloadVersion) {
await downloadMcData(downloadVersion)
Expand Down
Loading