Skip to content

Instantly share code, notes, and snippets.

@LinqLover
Created October 2, 2023 20:02
Show Gist options
  • Save LinqLover/ed9ef285651e1c00648e36899e926cc6 to your computer and use it in GitHub Desktop.
Save LinqLover/ed9ef285651e1c00648e36899e926cc6 to your computer and use it in GitHub Desktop.
Debug THREE.js shaders in JavaScript
//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