Setting the values of a struct array from JS to GLSL

前端 未结 1 347
故里飘歌
故里飘歌 2021-01-06 15:08

I\'ve been trying to make a structure that will contain all the lights of my WebGL app, and I\'m having troubles setting up it\'s values from JS. The structure is as follows

相关标签:
1条回答
  • 2021-01-06 15:36

    You're doing it right. You could try to tighten it up a bit as in

    lightLocations = [
      "position",
      "diffuse",
      "specular",
      "ambient",
      "spotDirection",
      "spotCutOff",
      "constantAttenuation",
      "linearAttenuation",
      "quadraticAttenuation",
      "spotExponent",
      "spotLightCosCutOff",
    ];
    
    var program = {
      uniform: {
        lights: [];
      }
    };
    
    for (var ll = 0; ll < numLights; ++ll) {
      var locations = { };
      for (var jj = 0; jj < lightLocations.length; ++jj) {
        var name = lightLocaitons[jj];
        locations = gl.getUniformLocation(program, "lights[" + ll + "]." + name);
      }
      program.uniform.lights[ll] = locations;
    }
    
    0 讨论(0)
提交回复
热议问题