How to use the troika-three-utils.getShaderUniformTypes function in troika-three-utils

To help you get started, we’ve selected a few troika-three-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github protectwise / troika / packages / troika-3d / src / facade / instancing / InstancingShaderUpgrades.js View on Github external
export function upgradeShaders(vertexShader, fragmentShader, instanceUniforms=[]) {
  // Pre-expand includes
  vertexShader = expandShaderIncludes(vertexShader)
  fragmentShader = expandShaderIncludes(fragmentShader)

  // See what gets used
  let usesModelMatrix = modelMatrixRefRE.test(vertexShader)
  let usesModelViewMatrix = modelViewMatrixRefRE.test(vertexShader)
  let usesNormalMatrix = normalMatrixRefRE.test(vertexShader)

  // Find what uniforms are declared in which shader and their types
  let vertexUniforms = getShaderUniformTypes(vertexShader)
  let fragmentUniforms = getShaderUniformTypes(fragmentShader)

  let vertexDeclarations = [modelMatrixRowAttrs]
  let vertexAssignments = []
  let fragmentDeclarations = []

  // Add variable assignments for, and rewrite references to, builtin matrices
  if (usesModelMatrix || usesModelViewMatrix || usesNormalMatrix) {
    vertexShader = vertexShader.replace(modelMatrixRefRE, attrRefReplacer)
    vertexAssignments.push(modelMatrixVarAssignment)
  }
  if (usesModelViewMatrix || usesNormalMatrix) {
    vertexShader = vertexShader.replace(modelViewMatrixRefRE, attrRefReplacer)
    vertexAssignments.push(modelViewMatrixVarAssignment)
  }
  if (usesNormalMatrix) {
github protectwise / troika / packages / troika-3d / src / facade / instancing / InstancingShaderUpgrades.js View on Github external
export function upgradeShaders(vertexShader, fragmentShader, instanceUniforms=[]) {
  // Pre-expand includes
  vertexShader = expandShaderIncludes(vertexShader)
  fragmentShader = expandShaderIncludes(fragmentShader)

  // See what gets used
  let usesModelMatrix = modelMatrixRefRE.test(vertexShader)
  let usesModelViewMatrix = modelViewMatrixRefRE.test(vertexShader)
  let usesNormalMatrix = normalMatrixRefRE.test(vertexShader)

  // Find what uniforms are declared in which shader and their types
  let vertexUniforms = getShaderUniformTypes(vertexShader)
  let fragmentUniforms = getShaderUniformTypes(fragmentShader)

  let vertexDeclarations = [modelMatrixRowAttrs]
  let vertexAssignments = []
  let fragmentDeclarations = []

  // Add variable assignments for, and rewrite references to, builtin matrices
  if (usesModelMatrix || usesModelViewMatrix || usesNormalMatrix) {
    vertexShader = vertexShader.replace(modelMatrixRefRE, attrRefReplacer)
    vertexAssignments.push(modelMatrixVarAssignment)
  }
  if (usesModelViewMatrix || usesNormalMatrix) {
    vertexShader = vertexShader.replace(modelViewMatrixRefRE, attrRefReplacer)
    vertexAssignments.push(modelViewMatrixVarAssignment)
  }
  if (usesNormalMatrix) {
    vertexShader = vertexShader.replace(normalMatrixRefRE, attrRefReplacer)
github protectwise / troika / packages / troika-3d / src / facade / instancing / InstancingManager.js View on Github external
_getInstanceUniformsTypes(material) {
    let cache = this._uniformTypesCache || (this._uniformTypesCache = Object.create(null)) //cache results for duration of this frame
    let result = cache[material.id]
    if (!result) {
      result = cache[material.id] = Object.create(null)
      let {instanceUniforms} = material
      if (instanceUniforms && instanceUniforms.length) {
        let {vertexShader, fragmentShader} = getShadersForMaterial(material)
        let allTypes = assign(
          getShaderUniformTypes(expandShaderIncludes(vertexShader)),
          getShaderUniformTypes(expandShaderIncludes(fragmentShader))
        ) //TODO handle type mismatches?
        for (let i = instanceUniforms.length; i--;) {
          let uniform = instanceUniforms[i]
          if (allTypes[uniform]) {
            result[uniform] = allTypes[uniform]
          }
        }
      }
    }
    return result
  }
github protectwise / troika / packages / troika-3d / src / facade / instancing / InstancingManager.js View on Github external
_getInstanceUniformsTypes(material) {
    let cache = this._uniformTypesCache || (this._uniformTypesCache = Object.create(null)) //cache results for duration of this frame
    let result = cache[material.id]
    if (!result) {
      result = cache[material.id] = Object.create(null)
      let {instanceUniforms} = material
      if (instanceUniforms && instanceUniforms.length) {
        let {vertexShader, fragmentShader} = getShadersForMaterial(material)
        let allTypes = assign(
          getShaderUniformTypes(expandShaderIncludes(vertexShader)),
          getShaderUniformTypes(expandShaderIncludes(fragmentShader))
        ) //TODO handle type mismatches?
        for (let i = instanceUniforms.length; i--;) {
          let uniform = instanceUniforms[i]
          if (allTypes[uniform]) {
            result[uniform] = allTypes[uniform]
          }
        }
      }
    }
    return result
  }

troika-three-utils

Various utilities related to Three.js

MIT
Latest version published 11 days ago

Package Health Score

83 / 100
Full package analysis

Similar packages