Created
October 2, 2023 20:02
-
-
Save LinqLover/ed9ef285651e1c00648e36899e926cc6 to your computer and use it in GitHub Desktop.
Debug THREE.js shaders in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//debugging shaders | |
const getBufferItems = buffer => Array.from({ length: buffer.count }, (_, i) => | |
Array.from({ length: buffer.itemSize }, (_, j) => | |
buffer.array[i * buffer.itemSize + j])) | |
// declare uniforms (INSERT HERE) | |
const { v1, v2, v3 } = Object.fromEntries(Object.entries(mesh.material.uniforms).map(([k, v]) => [k, v.value])) | |
// declare shader functions | |
const clamp = (x, min, max) => Math.min(Math.max(x, min), max) | |
const float = x => x | |
const step = (edge, x) => x < edge ? 0 : 1 | |
// run shader code | |
getBufferItems(mesh.geometry.attributes.position).map((position, gl_VertexID) => { | |
// shader code (INSERT HERE) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment