[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79E885EYQXYT2V74WR2NX2W":3,"skill-same:01M79E885EYQXYT2V74WR2NX2W":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M79E885EYQXYT2V74WR2NX2W","webgl-and-threejs-3d-experiences",null,"Production WebGL & Three.js 3D experience architecture, custom GLSL shaders, memory management & GPU disposal pipelines, instanced rendering, performance optimization, and anti-patterns.","hamzabellouch\u002Fagent-skills","hamzabellouch","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F237856042?v=4","01M79BRYW7XAMK3YDWQEMTWGWS","Hamza Bellouch","01M79BRYWXQV3JK2TGVTX8GN2A",8,"MIT","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FProgramming\u002FFrontend\u002FModern_Frameworks\u002Fwebgl-and-threejs-3d-experiences\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: webgl-and-threejs-3d-experiences\ndescription: Production WebGL & Three.js 3D experience architecture, custom GLSL shaders, memory management & GPU disposal pipelines, instanced rendering, performance optimization, and anti-patterns.\n---\n\n# WebGL & Three.js 3D Experiences Architecture Guide\n\n## Core Architectural Principles\n\n### 1. Scene Graph Architecture & Render Lifecycle\n- **Unified Engine Class Pattern**: Enforce OOP or functional composition encapsulating `WebGLRenderer`, `Scene`, `PerspectiveCamera`, and RAF loop into a self-contained renderer manager.\n- **Render Loop Delta Capping**: Always cap `clock.getDelta()` (e.g., `Math.min(delta, 0.1)`) to avoid physics explosion\u002Fteleportation during window unfocus or frame drops.\n- **Pixel Ratio Guardrails**: Cap `renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))` to prevent mobile GPUs from rendering native 4K\u002F8K viewports at unusable framerates.\n\n### 2. GPU Memory Management & Resource Lifecycle\n- **Explicit Garbage Collection**: JavaScript GC does not manage VRAM allocated to WebGL buffers, textures, geometries, or render targets.\n- **Disposal Traversal**: Recursively traverse scenes and call `.dispose()` on geometries, materials, textures, and render targets upon component unmount or scene switching.\n- **Resource Pooling & Material Sharing**: Instantiation of geometries and materials must happen outside animation loops. Share materials across meshes wherever possible.\n\n### 3. High-Performance WebGL Techniques\n- **InstancedMesh**: Use `InstancedMesh` for rendering thousands of repetitive objects (particles, trees, debris) using single draw calls.\n- **BVH (Bounding Volume Hierarchy)**: Integrate `three-mesh-bvh` for sub-millisecond raycasting against high-poly meshes instead of brute-force triangle intersection checks.\n- **Compressed Assets**: Standardize on KTX2\u002FBasis for textures and DRACO\u002FMeshopt compression for GLTF\u002FGLB models.\n\n---\n\n## Production Code Examples\n\n### Example 1: Full Production Three.js Engine Lifecycle with Automatic GPU Disposal\n*Location: `src\u002F3d\u002FEngine.ts`*\n\n```typescript\nimport * as THREE from 'three'\nimport { OrbitControls } from 'three\u002Fexamples\u002Fjsm\u002Fcontrols\u002FOrbitControls.js'\n\nexport class Engine {\n  private container: HTMLElement\n  private scene: THREE.Scene\n  private camera: THREE.PerspectiveCamera\n  private renderer: THREE.WebGLRenderer\n  private controls: OrbitControls\n  private clock: THREE.Clock\n  private animationFrameId: number | null = null\n  private isDisposed = false\n\n  constructor(container: HTMLElement) {\n    this.container = container\n\n    \u002F\u002F 1. Scene Initialization\n    this.scene = new THREE.Scene()\n    this.scene.background = new THREE.Color('#0a0a0c')\n\n    \u002F\u002F 2. Camera Setup\n    const aspect = container.clientWidth \u002F container.clientHeight\n    this.camera = new THREE.PerspectiveCamera(60, aspect, 0.1, 1000)\n    this.camera.position.set(0, 5, 10)\n\n    \u002F\u002F 3. WebGL Renderer Setup with Pixel Ratio Capping\n    this.renderer = new THREE.WebGLRenderer({\n      antialias: true,\n      alpha: false,\n      powerPreference: 'high-performance'\n    })\n    this.renderer.setSize(container.clientWidth, container.clientHeight)\n    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))\n    this.renderer.shadowMap.enabled = true\n    this.renderer.shadowMap.type = THREE.PCFSoftShadowMap\n    this.renderer.outputColorSpace = THREE.SRGBColorSpace\n\n    container.appendChild(this.renderer.domElement)\n\n    \u002F\u002F 4. Controls & Time Tracking\n    this.controls = new OrbitControls(this.camera, this.renderer.domElement)\n    this.controls.enableDamping = true\n    this.controls.dampingFactor = 0.05\n\n    this.clock = new THREE.Clock()\n\n    \u002F\u002F 5. Setup Listeners & Start Loop\n    window.addEventListener('resize', this.onResize)\n    this.start()\n  }\n\n  private onResize = () => {\n    if (this.isDisposed) return\n    const width = this.container.clientWidth\n    const height = this.container.clientHeight\n\n    this.camera.aspect = width \u002F height\n    this.camera.updateProjectionMatrix()\n\n    this.renderer.setSize(width, height)\n    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))\n  }\n\n  private start() {\n    const tick = () => {\n      if (this.isDisposed) return\n\n      \u002F\u002F Delta capping to prevent un-focused window physics explosions\n      const delta = Math.min(this.clock.getDelta(), 0.1)\n\n      this.controls.update()\n      this.renderer.render(this.scene, this.camera)\n\n      this.animationFrameId = requestAnimationFrame(tick)\n    }\n\n    tick()\n  }\n\n  public getScene(): THREE.Scene {\n    return this.scene\n  }\n\n  \u002F\u002F Comprehensive GPU Memory Cleanup Pipeline\n  public dispose() {\n    this.isDisposed = true\n\n    if (this.animationFrameId !== null) {\n      cancelAnimationFrame(this.animationFrameId)\n    }\n\n    window.removeEventListener('resize', this.onResize)\n    this.controls.dispose()\n\n    \u002F\u002F Recursive traversal and disposal of all geometries, materials, and textures\n    this.scene.traverse((object: THREE.Object3D) => {\n      if (!(object instanceof THREE.Mesh)) return\n\n      \u002F\u002F Dispose geometry\n      object.geometry.dispose()\n\n      \u002F\u002F Dispose material(s)\n      if (Array.isArray(object.material)) {\n        object.material.forEach((mat) => this.disposeMaterial(mat))\n      } else if (object.material) {\n        this.disposeMaterial(object.material)\n      }\n    })\n\n    this.renderer.dispose()\n    if (this.renderer.domElement && this.renderer.domElement.parentElement) {\n      this.renderer.domElement.parentElement.removeChild(this.renderer.domElement)\n    }\n  }\n\n  private disposeMaterial(material: THREE.Material) {\n    material.dispose()\n\n    \u002F\u002F Dispose all potential texture maps on the material\n    for (const key of Object.keys(material)) {\n      const value = (material as any)[key]\n      if (value && value instanceof THREE.Texture) {\n        value.dispose()\n      }\n    }\n  }\n}\n```\n\n### Example 2: High-Performance `InstancedMesh` Particle Grid\n*Location: `src\u002F3d\u002FInstancedGrid.ts`*\n\n```typescript\nimport * as THREE from 'three'\n\nexport function createInstancedGrid(gridSize: number = 50): THREE.InstancedMesh {\n  const count = gridSize * gridSize\n  const geometry = new THREE.BoxGeometry(0.8, 0.8, 0.8)\n  const material = new THREE.MeshStandardMaterial({\n    color: new THREE.Color('#3a86ff'),\n    roughness: 0.2,\n    metalness: 0.8\n  })\n\n  const instancedMesh = new THREE.InstancedMesh(geometry, material, count)\n  instancedMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage) \u002F\u002F Matrix updates every frame\n\n  const dummy = new THREE.Object3D()\n  let index = 0\n\n  const halfGrid = gridSize \u002F 2\n  for (let x = 0; x \u003C gridSize; x++) {\n    for (let z = 0; z \u003C gridSize; z++) {\n      dummy.position.set(x - halfGrid, 0, z - halfGrid)\n      dummy.updateMatrix()\n      instancedMesh.setMatrixAt(index++, dummy.matrix)\n    }\n  }\n\n  instancedMesh.instanceMatrix.needsUpdate = true\n  return instancedMesh\n}\n\n\u002F\u002F Render-loop height wave animator for InstancedMesh\nexport function animateInstancedGrid(\n  instancedMesh: THREE.InstancedMesh,\n  gridSize: number,\n  time: number\n) {\n  const dummy = new THREE.Object3D()\n  const matrix = new THREE.Matrix4()\n  const position = new THREE.Vector3()\n  let index = 0\n\n  for (let x = 0; x \u003C gridSize; x++) {\n    for (let z = 0; z \u003C gridSize; z++) {\n      instancedMesh.getMatrixAt(index, matrix)\n      position.setFromMatrixPosition(matrix)\n\n      \u002F\u002F Calculate dynamic wave height offset using sine\u002Fcosine harmonics\n      const dist = Math.sqrt(position.x * position.x + position.z * position.z)\n      const y = Math.sin(dist * 0.5 - time * 3) * 0.8\n\n      dummy.position.set(position.x, y, position.z)\n      dummy.updateMatrix()\n      instancedMesh.setMatrixAt(index++, dummy.matrix)\n    }\n  }\n\n  instancedMesh.instanceMatrix.needsUpdate = true\n}\n```\n\n### Example 3: Custom GLSL Animated Vertex Displacement Shader\n*Location: `src\u002F3d\u002Fshaders\u002FWaveShader.ts`*\n\n```typescript\nimport * as THREE from 'three'\n\nconst vertexShader = \u002F* glsl *\u002F `\n  uniform float uTime;\n  uniform float uWaveSpeed;\n  uniform float uWaveFrequency;\n  uniform float uWaveElevation;\n\n  varying vec2 vUv;\n  varying float vElevation;\n\n  void main() {\n    vUv = uv;\n\n    vec4 modelPosition = modelMatrix * vec4(position, 1.0);\n\n    float elevation = sin(modelPosition.x * uWaveFrequency + uTime * uWaveSpeed) *\n                      cos(modelPosition.z * uWaveFrequency + uTime * uWaveSpeed) *\n                      uWaveElevation;\n\n    modelPosition.y += elevation;\n    vElevation = elevation;\n\n    vec4 viewPosition = viewMatrix * modelPosition;\n    vec4 projectedPosition = projectionMatrix * viewPosition;\n\n    gl_Position = projectedPosition;\n  }\n`\n\nconst fragmentShader = \u002F* glsl *\u002F `\n  uniform vec3 uDepthColor;\n  uniform vec3 uSurfaceColor;\n  uniform float uColorOffset;\n  uniform float uColorMultiplier;\n\n  varying vec2 vUv;\n  varying float vElevation;\n\n  void main() {\n    float mixStrength = (vElevation + uColorOffset) * uColorMultiplier;\n    vec3 color = mix(uDepthColor, uSurfaceColor, clamp(mixStrength, 0.0, 1.0));\n\n    gl_FragColor = vec4(color, 1.0);\n  }\n`\n\nexport function createWaveMaterial(): THREE.ShaderMaterial {\n  return new THREE.ShaderMaterial({\n    vertexShader,\n    fragmentShader,\n    uniforms: {\n      uTime: { value: 0 },\n      uWaveSpeed: { value: 2.0 },\n      uWaveFrequency: { value: 1.5 },\n      uWaveElevation: { value: 0.5 },\n      uDepthColor: { value: new THREE.Color('#001219') },\n      uSurfaceColor: { value: new THREE.Color('#0a9396') },\n      uColorOffset: { value: 0.2 },\n      uColorMultiplier: { value: 1.5 }\n    },\n    wireframe: false\n  })\n}\n```\n\n---\n\n## Anti-Patterns & Common Pitfalls\n\n### ❌ Anti-Pattern 1: Allocating Geometries or Materials Inside the Render Loop\n```typescript\n\u002F\u002F BAD: Allocating WebGL objects every frame spikes CPU garbage collection & causes VRAM leaks!\nfunction tick() {\n  const geometry = new THREE.SphereGeometry(1, 32, 32) \u002F\u002F BUG: 60 objects created per second!\n  const mesh = new THREE.Mesh(geometry, sharedMaterial)\n  scene.add(mesh)\n\n  renderer.render(scene, camera)\n  requestAnimationFrame(tick)\n}\n\n\u002F\u002F GOOD: Allocate once and reuse references or use InstancedMesh\nconst sphereGeometry = new THREE.SphereGeometry(1, 32, 32)\n```\n\n### ❌ Anti-Pattern 2: Uncapped Pixel Ratio on High DPI Mobile Displays\n```typescript\n\u002F\u002F BAD: Rendering 4K native canvas on mobile device GPUs destroys FPS\nrenderer.setPixelRatio(window.devicePixelRatio) \u002F\u002F Device ratio could be 3.5 or 4!\n\n\u002F\u002F GOOD: Cap device pixel ratio at maximum of 2\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))\n```\n\n### ❌ Anti-Pattern 3: Removing Meshes from Scene without Calling `dispose()`\n```typescript\n\u002F\u002F BAD: Removing mesh from scene graph leaves WebGL geometry\u002Ftexture memory allocated on GPU\nscene.remove(mesh) \u002F\u002F GPU VRAM memory is STILL allocated!\n\n\u002F\u002F GOOD: Remove AND call dispose() on geometries & materials\nscene.remove(mesh)\nmesh.geometry.dispose()\nif (Array.isArray(mesh.material)) {\n  mesh.material.forEach((m) => m.dispose())\n} else {\n  mesh.material.dispose()\n}\n```\n\n### ❌ Anti-Pattern 4: Uncapped `clock.getDelta()` on Frame Lag or Tab Unfocus\n```typescript\n\u002F\u002F BAD: Switching browser tabs makes delta huge (e.g. 5 seconds), breaking animation\u002Fphysics calculation\nconst delta = clock.getDelta()\nmesh.position.x += delta * 10 \u002F\u002F Object teleports out of view!\n\n\u002F\u002F GOOD: Clamp delta calculation\nconst delta = Math.min(clock.getDelta(), 0.1)\nmesh.position.x += delta * 10\n```\n","# WebGL & Three.js 3D Experiences Architecture Guide\n\n## Core Architectural Principles\n\n### 1. Scene Graph Architecture & Render Lifecycle\n- **Unified Engine Class Pattern**: Enforce OOP or functional composition encapsulating `WebGLRenderer`, `Scene`, `PerspectiveCamera`, and RAF loop into a self-contained renderer manager.\n- **Render Loop Delta Capping**: Always cap `clock.getDelta()` (e.g., `Math.min(delta, 0.1)`) to avoid physics explosion\u002Fteleportation during window unfocus or frame drops.\n- **Pixel Ratio Guardrails**: Cap `renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))` to prevent mobile GPUs from rendering native 4K\u002F8K viewports at unusable framerates.\n\n### 2. GPU Memory Management & Resource Lifecycle\n- **Explicit Garbage Collection**: JavaScript GC does not manage VRAM allocated to WebGL buffers, textures, geometries, or render targets.\n- **Disposal Traversal**: Recursively traverse scenes and call `.dispose()` on geometries, materials, textures, and render targets upon component unmount or scene switching.\n- **Resource Pooling & Material Sharing**: Instantiation of geometries and materials must happen outside animation loops. Share materials across meshes wherever possible.\n\n### 3. High-Performance WebGL Techniques\n- **InstancedMesh**: Use `InstancedMesh` for rendering thousands of repetitive objects (particles, trees, debris) using single draw calls.\n- **BVH (Bounding Volume Hierarchy)**: Integrate `three-mesh-bvh` for sub-millisecond raycasting against high-poly meshes instead of brute-force triangle intersection checks.\n- **Compressed Assets**: Standardize on KTX2\u002FBasis for textures and DRACO\u002FMeshopt compression for GLTF\u002FGLB models.\n\n---\n\n## Production Code Examples\n\n### Example 1: Full Production Three.js Engine Lifecycle with Automatic GPU Disposal\n*Location: `src\u002F3d\u002FEngine.ts`*\n\n```typescript\nimport * as THREE from 'three'\nimport { OrbitControls } from 'three\u002Fexamples\u002Fjsm\u002Fcontrols\u002FOrbitControls.js'\n\nexport class Engine {\n  private container: HTMLElement\n  private scene: THREE.Scene\n  private camera: THREE.PerspectiveCamera\n  private renderer: THREE.WebGLRenderer\n  private controls: OrbitControls\n  private clock: THREE.Clock\n  private animationFrameId: number | null = null\n  private isDisposed = false\n\n  constructor(container: HTMLElement) {\n    this.container = container\n\n    \u002F\u002F 1. Scene Initialization\n    this.scene = new THREE.Scene()\n    this.scene.background = new THREE.Color('#0a0a0c')\n\n    \u002F\u002F 2. Camera Setup\n    const aspect = container.clientWidth \u002F container.clientHeight\n    this.camera = new THREE.PerspectiveCamera(60, aspect, 0.1, 1000)\n    this.camera.position.set(0, 5, 10)\n\n    \u002F\u002F 3. WebGL Renderer Setup with Pixel Ratio Capping\n    this.renderer = new THREE.WebGLRenderer({\n      antialias: true,\n      alpha: false,\n      powerPreference: 'high-performance'\n    })\n    this.renderer.setSize(container.clientWidth, container.clientHeight)\n    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))\n    this.renderer.shadowMap.enabled = true\n    this.renderer.shadowMap.type = THREE.PCFSoftShadowMap\n    this.renderer.outputColorSpace = THREE.SRGBColorSpace\n\n    container.appendChild(this.renderer.domElement)\n\n    \u002F\u002F 4. Controls & Time Tracking\n    this.controls = new OrbitControls(this.camera, this.renderer.domElement)\n    this.controls.enableDamping = true\n    this.controls.dampingFactor = 0.05\n\n    this.clock = new THREE.Clock()\n\n    \u002F\u002F 5. Setup Listeners & Start Loop\n    window.addEventListener('resize', this.onResize)\n    this.start()\n  }\n\n  private onResize = () => {\n    if (this.isDisposed) return\n    const width = this.container.clientWidth\n    const height = this.container.clientHeight\n\n    this.camera.aspect = width \u002F height\n    this.camera.updateProjectionMatrix()\n\n    this.renderer.setSize(width, height)\n    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))\n  }\n\n  private start() {\n    const tick = () => {\n      if (this.isDisposed) return\n\n      \u002F\u002F Delta capping to prevent un-focused window physics explosions\n      const delta = Math.min(this.clock.getDelta(), 0.1)\n\n      this.controls.update()\n      this.renderer.render(this.scene, this.camera)\n\n      this.animationFrameId = requestAnimationFrame(tick)\n    }\n\n    tick()\n  }\n\n  public getScene(): THREE.Scene {\n    return this.scene\n  }\n\n  \u002F\u002F Comprehensive GPU Memory Cleanup Pipeline\n  public dispose() {\n    this.isDisposed = true\n\n    if (this.animationFrameId !== null) {\n      cancelAnimationFrame(this.animationFrameId)\n    }\n\n    window.removeEventListener('resize', this.onResize)\n    this.controls.dispose()\n\n    \u002F\u002F Recursive traversal and disposal of all geometries, materials, and textures\n    this.scene.traverse((object: THREE.Object3D) => {\n      if (!(object instanceof THREE.Mesh)) return\n\n      \u002F\u002F Dispose geometry\n      object.geometry.dispose()\n\n      \u002F\u002F Dispose material(s)\n      if (Array.isArray(object.material)) {\n        object.material.forEach((mat) => this.disposeMaterial(mat))\n      } else if (object.material) {\n        this.disposeMaterial(object.material)\n      }\n    })\n\n    this.renderer.dispose()\n    if (this.renderer.domElement && this.renderer.domElement.parentElement) {\n      this.renderer.domElement.parentElement.removeChild(this.renderer.domElement)\n    }\n  }\n\n  private disposeMaterial(material: THREE.Material) {\n    material.dispose()\n\n    \u002F\u002F Dispose all potential texture maps on the material\n    for (const key of Object.keys(material)) {\n      const value = (material as any)[key]\n      if (value && value instanceof THREE.Texture) {\n        value.dispose()\n      }\n    }\n  }\n}\n```\n\n### Example 2: High-Performance `InstancedMesh` Particle Grid\n*Location: `src\u002F3d\u002FInstancedGrid.ts`*\n\n```typescript\nimport * as THREE from 'three'\n\nexport function createInstancedGrid(gridSize: number = 50): THREE.InstancedMesh {\n  const count = gridSize * gridSize\n  const geometry = new THREE.BoxGeometry(0.8, 0.8, 0.8)\n  const material = new THREE.MeshStandardMaterial({\n    color: new THREE.Color('#3a86ff'),\n    roughness: 0.2,\n    metalness: 0.8\n  })\n\n  const instancedMesh = new THREE.InstancedMesh(geometry, material, count)\n  instancedMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage) \u002F\u002F Matrix updates every frame\n\n  const dummy = new THREE.Object3D()\n  let index = 0\n\n  const halfGrid = gridSize \u002F 2\n  for (let x = 0; x \u003C gridSize; x++) {\n    for (let z = 0; z \u003C gridSize; z++) {\n      dummy.position.set(x - halfGrid, 0, z - halfGrid)\n      dummy.updateMatrix()\n      instancedMesh.setMatrixAt(index++, dummy.matrix)\n    }\n  }\n\n  instancedMesh.instanceMatrix.needsUpdate = true\n  return instancedMesh\n}\n\n\u002F\u002F Render-loop height wave animator for InstancedMesh\nexport function animateInstancedGrid(\n  instancedMesh: THREE.InstancedMesh,\n  gridSize: number,\n  time: number\n) {\n  const dummy = new THREE.Object3D()\n  const matrix = new THREE.Matrix4()\n  const position = new THREE.Vector3()\n  let index = 0\n\n  for (let x = 0; x \u003C gridSize; x++) {\n    for (let z = 0; z \u003C gridSize; z++) {\n      instancedMesh.getMatrixAt(index, matrix)\n      position.setFromMatrixPosition(matrix)\n\n      \u002F\u002F Calculate dynamic wave height offset using sine\u002Fcosine harmonics\n      const dist = Math.sqrt(position.x * position.x + position.z * position.z)\n      const y = Math.sin(dist * 0.5 - time * 3) * 0.8\n\n      dummy.position.set(position.x, y, position.z)\n      dummy.updateMatrix()\n      instancedMesh.setMatrixAt(index++, dummy.matrix)\n    }\n  }\n\n  instancedMesh.instanceMatrix.needsUpdate = true\n}\n```\n\n### Example 3: Custom GLSL Animated Vertex Displacement Shader\n*Location: `src\u002F3d\u002Fshaders\u002FWaveShader.ts`*\n\n```typescript\nimport * as THREE from 'three'\n\nconst vertexShader = \u002F* glsl *\u002F `\n  uniform float uTime;\n  uniform float uWaveSpeed;\n  uniform float uWaveFrequency;\n  uniform float uWaveElevation;\n\n  varying vec2 vUv;\n  varying float vElevation;\n\n  void main() {\n    vUv = uv;\n\n    vec4 modelPosition = modelMatrix * vec4(position, 1.0);\n\n    float elevation = sin(modelPosition.x * uWaveFrequency + uTime * uWaveSpeed) *\n                      cos(modelPosition.z * uWaveFrequency + uTime * uWaveSpeed) *\n                      uWaveElevation;\n\n    modelPosition.y += elevation;\n    vElevation = elevation;\n\n    vec4 viewPosition = viewMatrix * modelPosition;\n    vec4 projectedPosition = projectionMatrix * viewPosition;\n\n    gl_Position = projectedPosition;\n  }\n`\n\nconst fragmentShader = \u002F* glsl *\u002F `\n  uniform vec3 uDepthColor;\n  uniform vec3 uSurfaceColor;\n  uniform float uColorOffset;\n  uniform float uColorMultiplier;\n\n  varying vec2 vUv;\n  varying float vElevation;\n\n  void main() {\n    float mixStrength = (vElevation + uColorOffset) * uColorMultiplier;\n    vec3 color = mix(uDepthColor, uSurfaceColor, clamp(mixStrength, 0.0, 1.0));\n\n    gl_FragColor = vec4(color, 1.0);\n  }\n`\n\nexport function createWaveMaterial(): THREE.ShaderMaterial {\n  return new THREE.ShaderMaterial({\n    vertexShader,\n    fragmentShader,\n    uniforms: {\n      uTime: { value: 0 },\n      uWaveSpeed: { value: 2.0 },\n      uWaveFrequency: { value: 1.5 },\n      uWaveElevation: { value: 0.5 },\n      uDepthColor: { value: new THREE.Color('#001219') },\n      uSurfaceColor: { value: new THREE.Color('#0a9396') },\n      uColorOffset: { value: 0.2 },\n      uColorMultiplier: { value: 1.5 }\n    },\n    wireframe: false\n  })\n}\n```\n\n---\n\n## Anti-Patterns & Common Pitfalls\n\n### ❌ Anti-Pattern 1: Allocating Geometries or Materials Inside the Render Loop\n```typescript\n\u002F\u002F BAD: Allocating WebGL objects every frame spikes CPU garbage collection & causes VRAM leaks!\nfunction tick() {\n  const geometry = new THREE.SphereGeometry(1, 32, 32) \u002F\u002F BUG: 60 objects created per second!\n  const mesh = new THREE.Mesh(geometry, sharedMaterial)\n  scene.add(mesh)\n\n  renderer.render(scene, camera)\n  requestAnimationFrame(tick)\n}\n\n\u002F\u002F GOOD: Allocate once and reuse references or use InstancedMesh\nconst sphereGeometry = new THREE.SphereGeometry(1, 32, 32)\n```\n\n### ❌ Anti-Pattern 2: Uncapped Pixel Ratio on High DPI Mobile Displays\n```typescript\n\u002F\u002F BAD: Rendering 4K native canvas on mobile device GPUs destroys FPS\nrenderer.setPixelRatio(window.devicePixelRatio) \u002F\u002F Device ratio could be 3.5 or 4!\n\n\u002F\u002F GOOD: Cap device pixel ratio at maximum of 2\nrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))\n```\n\n### ❌ Anti-Pattern 3: Removing Meshes from Scene without Calling `dispose()`\n```typescript\n\u002F\u002F BAD: Removing mesh from scene graph leaves WebGL geometry\u002Ftexture memory allocated on GPU\nscene.remove(mesh) \u002F\u002F GPU VRAM memory is STILL allocated!\n\n\u002F\u002F GOOD: Remove AND call dispose() on geometries & materials\nscene.remove(mesh)\nmesh.geometry.dispose()\nif (Array.isArray(mesh.material)) {\n  mesh.material.forEach((m) => m.dispose())\n} else {\n  mesh.material.dispose()\n}\n```\n\n### ❌ Anti-Pattern 4: Uncapped `clock.getDelta()` on Frame Lag or Tab Unfocus\n```typescript\n\u002F\u002F BAD: Switching browser tabs makes delta huge (e.g. 5 seconds), breaking animation\u002Fphysics calculation\nconst delta = clock.getDelta()\nmesh.position.x += delta * 10 \u002F\u002F Object teleports out of view!\n\n\u002F\u002F GOOD: Clamp delta calculation\nconst delta = Math.min(clock.getDelta(), 0.1)\nmesh.position.x += delta * 10\n```\n",{"name":5,"description":7},"main","e905af21e5f1e1c3ca605e9656c3a7930360a84e","Programming\u002FFrontend\u002FModern_Frameworks\u002Fwebgl-and-threejs-3d-experiences",1,"https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills","https:\u002F\u002Fhamzabellouch.github.io\u002F","https:\u002F\u002Fgithub.com\u002Fhamzabellouch","hamzabellouch.github.io","CEO & Founder of @tknoglobal | Researcher in Technology & Applied Sciences.","2026-10-17 03:20:19",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add hamzabellouch\u002Fagent-skills --skill webgl-and-threejs-3d-experiences",{"tool":40,"command":41},"bunx","bunx skills add hamzabellouch\u002Fagent-skills --skill webgl-and-threejs-3d-experiences",{"tool":43,"command":44},"pnpm","pnpm dlx skills add hamzabellouch\u002Fagent-skills --skill webgl-and-threejs-3d-experiences","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FProgramming\u002FFrontend\u002FModern_Frameworks\u002Fwebgl-and-threejs-3d-experiences\u002FSKILL.md",true,[],[49,56,63,70,77,84],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":19},"01M79FHH2H815A9TAP6WNKH4Q8","security-audit","Comprehensive security guidance, source code audit, vulnerability assessment, and penetration test review for codebases, APIs, microservices, CLI tools, libraries, and LLM-backed applications. Triggers on requests to audit a codebase, conduct security reviews, find vulnerabilities or flaws, pen-test source code, or when the user asks in Arabic (فحص أمني، تدقيق الكود أمنياً، مراجعة الثغرات، فحص أمان المشروع). Supports Guidance mode (focused review) and Full Audit mode (deterministic 6-phase harness).","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FSecurity_Audit_and_Code_Review\u002Fsecurity-audit\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M79FHBGXVBY6VQ1X7ETAZMF1","malware-analysis-reversing","Production malware analysis workflows, reverse engineering methodologies, isolated sandbox triage, static\u002Fdynamic binary analysis, memory forensics, and YARA detection rule authoring.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FOffensive_Security_and_Pentesting\u002Fmalware-analysis-reversing\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M79FH6EACDR801TZCE4R8SAC","application-security-pentesting","Production Application Security (AppSec) standards, OWASP Top 10 vulnerability remediation, SAST\u002FDAST pipeline integration, secure code review, threat modeling, and defensive security posture.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FOffensive_Security_and_Pentesting\u002Fapplication-security-pentesting\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M79FH0VKVT44FK923K520ZQA","oauth2-oidc-security-flows","Implement enterprise OAuth 2.1 and OpenID Connect (OIDC) authorization code flow with Proof Key for Code Exchange (PKCE), state and nonce verification, refresh token rotation, token revocation, and centralized IdP federation (Keycloak, Auth0, Okta). Trigger when building secure authentication, single sign-on (SSO), or third-party delegated authorization.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FIdentity_and_Access_Management_IAM\u002Foauth2-oidc-security-flows\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M79FGVVB3R4T88XXD8FRSV5B","jwt-session-management-hardening","Harden JWT-based authentication and session lifecycles using asymmetric signing (RS256\u002FEdDSA), JWKS rotation, strict claims validation, Redis-backed sliding window sessions, revocation lists, and secure HttpOnly cookie storage. Trigger when implementing token validation, session revocation, or hardening API authentication.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FIdentity_and_Access_Management_IAM\u002Fjwt-session-management-hardening\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M79FGNCPZ85CVEY0B3NE4H3B","soc2-compliance-automation","Best practices for implementing SOC 2 Type II compliance controls, continuous evidence collection, infrastructure policy-as-code, and automated security monitoring. Use when automating Trust Services Criteria (Security, Availability, Confidentiality, Processing Integrity, Privacy), audit logging, IAM least privilege, or CI\u002FCD security gates.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FGovernance_Compliance_and_Legal_Tech\u002Fsoc2-compliance-automation\u002FSKILL.md",[],[]]