Changes to vertex shader

This commit is contained in:
Lucas Dower 2021-07-07 14:40:42 +01:00
parent 24aaa00c7c
commit 0d79afbcd3
5 changed files with 49 additions and 20 deletions

View File

@ -11,13 +11,13 @@
</head>
<body id="bootstrap-overrides">
<div class="container bg-dark">
<div class="row mb-2 mt-2">
<!-- LEFT -->
<div class="col">
<div class="input-group">
<input type="file" class="form-control" id="objFile" aria-describedby="inputGroupFileAddon04" aria-label="Upload">
<input type="file" accept=".obj" class="form-control" id="objFile" aria-describedby="inputGroupFileAddon04" aria-label="Upload">
<button id="objBtn" class="btn btn-primary" type="button" id="inputGroupFileAddon04">Load</button>
</div>
</div>
@ -39,12 +39,18 @@
</div>
</div>
</div>
<!-- CANVAS -->
<canvas id="c"></canvas>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="module" src="./src/client.js"></script>
<script>
$(document).ready(function() {
$(".toast").toast('show');
});
</script>
</html>

View File

@ -21,16 +21,16 @@
"devDependencies": {
"electron": "^13.1.4",
"electron-packager": "^15.2.0",
"expand-vertex-data": "^1.1.2",
"load-wavefront-obj": "^0.8.0",
"prismarine-nbt": "^1.6.0",
"twgl.js": "^4.19.1",
"wavefront-obj-parser": "^2.0.1"
"wavefront-obj-parser": "^2.0.1",
"expand-vertex-data": "^1.1.2",
"prismarine-nbt": "^1.6.0"
},
"dependencies": {
"twgl.js": "^4.19.1",
"load-wavefront-obj": "^0.8.0",
"wavefront-obj-parser": "^2.0.1",
"expand-vertex-data": "^1.1.2"
"expand-vertex-data": "^1.1.2",
"prismarine-nbt": "^1.6.0"
}
}

View File

@ -16,7 +16,20 @@ void main() {
float lighting = abs(dot(v_normal, v_lightDir));
//v_colour = vec4(abs(normal) * lighting, 1.0);
v_colour = vec4(vec3(lighting), 1.0);
//v_colour = vec4(vec3(lighting), 1.0);
/*
vec3 normal_ = vec3(0.0, 0.0, 0.0);
normal_.x = (normal.x + 1.0) / 2.0;
normal_.y = (normal.y + 1.0) / 2.0;
normal_.z = (normal.z + 1.0) / 2.0;
*/
lighting = (clamp(lighting, 0.0, 1.0) * 0.66) + 0.33;
vec3 normal_ = (normal + 1.0) / 2.0;
v_colour = vec4(normal_ * lighting, 1.0);
//v_colour = vec4(normal_, 1.0);
gl_Position = a_position;
}

View File

@ -12,7 +12,7 @@ const voxelManager = new VoxelManager(voxelSize);
const canvas = document.querySelector("#c");
const showMeshing = false;
const showMeshing = true;
const showFailedAABBs = false;
let loadedMesh = null;
@ -24,8 +24,18 @@ document.querySelector("#objBtn").addEventListener('click', () => {
if (files.length != 1) {
return;
}
loadedMesh = new Mesh(files[0].path);
const file = files[0];
if (!file.name.endsWith(".obj")) {
console.error("Could not load");
return;
}
try {
loadedMesh = new Mesh(files[0].path);
} catch (err) {
console.error("Could not load");
}
renderer.clear();
renderer.registerMesh(loadedMesh);
@ -57,14 +67,14 @@ document.querySelector("#voxelBtn").addEventListener('click', () => {
}
if (showMeshing) {
renderer.setStroke(new Vector3(1.0, 0.0, 0.0));
renderer.setStroke(new Vector3(0.0, 0.0, 0.0));
for (const box of mesh) {
renderer.registerBox(box.centre, box.size, true);
}
}
if (showFailedAABBs) {
renderer.setStroke(new Vector3(0.0, 0.0, 1.0));
renderer.setStroke(new Vector3(0.0, 0.0, 0.0));
for (const box of voxelManager.failedAABBs) {
renderer.registerBox(box.centre, box.size, true);
}

View File

@ -79,7 +79,7 @@ class Renderer {
this._gl.blendFuncSeparate(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE_MINUS_SRC_ALPHA);
this._gl.enable(this._gl.DEPTH_TEST);
//this._gl.enable(this._gl.CULL_FACE);
this._gl.enable(this._gl.CULL_FACE);
//this._gl.enable(this._gl.BLEND);
this._gl.clearColor(this._backgroundColour.x, this._backgroundColour.y, this._backgroundColour.z, 1);
this._gl.clear(this._gl.COLOR_BUFFER_BIT | this._gl.DEPTH_BUFFER_BIT);
@ -153,8 +153,8 @@ class Renderer {
_drawRegisters() {
const uniforms = {
//u_lightWorldPos: this._camera.getCameraPosition(0.5, 0.0),
u_lightWorldPos: new Vector3(4, 2, 1).normalise().toArray(),
u_lightWorldPos: this._camera.getCameraPosition(0.0, 0.0),
//u_lightWorldPos: new Vector3(4, 2, 1).normalise().toArray(),
u_worldViewProjection: this._camera.getWorldViewProjection(),
u_worldInverseTranspose: this._camera.getWorldInverseTranspose()
};