Notebook - Welcome to Notebook

Contact/Report Bugs
You can contact me at: bkenwright@xbdev.net












WebGPU Example Wireframe taking advantage of barycentric coordinates Wireframes come in as a handy tool for debugging Seeing all the triangles is valuable And the least disturbing the simplest to use method is the one we want The example here draws wireframes for triangles by taking advantage of the trick using barycentric coordinates For every triangle consisting of 6 vertices 3 points of two coordinates Three points of three coordinates respectively p 1 1 0 0 p 2 0 1 0 p 3 0 0 1 Each triangle vertex has a corresponding barycentric coordinate assigned v1 p1 v2 p2 v3 p3 The trick behind the barycentric approach is in the fragment shader Assuming you only know that the barycentric coordinates if any of the coordinates is lower than some constant e g 0 01 render it black as these are the edges let canvas document createElement canvas document body appendChild canvas canvas width 400 canvas height 400 console log canvas width console log canvas height const adapter await navigator gpu requestAdapter const device await adapter requestDevice const context canvas getContext webgpu const devicePixelRatio window devicePixelRatio 1 const presentationSize canvas clientWidth devicePixelRatio canvas clientHeight devicePixelRatio const presentationFormat context getPreferredFormat adapter context configure device format presentationFormat size presentationSize let vertWGSL block struct Uniforms mousex f32 mousey f32 var1 f32 var2 f32 binding 0 group 0 var uniform uniforms Uniforms struct VSOut builtin position Position vec4 f32 location 0 bar vec3 f32 stage vertex fn main builtin vertex index VertexIndex u32 VSOut index is passed to the vertex shader which looks up the triangle vertex data given below var pos array vec2 f32 3 vec2 f32 0 0 0 5 vec2 f32 0 5 0 5 vec2 f32 0 5 0 5 var bar array vec3 f32 3 vec3 f32 1 0 0 0 0 0 vec3 f32 0 0 1 0 0 0 vec3 f32 0 0 0 0 1 0 var vsOut VSOut vsOut Position vec4 f32 pos VertexIndex 0 0 1 0 vsOut bar bar VertexIndex return vsOut let fragWGSL block struct Uniforms mousex f32 mousey f32 var1 f32 0 1 0 var2 f32 binding 1 group 0 var uniform uniforms Uniforms stage fragment fn main location 0 vbc vec3 f32 location 0 vec4 f32 if uniforms var2 0 0 return vec4 f32 vbc 1 0 if uniforms var2 1 0 if vbc x uniforms var1 vbc y uniforms var1 vbc z uniforms var1 return vec4 f32 0 0 0 0 0 0 1 0 discard if vbc x uniforms var1 if sin vbc y 100 0 1 0 0 5 return vec4 f32 sin vbc y 100 0 0 0 0 0 1 0 if vbc y uniforms var1 if sin vbc z 100 0 0 5 return vec4 f32 0 0 sin vbc z 100 0 0 0 1 0 if vbc z uniforms var1 if sin vbc x 100 0 0 5 return vec4 f32 0 0 0 0 sin vbc x 100 0 1 0 discard return vec4 f32 0 5 0 5 0 5 1 0 const uniformData mousex 0 0 mousey 0 0 var1 0 1 var2 2 0 const vertexUniformBuffer device createBuffer size Object values uniformData length 4 usage GPUBufferUsage UNIFORM GPUBufferUsage COPY DST var uniformDataFloats new Float32Array Object values uniformData device queue writeBuffer vertexUniformBuffer 0 uniformDataFloats const sceneUniformBindGroupLayout device createBindGroupLayout entries binding 0 visibility GPUShaderStage VERTEX buffer type uniform binding 1 visibility GPUShaderStage FRAGMENT buffer type uniform const uniformBindGroup device createBindGroup layout sceneUniformBindGroupLayout entries binding 0 resource buffer vertexUniformBuffer binding 1 resource buffer vertexUniformBuffer const sampleCount 4 const pipeline device createRenderPipeline layout device createPipelineLayout bindGroupLayouts sceneUniformBindGroupLayout vertex module device createShaderModule code vertWGSL replace g entryPoint main fragment module device createShaderModule code fragWGSL replace g entryPoint main targets format presentationFormat primitive topology triangle list GPUPrimitiveTopology point list line list line strip triangle list triangle strip multisample count 4 const texture device createTexture size presentationSize sampleCount format presentationFormat usage GPUTextureUsage RENDER ATTACHMENT const view texture createView function frame uniformDataFloats new Float32Array Object values uniformData device queue writeBuffer vertexUniformBuffer 0 uniformDataFloats const commandEncoder device createCommandEncoder const renderPassDescriptor GPURenderPassDescriptor colorAttachments view resolveTarget context getCurrentTexture createView loadValue r 1 0 g 1 0 b 1 0 a 1 0 storeOp discard const passEncoder commandEncoder beginRenderPass renderPassDescriptor passEncoder setBindGroup 0 uniformBindGroup passEncoder setPipeline pipeline passEncoder draw 3 1 0 0 passEncoder endPass device queue submit commandEncoder finish requestAnimationFrame frame frame canvas onmousemove function event uniformData mousex event clientX canvas width uniformData mousey event clientY canvas height let var2 document createElement div document body appendChild var2 var2 style position absolute var2 style left 30px var2 style top 10px var2 style width 300px var2 innerHTML fieldset id var2 legend Select type legend label for radio1 None label input type radio value 0 name myval2 id radio1 checked checked label for radio2 Line label input type radio value 1 name myval2 id radio2 label for radio 3 Pattern label input type radio value 2 name myval2 id radio3 fieldset let var1 document createElement div document body appendChild var1 var1 id var1 var1 style position absolute var1 style left 35px var1 style top 75px var1 style width 200px var1 style border 1px solid blue let link document createElement link link href https code jquery com ui 1 10 4 themes ui lightness jquery ui css link rel stylesheet link async false document body appendChild link let script1 document createElement script script1 src https code jquery com jquery 1 10 2 js script1 type text javascript script1 async false document body appendChild script1 let script2 document createElement script script2 src https code jquery com ui 1 10 4 jquery ui js script2 type text javascript script2 async false document body appendChild script2 script2 onload function var1 slider values 0 1 min 0 005 max 1 0 step 0 01 values 75 300 slide function event ui ui handle text ui value uniformData var1 parseFloat ui value ui slider handle each function this text this parent slider values 0 var2 change function let selectedValue input name myval2 checked val uniformData var2 parseFloat selectedValue end onload console log done

