Notebook - Welcome to Notebook

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












WebGPU Example Parallax Parallax Steep Hard Shadows use strict document body style height 600px const cubev p 1 0 1 0 1 0 u 0 0 1 0 c 1 0 0 0 0 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 1 0 1 0 c 1 0 0 0 0 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 0 0 0 0 c 1 0 0 0 0 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 1 0 0 0 c 1 0 0 0 0 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 1 0 0 0 c 0 0 1 0 0 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 0 0 0 0 c 0 0 1 0 0 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 1 0 1 0 c 0 0 1 0 0 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 0 0 1 0 c 0 0 1 0 0 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 1 0 0 0 c 0 0 0 0 1 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 0 0 0 0 c 0 0 0 0 1 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 1 0 1 0 c 0 0 0 0 1 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 0 0 1 0 c 0 0 0 0 1 0 n 0 0 0 0 1 0 p 1 0 1 0 1 0 u 1 0 0 0 c 1 0 0 0 1 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 0 0 0 0 c 1 0 0 0 1 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 1 0 1 0 c 1 0 0 0 1 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 0 0 1 0 c 1 0 0 0 1 0 n 1 0 0 0 0 0 p 1 0 1 0 1 0 u 0 0 1 0 c 1 0 1 0 0 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 1 0 1 0 c 1 0 1 0 0 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 0 0 0 0 c 1 0 1 0 0 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 1 0 0 0 c 1 0 1 0 0 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 0 0 1 0 c 1 0 1 0 1 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 1 0 1 0 c 1 0 1 0 1 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 0 0 0 0 c 1 0 1 0 1 0 n 0 0 1 0 0 0 p 1 0 1 0 1 0 u 1 0 0 0 c 1 0 1 0 1 0 n 0 0 1 0 0 0 const cubef 0 1 3 0 3 2 Face front 4 5 7 4 7 6 Face right 8 9 11 8 11 10 12 13 15 12 15 14 16 17 19 16 19 18 20 21 23 20 23 22 calculate tangent vector for uv coordinates calculate bi tangent using normal for let i 0 i cubef length i 3 let v0 cubev cubef i 0 let v1 cubev cubef i 1 let v2 cubev cubef i 2 let edge0 v1 p 0 v0 p 0 v1 p 1 v0 p 1 v1 p 2 v0 p 2 let edge1 v2 p 0 v0 p 0 v2 p 1 v0 p 1 v2 p 2 v0 p 2 let duv0 v1 u 0 v0 u 0 v1 u 1 v0 u 1 v1 u 2 v0 u 2 let duv1 v2 u 0 v0 u 0 v2 u 1 v0 u 1 v2 u 2 v0 u 2 var f 1 0 duv0 0 duv1 1 duv1 0 duv0 1 let tangentx f duv1 1 edge0 0 duv0 1 edge1 0 let tangenty f duv1 1 edge0 1 duv0 1 edge1 1 let tangentz f duv1 1 edge0 2 duv0 1 edge1 2 cubev cubef i 0 t tangentx tangenty tangentz cubev cubef i 1 t tangentx tangenty tangentz cubev cubef i 2 t tangentx tangenty tangentz console log vertices cubev length console log faces cubef length get some bounds for the model doesn t go off screen let min x 10000 y 10000 z 10000 let max x 10000 y 10000 z 10000 for let i 0 i cubev length i min x Math min min x cubev i p 0 min y Math min min y cubev i p 1 min z Math min min z cubev i p 2 max x Math max max x cubev i p 0 max y Math max max y cubev i p 1 max z Math max max z cubev i p 0 let delta x max x min x y max y min y z max z min z let middle x min x delta x 0 5 y min y delta y 0 5 z min z delta z 0 5 let dist Math sqrt delta x delta x delta y delta y delta z delta z console log model size dist console log min min x min y min z console log max max x max y max z console log middle middle x middle y middle z done this way instead of setting src to wait until loaded await let response await fetch https cdnjs cloudflare com ajax libs gl matrix 2 6 0 gl matrix min js var script document createElement script script type text javascript script async false script innerHTML await response text document head appendChild script let canvas document createElement canvas document body appendChild canvas canvas width 600 canvas height 600 const adapter await navigator gpu requestAdapter const device await adapter requestDevice const context canvas getContext webgpu const presentationSize canvas width window devicePixelRatio canvas height window devicePixelRatio const presentationFormat context getPreferredFormat adapter let translateMat mat4 create let rotateXMat mat4 create let rotateYMat mat4 create let rotateZMat mat4 create let scaleMat mat4 create const rotation 0 0 0 const modelMatrix mat4 create const viewMatrix mat4 create const projectionMatrix mat4 create const parallaxValue new Float32Array 1 1 const const1Value new Float32Array 0 16 const const2Value new Float32Array 10 0 const parallaxType new Float32Array 1 0 const uniformBuffer device createBuffer size 64 3 64 192 3 x mat4x4 3x64 192 usage GPUBufferUsage UNIFORM GPUBufferUsage COPY_DST mat4 perspective projectionMatrix Math PI 2 canvas width canvas height 0 001 500 0 mat4 lookAt viewMatrix 0 0 0 8 dist 0 0 0 0 1 0 device queue writeBuffer uniformBuffer 0 modelMatrix device queue writeBuffer uniformBuffer 64 viewMatrix device queue writeBuffer uniformBuffer 128 projectionMatrix device queue writeBuffer uniformBuffer 192 parallaxValue device queue writeBuffer uniformBuffer 196 const1Value device queue writeBuffer uniformBuffer 200 const2Value device queue writeBuffer uniformBuffer 204 parallaxType async function setupTexture fileName const img document createElement img img src fileName https notebook xbdev net var images test512 png await img decode const basicTexture device createTexture size img width img height 1 format rgba8unorm presentationFormat bgra8unorm rgba8unorm usage 0x2 0x4 GPUTextureUsage COPY_DST GPUTextureUsage TEXTURE_BINDING console log presentationFormat presentationFormat bgra8unorm const imageCanvas document createElement canvas imageCanvas width img width imageCanvas height img height const imageCanvasContext imageCanvas getContext 2d imageCanvasContext drawImage img 0 0 imageCanvas width imageCanvas height const imageData imageCanvasContext getImageData 0 0 imageCanvas width imageCanvas height let textureData new Uint8Array img width img height 4 for let x 0 x img width img height 4 x textureData x imageData data x await device queue writeTexture texture basicTexture textureData offset 0 bytesPerRow img width 4 rowsPerImage img height img width img height 1 return basicTexture end setupTexture let textureSampler device createSampler minFilter linear magFilter linear var texturesExamples https notebook xbdev net var images wall1 png https notebook xbdev net var images wall1Height png https notebook xbdev net var images wall1Height png https notebook xbdev net var images toybox png https notebook xbdev net var images toyboxHeight png https notebook xbdev net var images toyboxNormal png https notebook xbdev net var images bricks png https notebook xbdev net var images bricksHeight png https notebook xbdev net var images bricksNormal png https notebook xbdev net var images Cobbles png https notebook xbdev net var images CobblesHeight png https notebook xbdev net var images CobblesNormal png let textures for let i 0 i texturesExamples length i let texture0 await setupTexture texturesExamples i 0 let colorTexture texture0 0 let texture1 await setupTexture texturesExamples i 1 let heightTexture texture1 0 let texture2 await setupTexture texturesExamples i 2 let normalTexture texture2 0 textures push c colorTexture h heightTexture n normalTexture Create a texture programatically draw on it using canvas functions const basicTexture device createTexture size 512 512 1 format rgba8unorm presentationFormat bgra8unorm rgba8unorm usage 0x2 0x4 GPUTextureUsage COPY_DST GPUTextureUsage TEXTURE_BINDING const imageCanvas document createElement canvas imageCanvas width 512 imageCanvas height 512 var ctx imageCanvas getContext 2d ctx fillStyle ffffff ctx fillRect 0 0 512 512 ctx fillStyle 000000 ctx font 130px Arial ctx fillText Hello World 10 200 const imageCanvasContext imageCanvas getContext 2d const imageData imageCanvasContext getImageData 0 0 imageCanvas width imageCanvas height let textureData new Uint8Array imageCanvas width imageCanvas height 4 for let x 0 x imageCanvas width imageCanvas height 4 x textureData x imageData data x await device queue writeTexture texture basicTexture textureData offset 0 bytesPerRow imageCanvas width 4 rowsPerImage imageCanvas height imageCanvas width imageCanvas height 1 textures push c basicTexture h basicTexture n basicTexture const sceneUniformBindGroupLayout device createBindGroupLayout entries binding 0 visibility GPUShaderStage VERTEX buffer type uniform binding 1 visibility GPUShaderStage FRAGMENT buffer type uniform binding 2 visibility GPUShaderStage FRAGMENT sampler type filtering binding 3 visibility GPUShaderStage FRAGMENT texture sampleType float viewDimension 2d binding 4 visibility GPUShaderStage FRAGMENT texture sampleType float viewDimension 2d binding 5 visibility GPUShaderStage FRAGMENT texture sampleType float viewDimension 2d var bgDescriptor GPUBindGroupDescriptor layout sceneUniformBindGroupLayout entries binding 0 resource buffer uniformBuffer binding 1 resource buffer uniformBuffer binding 2 resource textureSampler binding 3 resource textures 1 c createView binding 4 resource textures 1 h createView binding 5 resource textures 1 n createView var sceneUniformBindGroup device createBindGroup bgDescriptor context configure device device format presentationFormat size presentationSize const vertWGSL block struct Uniforms matrixModel mat4x4 f32 matrixView mat4x4 f32 matrixProjection mat4x4 f32 parallaxValue f32 const1 f32 const2 f32 parallaxType f32 binding 0 group 0 var uniform uniforms Uniforms struct VSOut builtin position Position vec4 f32 location 0 verPos vec3 f32 location 1 tcoord vec2 f32 location 2 normal vec3 f32 location 3 tangent vec3 f32 location 4 color vec3 f32 location 5 eyePos vec3 f32 stage vertex fn main location 0 inPos vec3 f32 location 1 tcoord vec2 f32 location 2 normal vec3 f32 location 3 tangent vec3 f32 location 4 color vec3 f32 VSOut var MVP uniforms matrixProjection uniforms matrixView uniforms matrixModel var MV uniforms matrixView uniforms matrixModel var vsOut VSOut vsOut Position MVP vec4 f32 inPos 1 0 vsOut verPos MV vec4 f32 inPos 1 0 xyz vsOut normal MV vec4 f32 normal 0 0 xyz vsOut tangent MV vec4 f32 tangent 0 0 xyz vsOut tcoord tcoord vsOut color color vsOut eyePos vec3 f32 uniforms matrixView 3 1 uniforms matrixView 3 2 uniforms matrixView 3 3 return vsOut const fragWGSL block struct Uniforms matrixModel mat4x4 f32 matrixView mat4x4 f32 matrixProjection mat4x4 f32 parallaxValue f32 const1 f32 const2 f32 parallaxType f32 binding 1 group 0 var uniform uniforms Uniforms group 0 binding 2 var mySampler sampler group 0 binding 3 var myTexture0 texture_2d f32 group 0 binding 4 var myTexture1 texture_2d f32 group 0 binding 5 var myTexture2 texture_2d f32 fn ParallaxMapping texCoords vec2 f32 viewDir vec3 f32 vec2 f32 let height textureSample myTexture1 mySampler texCoords x uniforms const1 let p viewDir xy viewDir z height uniforms parallaxValue return texCoords p fn ParallaxHardShadow texCoords vec2 f32 viewDir vec3 f32 height f32 f32 var shadowMultiplier 1 0 if dot vec3 f32 0 0 0 0 1 0 viewDir 0 0 return shadowMultiplier let numSteps clamp uniforms const2 5 0 40 0 5 30 let dir viewDir xy uniforms parallaxValue uniforms const1 1 0 numSteps 4 0 var curTexCoords texCoords var stepDepth textureSample myTexture1 mySampler curTexCoords x for var i 0 0 i numSteps i i 1 0 stepDepth stepDepth i numSteps 1 0 0 0 let curDepth textureSample myTexture1 mySampler curTexCoords x if stepDepth 0 0 return 1 0 if curDepth stepDepth return 0 5 curTexCoords curTexCoords dir return shadowMultiplier fn ParallaxMappingSteep texCoords vec2 f32 viewDir vec3 f32 vec2 f32 let numSteps clamp uniforms const2 5 0 40 0 5 30 var dir viewDir xy uniforms parallaxValue uniforms const1 1 0 numSteps var currTexCoords texCoords var currDepth textureSample myTexture1 mySampler currTexCoords x for var i 0 0 i numSteps i i 1 0 let stepDepth i numSteps 0 0 1 0 let texDepth textureSample myTexture1 mySampler currTexCoords x if texDepth stepDepth break currTexCoords currTexCoords dir return currTexCoords stage fragment fn main location 0 verPos vec3 f32 location 1 tcoord vec2 f32 location 2 normal vec3 f32 location 3 tangent vec3 f32 location 4 color vec3 f32 location 5 eyePos vec3 f32 location 0 vec4 f32 let parallaxValue uniforms parallaxValue 0 5 let const1 uniforms const1 0 02 let const2 uniforms const2 let parallaxType uniforms parallaxType var bt cross normalize normal normalize tangent let tbn mat3x3 f32 normalize tangent normalize bt normalize normal var eyePos2 vec3 f32 0 0 0 0 0 8 3 464101 var EyeT tbn normalize eyePos2 verPos var texCoords tcoord texCoords ParallaxMappingSteep tcoord EyeT let lightPos vec3 f32 8 0 3 0 5 0 let lightDir tbn normalize lightPos verPos var tnormal textureSample myTexture2 mySampler texCoords xyz tnormal normalize tnormal 2 0 1 0 let lightDir2 normalize vec3 f32 0 0 1 0 1 0 let light clamp dot lightDir2 tnormal 0 5 1 0 var shadow 1 0 if parallaxType 1 0 shadow ParallaxHardShadow texCoords lightDir 1 0 var fragColor textureSample myTexture0 mySampler texCoords light shadow fragColor a 1 0 return fragColor var positionBuffer null var colorBuffer null var tcoordsBuffer null var normalBuffer null var tangentBuffer null var indexBuffer null console log creating buffers let arrays v u n f t c for let i 0 i cubev length i arrays v push cubev i p 0 arrays v push cubev i p 1 arrays v push cubev i p 2 arrays c push cubev i c 0 arrays c push cubev i c 1 arrays c push cubev i c 2 arrays u push cubev i u 0 arrays u push cubev i u 1 arrays n push cubev i n 0 arrays n push cubev i n 1 arrays n push cubev i n 2 arrays t push cubev i t 0 arrays t push cubev i t 1 arrays t push cubev i t 2 for let i 0 i cubef length i arrays f push cubef i let positions new Float32Array arrays v let colors new Float32Array arrays c let tcoords new Float32Array arrays u let normals new Float32Array arrays n let tangents new Float32Array arrays t let indices new Uint32Array arrays f positionBuffer device createBuffer size positions byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST colorBuffer device createBuffer size colors byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST tcoordBuffer device createBuffer size tcoords byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST normalBuffer device createBuffer size normals byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST tangentBuffer device createBuffer size tangents byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST indexBuffer device createBuffer size indices byteLength 3 3 usage GPUBufferUsage INDEX GPUBufferUsage COPY_DST device queue writeBuffer positionBuffer 0 positions device queue writeBuffer colorBuffer 0 colors device queue writeBuffer tcoordBuffer 0 tcoords device queue writeBuffer normalBuffer 0 normals device queue writeBuffer tangentBuffer 0 tangents device queue writeBuffer indexBuffer 0 indices const pipeline device createRenderPipeline layout device createPipelineLayout bindGroupLayouts sceneUniformBindGroupLayout vertex module device createShaderModule code vertWGSL entryPoint main buffers arrayStride 12 attributes shaderLocation 0 format float32x3 offset 0 arrayStride 8 attributes shaderLocation 1 format float32x2 offset 0 arrayStride 12 attributes shaderLocation 2 format float32x3 offset 0 arrayStride 12 attributes shaderLocation 3 format float32x3 offset 0 arrayStride 12 attributes shaderLocation 4 format float32x3 offset 0 fragment module device createShaderModule code fragWGSL entryPoint main targets format presentationFormat primitive topology triangle list frontFace ccw cullMode back depthStencil format depth24plus depthWriteEnabled true depthCompare less const depthTexture device createTexture size canvas width canvas height 1 format depth24plus usage GPUTextureUsage RENDER_ATTACHMENT const renderPassDescription colorAttachments view context getCurrentTexture createView loadValue 0 0 0 8 0 8 1 clear screen storeOp store depthStencilAttachment view depthTexture createView depthLoadValue 1 depthStoreOp store stencilLoadValue 0 stencilStoreOp store rotation 0 0 7 function frame rotation 1 0 001 rotation 0 0 0023 let translate middle x middle y middle z mat4 fromTranslation translateMat translate mat4 fromXRotation rotateXMat rotation 0 mat4 fromYRotation rotateYMat rotation 1 mat4 fromZRotation rotateZMat rotation 2 mat4 multiply modelMatrix rotateYMat rotateZMat mat4 multiply modelMatrix modelMatrix rotateXMat mat4 multiply modelMatrix modelMatrix translateMat device queue writeBuffer uniformBuffer 0 modelMatrix device queue writeBuffer uniformBuffer 192 parallaxValue device queue writeBuffer uniformBuffer 196 const1Value device queue writeBuffer uniformBuffer 200 const2Value device queue writeBuffer uniformBuffer 204 parallaxType renderPassDescription colorAttachments 0 view context getCurrentTexture createView const commandEncoder device createCommandEncoder const renderPass commandEncoder beginRenderPass renderPassDescription renderPass setPipeline pipeline renderPass setVertexBuffer 0 positionBuffer renderPass setVertexBuffer 1 tcoordBuffer renderPass setVertexBuffer 2 normalBuffer renderPass setVertexBuffer 3 tangentBuffer renderPass setVertexBuffer 4 colorBuffer renderPass setIndexBuffer indexBuffer uint32 renderPass setBindGroup 0 sceneUniformBindGroup renderPass drawIndexed cubef length 1 renderPass endPass device queue submit commandEncoder finish requestAnimationFrame frame frame let rstart x rotation 0 y rotation 1 z rotation 2 let mstart x 0 y 0 let dragging false document onmousedown function e if e button 2 return dragging true mstart x e pageX mstart y e pageY rstart x rotation 0 y rotation 1 z rotation 2 document onmouseup function e dragging false document onmousemove function e if dragging return let s 0 01 rotation 0 rstart x mstart y e pageY s rotation 1 rstart y mstart x e pageX s 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 Rocks label input type radio value 0 name myval2 id radio1 label for radio2 Toy label input type radio value 1 name myval2 id radio2 checked checked label for radio3 Brick label input type radio value 2 name myval2 id radio3 label for radio4 Cobbles label input type radio value 3 name myval2 id radio4 label for radio5 Text label input type radio value 4 name myval2 id radio5 fieldset let var3 document createElement div document body appendChild var3 var3 style position absolute var3 style left 30px var3 style bottom 10px var3 style width 300px var3 innerHTML fieldset id var3 legend Select type legend label for radio1 Basic label input type radio value 0 name myval3 id radio1 label for radio2 Shadow label input type radio value 1 name myval3 id radio2 checked checked fieldset let var1 document createElement div document body appendChild var1 var1 id var1 var1 style position absolute var1 style left 35px var1 style top 90px var1 style width 200px let const1 document createElement div document body appendChild const1 const1 id const1 const1 style position absolute const1 style left 35px const1 style top 110px const1 style width 200px let const2 document createElement div document body appendChild const2 const2 id const2 const2 style position absolute const2 style left 35px const2 style top 135px const2 style width 200px 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 document body oncontextmenu function return false script2 onload function var1 slider values parallaxValue 0 min 0 0 max 2 0 step 0 01 slide function event ui ui handle text ui value parallaxValue 0 parseFloat ui value const1 slider values const1Value 0 min 0 5 max 0 5 step 0 01 slide function event ui ui handle text ui value const1Value 0 parseFloat ui value const2 slider values const2Value 0 min 5 0 max 40 0 step 1 0 slide function event ui ui handle text ui value const2Value 0 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 let indx parseFloat selectedValue bgDescriptor entries 3 resource textures indx c createView bgDescriptor entries 4 resource textures indx h createView bgDescriptor entries 5 resource textures indx n createView sceneUniformBindGroup device createBindGroup bgDescriptor var3 change function let selectedValue input name myval3 checked val let indx parseFloat selectedValue parallaxType 0 indx end onload console log ready console log right click and drag to rotate shape

