0.0.9 • Published 6 years ago
display-sdf v0.0.9
display-sdf
Helper library for displaying SDFs, supports rendering "straight" from GPU, or meshing with surface-nets and displaying as a mesh.
Installation
npm install display-sdf --save
Basic Usage
const { displayRaw } = require("display-sdf");
// generate shaderCode
displayRaw(shaderCode);In combination with hiccup-sdf:
const { displayRaw } = require("display-sdf");
const { compileShader, glslHelpers } = require("hiccup-sdf");
const tree = ["box"]
const { inject, model } = compileShader(tree);
const shader = glslHelpers.createShaderFull(model, inject);
displayRaw(shader);Meshing
Sometimes working with "straight" GPU rendering is not ideal, so display-sdf provides an option to mesh the SDF using surface-nets, and display afterwards:
const { displayRaw } = require("display-sdf");
// generate shaderCode
displayMesh(shader, { size: 128 });API
All options are optional.
displayRaw(shaderCode, [options])
shaderCode- stringified SDF GLSL codeoptions.textures- custom data textures to pass to the shader, used byhiccup-sdfmapfunction to work over large amounts of data
displayMesh(shaderCode, [options])
shaderCode- stringified SDF GLSL codeoptions.size- size of the surface-nets field (uniform box, so128becomes[128, 128, 128])options.textures- custom data textures to pass to the shader, used byhiccup-sdfmapfunction to work over large amounts of dataoptions.refine- shouldrefine-meshbe executed after meshing, this usually makes the output look nicer (true/false)options.refineOptions- custom options to pass torefine-mesh
Acknowledgements
This project was developed in part at Laboratory, an artist residency for interactive arts: https://laboratoryspokane.com.