const uniformBindGroup device createBindGroup layout sceneUniformBindGroupLayout entries binding 0 resource buffer vertexUniformBuffer binding 1 resource buffer vertexUniformBuffer const sampleCount 4 const pipeline device createRenderPipeline layout device createPipelineLayout bindGroupLayouts sceneUniformBindGroupLayout vertex module device createShaderModule code vertWGSL replace g entryPoint main fragment module device createShaderModule code fragWGSL replace g entryPoint main targets format presentationFormat primitive topology triangle list GPUPrimitiveTopology point list line list line strip triangle list triangle strip multisample count 4 const texture device createTexture size presentationSize sampleCount format presentationFormat usage GPUTextureUsage RENDER ATTACHMENT const view texture createView function frame uniformDataFloats new Float32Array Object values uniformData device queue writeBuffer vertexUniformBuffer 0 uniformDataFloats const commandEncoder device createCommandEncoder const renderPassDescriptor GPURenderPassDescriptor colorAttachments view resolveTarget context getCurrentTexture createView loadValue r 1 0 g 1 0 b 1 0 a 1 0 storeOp discard const passEncoder commandEncoder beginRenderPass renderPassDescriptor passEncoder setBindGroup 0 uniformBindGroup passEncoder setPipeline pipeline passEncoder draw 3 1 0 0 passEncoder endPass device queue submit commandEncoder finish requestAnimationFrame frame frame canvas onmousemove function event uniformData mousex event clientX canvas width uniformData mousey event clientY canvas height let var2 document createElement div document body appendChild var2 var2 style position absolute var2 style left 30px var2 style top 10px var2 style width 300px var2 innerHTML fieldset id var2 legend Select type legend label for radio1 None label input type radio value 0 name myval2 id radio1 checked checked label for radio2 Line label input type radio value 1 name myval2 id radio2 label for radio 3 Pattern label input type radio value 2 name myval2 id radio3 fieldset let var1 document createElement div document body appendChild var1 var1 id var1 var1 style position absolute var1 style left 35px var1 style top 75px var1 style width 200px var1 style border 1px solid blue let link document createElement link link href https code jquery com ui 1 10 4 themes ui lightness jquery ui css link rel stylesheet link async false document body appendChild link let script1 document createElement script script1 src https code jquery com jquery 1 10 2 js script1 type text javascript script1 async false document body appendChild script1 let script2 document createElement script script2 src https code jquery com ui 1 10 4 jquery ui js script2 type text javascript script2 async false document body appendChild script2 script2 onload function var1 slider values 0 1 min 0 005 max 1 0 step 0 01 values 75 300 slide function event ui ui handle text ui value uniformData var1 parseFloat ui value ui slider handle each function this text this parent slider values 0 var2 change function let selectedValue input name myval2 checked val uniformData var2 parseFloat selectedValue end onload console log done

3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
animbackgroundimage
aseformat
assert
asteroidsjs
backgrounds01
backgrounds02
backgrounds03
barnsleyfern
base26
base64
bib
binary
bodypix
bouncy
box2dweb
breakoutjs
browserversion
buslanes
busybutton
bvhreader
calendar
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
changingimages
chatgptusingopenai
chatgptusingopenai2
chatgptusingopenai3
checkboxtoggle
chinesetiles
classes
classfeatures
clipboardbutton
clonenode
codedropdown
codemirror
codemirror2
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csshas
csspulse
cssresizeaspect
cssspin
csszooming
csvtoarray
customcheckbox
d3datamap
d3js
d3js10
d3js11
d3js2
d3js3
d3js4
d3js5
d3js6
d3js7
d3js8
d3js9
d3jsanimatedgrid
d3jsarctransition
d3jsarctransition2
d3jsaxis
d3jsaxischanging
d3jsbars
d3jsbrushing
d3jsbuslanes
d3jsbuslanes2
d3jscalendar
d3jscheat
d3jsclock
d3jscloudmap
d3jscogs
d3jscolors
d3jscovid
d3jscovid2
d3jscovid3
d3jsdashboard
d3jsdashboard2
d3jsdashboard3
d3jsdatakeyfunction
d3jsdensity
d3jsdragresizing
d3jsdragresizing2
d3jseach
d3jsease
d3jsevents
d3jsflower
d3jsforcegroups
d3jsforces
d3jsforces2
d3jsfractaltree
d3jsgeo
d3jsgroupbars
d3jsgroups
d3jsheatmap
d3jshex
d3jshierarchies
d3jshierarchies2
d3jshistogram
d3jshistogram2
d3jshistogram3
d3jshistogram4
d3jsinterpolate
d3jsjoin
d3jskmean
d3jskmean2
d3jsline
d3jsline2
d3jsline3
d3jsline4
d3jslinetransition
d3jslinetransition0
d3jslinetransition2
d3jsmaplocations
d3jsmaps
d3jsmaps2
d3jsmaps3
d3jsmisc
d3jsmisc2
d3jsmodule
d3jsmodulecolor
d3jsmultistyles
d3jsnobel
d3jsoverlappinggraphs
d3jspanel
d3jspie
d3jspieinterpolate
d3jssankey
d3jssankey2
d3jsscatter
d3jsshapes
d3jsslider
d3jsspending
d3jsspending2
d3jsspiralplot
d3jsspirograph
d3jssquare
d3jsstack
d3jsstackedbar
d3jsstackedbar2
d3jssunburst
d3jssunmoon
d3jssvglines
d3jssymbols
d3jstimelines
d3jsuk
d3jsvoronoi
d3scatterplot
d3timeline
d3timeline2
datalist
datamuse
date
dblclickhighlight
deviceorientation
dictionaryapi
dockermenu
doodlepad
downloadgif
dragdroplistitems
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragrotateresizefontsize
dragselectbrush
drawlinesdiv
dropdown
dualquaternionimages
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
excalidraw
excalidraw2
excalidraw3
excalidraw5
expandable
faker
fetchplus
fileupload
fixedtopbar
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
misc
misc2
modules
myipdetails
neataptic
networkstructures
networkstructures2
number
obj
objtojson
openaiimages
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5jsanimatedcover
p5mengercube
p5snowflakes
palindrome
panel
parallax
paste
paste2
pasteimgfromurl
pdfjs
pdfjs2
pdfkit
pdfkit2
pdfkit3
pdfkit4
pdfkit5
pdfkit6
pdfmake
pdfmake2
pdfmake3
pdfmake4
pdfmake5
pdfmake6
perlin
perlin2
perlin3
perspective
pexels
playground
plotly
plotlynoise
plotlyranddist
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
python
quotes
racergame
random
randomprofilepatterns
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdfboxinboxtwist
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
svg
svgchaos
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
svgrandomfaces
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tabularjs
tabularjs2
tabulatordownload
tagcanvas
tensorflowgan
tensorflowjs
tensorflowjsbasic
tensorflowjscnn
tensorflowjssinewave
tensorflowjssound
tensorflowmobilenet
tetrahedronfractal
tetrahedronfractalfolding
tetris
textarea
textareaauto
textareadiv
textareadiv2
textmaskimage
theirorthere
thesaurus
threejs
threejs2
threejs3
threejs4
threejsgltf
threejstokyo
tiles
toaster
tooltip
transition
transitionexpandabledropdown
treeview
treeview2
tricks
tshirt
tshirt2
tshirt3
turningpages
unsplash
urlblob
urlblob2
userdefinepoints
vector
videos
videos2
visualsort
vue
w2ui
w2uientertextdialog
webcam
webgl
webgl2
webgl3
webgl4
webgl5
webglbasic1
webglbasic2
webglcube
webglfov
webglfrustum
webgljson
webglleaves
webgllighting
webglorthographic
webglpoints1
webglpoints2
webglpoints3
webglsquare
webgltexture1
webgltexture2
webgltexture3
webgltransforms
webgltriangle
webgpu
webgpu10
webgpu11
webgpu12
webgpu13
webgpu14
webgpu15
webgpu16
webgpu17
webgpu2
webgpu3
webgpu4
webgpu5
webgpu6
webgpu7
webgpu8
webgpu9
webgpubars
webgpubuffers
webgpubuffers2
webgpucellnoise
webgpuclouds
webgpuclydescope
webgpucompute
webgpucubemap
webgpucubemap2
webgpudeferred
webgpudepth
webgpudof
webgpudrops
webgpuetha
webgpufire
webgpufractalcubes
webgpuglassrain
webgpugltf
webgpugltf2
webgpugrass
webgpugrid
webgpukernel
webgpukleinian
webgpulabupdates
webgpulighting
webgpumandelbrot
webgpumeta3d
webgpumetaballs
webgpumouse
webgpunoise
webgpunormalmapping
webgpuobj
webgpuparallax
webgpuparallax2
webgpuparallax3
webgpuparallaxshadow
webgpuparallaxshadow2
webgpupixel
webgpuquad
webgpuray1
webgpuraytracing
webgpuraytracing2
webgpushadowmaps
webgpushadowmaps2
webgpusierpinski2d
webgpusierpinski3d
webgpusinusoid
webgpussao
webgpustadiumobj
webgpuswirl
webgputestpipe3
webgputoon
webgputopology
webgputt
webgpuvolcloud
webgpuwater
webgpuwireframe
webgpuwireframe2
webpcanvas
webworkers
webxr
webxr2
wiggly
wikipedia