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

Fresh new reworked renderer with insane performance #67

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 24 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// UPDATED: all configs below are misconfigured and will crash vscode, open dist/index.html and use live preview debug instead
// recommended as much faster
{
// to launch "C:\Program Files\Google\Chrome Beta\Application\chrome.exe" --remote-debugging-port=9222
// to launch "C:/Program Files/Google/Chrome Beta/Application/chrome.exe" --remote-debugging-port=9222
"type": "chrome",
"address": "localhost",
"name": "Attach Chrome",
Expand Down Expand Up @@ -43,9 +43,31 @@
// "<node_internals>/**/*vendors*"
"<node_internals>/**/*mc-data*"
],
"runtimeExecutable": "C:/Users/Raphael/AppData/Local/Yandex/YandexBrowser/Application/browser.exe"
},
{
// to launch "C:\Program Files\Mozilla Firefox\firefox.exe" -start-debugger-server
// not recommended as in most cases it will slower as it launches from extension host so it slows down extension host, not sure why
"type": "chrome",
"name": "Launch Chrome2",
"request": "launch",
"url": "http://localhost:9090",
"pathMapping": {
"/": "${workspaceFolder}/prismarine-viewer/public"
},
"outFiles": [
"${workspaceFolder}/prismarine-viewer/public/**/*.js",
// "!${workspaceFolder}/prismarine-viewer/public/**/*vendors*",
"!${workspaceFolder}/prismarine-viewer/public/**/*mc-data*",
"!**/node_modules/**"
],
"skipFiles": [
// "<node_internals>/**/*vendors*"
"<node_internals>/**/*mc-data*"
],
"runtimeExecutable": "C:/Users/Raphael/AppData/Local/Yandex/YandexBrowser/Application/browser.exe"
},
{
// to launch "C:/Program Files/Mozilla Firefox/firefox.exe" -start-debugger-server
"type": "firefox",
"name": "Attach Firefox",
"request": "attach",
Expand Down
2 changes: 2 additions & 0 deletions prismarine-viewer/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const buildOptions = {
metafile: true,
loader: {
'.png': 'dataurl',
'.vert': 'text',
'.frag': 'text'
},
plugins: [
{
Expand Down
7 changes: 7 additions & 0 deletions prismarine-viewer/examples/_FragmentShader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
varying vec2 vUv;

void main() {

gl_FragColor = vec4(0.5f,5.0f,0.0f,1.0f);

}
11 changes: 11 additions & 0 deletions prismarine-viewer/examples/_VertexShader.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
layout (location = 0) in vec3 aPos;

varying vec2 vUv;

void main() {

vUv = uv;

gl_Position = vec4( aPos, 1.0 );

}
23 changes: 23 additions & 0 deletions prismarine-viewer/examples/playground.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vite/client" />
import _ from 'lodash'
import { WorldDataEmitter, Viewer, MapControls } from '../viewer'
import { Vec3 } from 'vec3'
Expand All @@ -12,6 +13,11 @@ import { loadScript } from '../viewer/lib/utils'
import JSZip from 'jszip'
import { TWEEN_DURATION } from '../viewer/lib/entities'
import Entity from '../viewer/lib/entity/Entity'
//import FragShader from './shader.frag?raw'
//@ts-ignore
import VertShader from './_VertexShader.vert'
//@ts-ignore
import FragShader from './_FragmentShader.frag'

globalThis.THREE = THREE
//@ts-ignore
Expand Down Expand Up @@ -132,8 +138,24 @@ async function main () {
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)

const geometry = new THREE.PlaneGeometry( 2, 2 ); // RenderPlane on all Screen for shaderspace
let uniforms = {};
const material = new THREE.ShaderMaterial( {

uniforms: uniforms,
vertexShader: VertShader,
fragmentShader: FragShader
} );
const pos = new Float32Array([1,1,0,0,2,2])
geometry.setAttribute('position', new THREE.BufferAttribute(pos,3))

const mesh = new THREE.Mesh( geometry, material );

// Create viewer
const viewer = new Viewer(renderer, 1)
viewer.scene.add(mesh);
viewer.render()
return
viewer.entities.setDebugMode('basic')
viewer.setVersion(version)
viewer.entities.onSkinUpdate = () => {
Expand Down Expand Up @@ -329,6 +351,7 @@ async function main () {
setTimeout(() => {
viewer.update()
viewer.render()
console.log(VertShader)
}, TWEEN_DURATION)
}

Expand Down
16 changes: 9 additions & 7 deletions prismarine-viewer/viewer/lib/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ export class Viewer {
}

render () {
if (this.composer) {
this.renderPass.camera = this.camera
this.composer.render()
} else {
this.renderer.render(this.scene, this.camera)
}
this.entities.render()
// if (this.composer) {
// //this.renderPass.camera = this.camera
// //this.composer.render()
// } else {
// // this.renderer.render(this.scene, this.camera)
// }
// // this.entities.render()
let camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.renderer.render(this.scene, camera);
}

async waitForChunksToRender () {
Expand Down
Loading