Sampler sampler group 0 binding 3 var myTexture0 texture_2d f32 group 0 binding 4 var myTexture1 texture_2d f32 group 0 binding 5 var myTexture2 texture_2d f32 fn ParallaxMapping texCoords vec2 f32 viewDir vec3 f32 vec2 f32 let height textureSample myTexture1 mySampler texCoords x uniforms const1 let p viewDir xy viewDir z height uniforms parallaxValue return texCoords p fn ParallaxHardShadow texCoords vec2 f32 viewDir vec3 f32 height f32 f32 var shadowMultiplier 1 0 if dot vec3 f32 0 0 0 0 1 0 viewDir 0 0 return shadowMultiplier let numSteps clamp uniforms const2 5 0 40 0 5 30 let dir viewDir xy uniforms parallaxValue uniforms const1 1 0 numSteps 4 0 var curTexCoords texCoords var stepDepth textureSample myTexture1 mySampler curTexCoords x for var i 0 0 i numSteps i i 1 0 stepDepth stepDepth i numSteps 1 0 0 0 let curDepth textureSample myTexture1 mySampler curTexCoords x if stepDepth 0 0 return 1 0 if curDepth stepDepth return 0 5 curTexCoords curTexCoords dir return shadowMultiplier fn ParallaxMappingSteep texCoords vec2 f32 viewDir vec3 f32 vec2 f32 let numSteps clamp uniforms const2 5 0 40 0 5 30 var dir viewDir xy uniforms parallaxValue uniforms const1 1 0 numSteps var currTexCoords texCoords var currDepth textureSample myTexture1 mySampler currTexCoords x for var i 0 0 i numSteps i i 1 0 let stepDepth i numSteps 0 0 1 0 let texDepth textureSample myTexture1 mySampler currTexCoords x if texDepth stepDepth break currTexCoords currTexCoords dir return currTexCoords stage fragment fn main location 0 verPos vec3 f32 location 1 tcoord vec2 f32 location 2 normal vec3 f32 location 3 tangent vec3 f32 location 4 color vec3 f32 location 5 eyePos vec3 f32 location 0 vec4 f32 let parallaxValue uniforms parallaxValue 0 5 let const1 uniforms const1 0 02 let const2 uniforms const2 let parallaxType uniforms parallaxType var bt cross normalize normal normalize tangent let tbn mat3x3 f32 normalize tangent normalize bt normalize normal var eyePos2 vec3 f32 0 0 0 0 0 8 3 464101 var EyeT tbn normalize eyePos2 verPos var texCoords tcoord texCoords ParallaxMappingSteep tcoord EyeT let lightPos vec3 f32 8 0 3 0 5 0 let lightDir tbn normalize lightPos verPos var tnormal textureSample myTexture2 mySampler texCoords xyz tnormal normalize tnormal 2 0 1 0 let lightDir2 normalize vec3 f32 0 0 1 0 1 0 let light clamp dot lightDir2 tnormal 0 5 1 0 var shadow 1 0 if parallaxType 1 0 shadow ParallaxHardShadow texCoords lightDir 1 0 var fragColor textureSample myTexture0 mySampler texCoords light shadow fragColor a 1 0 return fragColor var positionBuffer null var colorBuffer null var tcoordsBuffer null var normalBuffer null var tangentBuffer null var indexBuffer null console log creating buffers let arrays v u n f t c for let i 0 i cubev length i arrays v push cubev i p 0 arrays v push cubev i p 1 arrays v push cubev i p 2 arrays c push cubev i c 0 arrays c push cubev i c 1 arrays c push cubev i c 2 arrays u push cubev i u 0 arrays u push cubev i u 1 arrays n push cubev i n 0 arrays n push cubev i n 1 arrays n push cubev i n 2 arrays t push cubev i t 0 arrays t push cubev i t 1 arrays t push cubev i t 2 for let i 0 i cubef length i arrays f push cubef i let positions new Float32Array arrays v let colors new Float32Array arrays c let tcoords new Float32Array arrays u let normals new Float32Array arrays n let tangents new Float32Array arrays t let indices new Uint32Array arrays f positionBuffer device createBuffer size positions byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST colorBuffer device createBuffer size colors byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST tcoordBuffer device createBuffer size tcoords byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST normalBuffer device createBuffer size normals byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST tangentBuffer device createBuffer size tangents byteLength 3 3 usage GPUBufferUsage VERTEX GPUBufferUsage COPY_DST indexBuffer device createBuffer size indices byteLength 3 3 usage GPUBufferUsage INDEX GPUBufferUsage COPY_DST device queue writeBuffer positionBuffer 0 positions device queue writeBuffer colorBuffer 0 colors device queue writeBuffer tcoordBuffer 0 tcoords device queue writeBuffer normalBuffer 0 normals device queue writeBuffer tangentBuffer 0 tangents device queue writeBuffer indexBuffer 0 indices const pipeline device createRenderPipeline layout device createPipelineLayout bindGroupLayouts sceneUniformBindGroupLayout vertex module device createShaderModule code vertWGSL entryPoint main buffers arrayStride 12 attributes shaderLocation 0 format float32x3 offset 0 arrayStride 8 attributes shaderLocation 1 format float32x2 offset 0 arrayStride 12 attributes shaderLocation 2 format float32x3 offset 0 arrayStride 12 attributes shaderLocation 3 format float32x3 offset 0 arrayStride 12 attributes shaderLocation 4 format float32x3 offset 0 fragment module device createShaderModule code fragWGSL entryPoint main targets format presentationFormat primitive topology triangle list frontFace ccw cullMode back depthStencil format depth24plus depthWriteEnabled true depthCompare less const depthTexture device createTexture size canvas width canvas height 1 format depth24plus usage GPUTextureUsage RENDER_ATTACHMENT const renderPassDescription colorAttachments view context getCurrentTexture createView loadValue 0 0 0 8 0 8 1 clear screen storeOp store depthStencilAttachment view depthTexture createView depthLoadValue 1 depthStoreOp store stencilLoadValue 0 stencilStoreOp store rotation 0 0 7 function frame rotation 1 0 001 rotation 0 0 0023 let translate middle x middle y middle z mat4 fromTranslation translateMat translate mat4 fromXRotation rotateXMat rotation 0 mat4 fromYRotation rotateYMat rotation 1 mat4 fromZRotation rotateZMat rotation 2 mat4 multiply modelMatrix rotateYMat rotateZMat mat4 multiply modelMatrix modelMatrix rotateXMat mat4 multiply modelMatrix modelMatrix translateMat device queue writeBuffer uniformBuffer 0 modelMatrix device queue writeBuffer uniformBuffer 192 parallaxValue device queue writeBuffer uniformBuffer 196 const1Value device queue writeBuffer uniformBuffer 200 const2Value device queue writeBuffer uniformBuffer 204 parallaxType renderPassDescription colorAttachments 0 view context getCurrentTexture createView const commandEncoder device createCommandEncoder const renderPass commandEncoder beginRenderPass renderPassDescription renderPass setPipeline pipeline renderPass setVertexBuffer 0 positionBuffer renderPass setVertexBuffer 1 tcoordBuffer renderPass setVertexBuffer 2 normalBuffer renderPass setVertexBuffer 3 tangentBuffer renderPass setVertexBuffer 4 colorBuffer renderPass setIndexBuffer indexBuffer uint32 renderPass setBindGroup 0 sceneUniformBindGroup renderPass drawIndexed cubef length 1 renderPass endPass device queue submit commandEncoder finish requestAnimationFrame frame frame let rstart x rotation 0 y rotation 1 z rotation 2 let mstart x 0 y 0 let dragging false document onmousedown function e if e button 2 return dragging true mstart x e pageX mstart y e pageY rstart x rotation 0 y rotation 1 z rotation 2 document onmouseup function e dragging false document onmousemove function e if dragging return let s 0 01 rotation 0 rstart x mstart y e pageY s rotation 1 rstart y mstart x e pageX s 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 Rocks label input type radio value 0 name myval2 id radio1 label for radio2 Toy label input type radio value 1 name myval2 id radio2 checked checked label for radio3 Brick label input type radio value 2 name myval2 id radio3 label for radio4 Cobbles label input type radio value 3 name myval2 id radio4 label for radio5 Text label input type radio value 4 name myval2 id radio5 fieldset let var3 document createElement div document body appendChild var3 var3 style position absolute var3 style left 30px var3 style bottom 10px var3 style width 300px var3 innerHTML fieldset id var3 legend Select type legend label for radio1 Basic label input type radio value 0 name myval3 id radio1 label for radio2 Shadow label input type radio value 1 name myval3 id radio2 checked checked fieldset let var1 document createElement div document body appendChild var1 var1 id var1 var1 style position absolute var1 style left 35px var1 style top 90px var1 style width 200px let const1 document createElement div document body appendChild const1 const1 id const1 const1 style position absolute const1 style left 35px const1 style top 110px const1 style width 200px let const2 document createElement div document body appendChild const2 const2 id const2 const2 style position absolute const2 style left 35px const2 style top 135px const2 style width 200px 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 document body oncontextmenu function return false script2 onload function var1 slider values parallaxValue 0 min 0 0 max 2 0 step 0 01 slide function event ui ui handle text ui value parallaxValue 0 parseFloat ui value const1 slider values const1Value 0 min 0 5 max 0 5 step 0 01 slide function event ui ui handle text ui value const1Value 0 parseFloat ui value const2 slider values const2Value 0 min 5 0 max 40 0 step 1 0 slide function event ui ui handle text ui value const2Value 0 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 let indx parseFloat selectedValue bgDescriptor entries 3 resource textures indx c createView bgDescriptor entries 4 resource textures indx h createView bgDescriptor entries 5 resource textures indx n createView sceneUniformBindGroup device createBindGroup bgDescriptor var3 change function let selectedValue input name myval3 checked val let indx parseFloat selectedValue parallaxType 0 indx end onload console log ready console log right click and drag to rotate shape

