Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WgCompCollisionGlobalShader

Performs collision detection globally, over all provided elements/atoms. For each element atom, this shader compares each atom with its neighbors (found via a uniform grid).

Based on an atom's radius, its proximity with a neighbor, and whether they have a bond, a collision is determined Element/Atom A collides with atom B if the following applies:

  • A and B are different: index(A) != index(B)
  • A and B overlap: distance(A,B) < radius(A) + radius(B) - lenience <- Lenience is a uniform parameter
  • A and B do not have a bond: !bond(A,B) If any of these rules do not apply, element/atom A does NOT collide

This check is performed for each element/atom. The output of this shader is a 'collisions' U32 buffer where each bit represents whether an atom collides or not. 0 means the atom does not collide with any other atom; 1 means the atom collides with at least one other atom

Hierarchy

Index

Constructors

constructor

  • Parameters

    • context: WgContext

      The WebGPU context

    • input: WgCompCollisionGlobalShaderInput

      The input buffers: - in_xyzcr: Input data, describing each element/atom's data. Each element/atom is described by 4x float32 elements in this buffer. The first 3 f32s describe the element/atom's 3D XYZ position The 4th f32 encodes the following: - The element/atom's radius in picometers, encoded in the first 8 bits - The element/atom's initial index (elemId), encoded in the last 24 bits See 'in_bonds' to see how elemId is useful

               - in_bonds:                Input data, describing each element/atom's BOND information
                                          Each element/atom is described by 4x uint32 elements in this buffer.
                                          Each of these 4 elements represents the initial index (elemId) of another
                                          element/atom, with which this element/atom has a bond.
                                          To indicate that no bonds exists, the value 0xffffffff is used.
                                          That allows these 4x uint32 slots to point
                                          from 0 to 4 other elements/atoms.
      
               - in_perBinElemCount_scan: The scan/prefix-sum of the element/atom count of each bin/cell of
                                          the grid (see WgCompScanShader).
      
               - out_collisions:          The output buffer, describing, for each atom, whether this atom collides
                                          or not. This is a U32 buffer, where each bit encodes an element/atom.
                                          0 means that this atom does not collide with any other atom.
                                          1 means that this atom collides with at least one other atom.
                                          See this class's description for more details
      
    • uniforms: WgCompCollisionGlobalShaderUniforms

      The uniforms for this shader:

                  - gridMin:     The min-point of the grid
                  - gridMax:     The max-point of the grid
                  - gridBinSize: The xyz sizes of a grid bin/cell
                  Together, these three values describe an axis-aligned box, subdivided uniformly into bins/cells
      
                  - lenience:    Given in Ångströms.
                                 A bias value that allows elements/atoms that overlap just a little bit to be
                                 considered as non-overlapping. The largest this value is, the less collisions are
                                 expected to be detected
      
    • Optional output: WgCompCollisionGlobalShaderOutput

      The output buffer and offset (useful for debugging)

    Returns WgCompCollisionGlobalShader

Properties

Private Readonly collisionUniforms

collisionUniforms: WgBuffer<Float32Array>

Private Readonly gridUniforms

gridUniforms: WgBuffer<Float32Array>

Private Readonly input

Private Optional Readonly output

Accessors

bindGroups

  • get bindGroups(): { bindGroup: GPUBindGroup; index: number }[]

dispatchSize

  • get dispatchSize(): [number, number, number]

outputs

  • get outputs(): { byteSize: number; dst: WgBuffer<Uint32Array>; dstOffset: number; src: WgBuffer<Uint32Array>; srcOffset: number }[]

pipeline

  • get pipeline(): GPUComputePipeline

workgroupSize

  • get workgroupSize(): keyof [number, number, number]

Methods

dispose

  • dispose(): void

setCollisionParams

  • setCollisionParams(params: { lenience: number }): void

Generated using TypeDoc