pex-gl / pex-context

Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
http://pex-gl.github.io/pex-context/
MIT License
160 stars 12 forks source link

Add support for uniforms array #140

Open dmnsgn opened 2 months ago

dmnsgn commented 2 months ago
// Instead of
for (let i = 0; i < directionalLights.length; i++) {
  sharedUniforms[`uDirectionalLights[${i}].intensity`] = directionalLights[i].intensity;
  sharedUniforms[`uDirectionalLights[${i}].color`] = lightColorToSrgb(directionalLights[i]);
}

const uniforms = {
  uDirectionalLights: directionalLights.map((light) => {
    intensity: light.intensity,
    color: lightColorToSrgb(light),
  })
}

ctx.submit({ uniforms })

Will require checking uniforms value Array.isArray of objects.