2dracecargame
3dplot
a4print
about
acecustomkeywords
acecustomkeywords2
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
candycrush
candycrush2
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
car2dsimulationphysics
car2dsimulationphysics2
changingimages
chaosgame
chaosrandom
chaosrandomhisto
chaosrandomhisto2
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
curleffect
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
fluiddynamics
fluiddynamics2
fluiddynamics3
fluidgaswatergl
fluidsmokedynamics
fluidsmokedynamics2
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
happyfont
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jsfire
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyboardpiano
keyframes
l2dwidget
lcpsolverrigidbodies
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdown3
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
minkowski2dboxes
misc
misc2
modules
myipdetails
mymodplotly
neataptic
networkstructures
networkstructures2
neural_network_drawshape
neural_network_plot_in_vs_out
neuralnetworkarrays
neuralnetworkblocks
neuralnetworksinewave
neuralnetworksnolibs
neuralnetworkvisualization
noiseflowfield
noiseflowfield2
noiseflowfield3
noiseflowfield4
noiseflowfield5
noiseflowfield6
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
pixelgridpattern
playground
plotly
plotlynoise
plotlyranddist
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
python
quotes
racergame
random
randomcalcpie
randomgenerator
randomprofilepatterns
randomsinhistogram
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
rigidbodyspheres2d
rigidbodyspheres3
rigidbodysphereslopetangent
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdf2dcanvas
sdfboxinboxtwist
sdfchessbishop
sdfchessking
sdfchessknight
sdfchesspawn
sdfchessqueen
sdfchessrook
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
sudoku
sudoku2
sudoku3
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