Sto tentando di implementare più luci nel mio shader ma ho difficoltà a riempire l'uniforme con i miei dati chiari.Passaggio di un array di vettori a un'uniforme
mio vertex shader:
attribute vec3 aVertex;
attribute vec3 aNormal;
attribute vec2 aTexture;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;
uniform vec3 uAmbientColor;
uniform vec3 uPointLightingLocation[16];
uniform vec3 uPointLightingColor[16];
varying vec2 vTexture;
varying vec3 vLightWeighting;
void main(void) {
vec4 mvPosition = uMVMatrix * vec4(aVertex, 1.0);
gl_Position = uPMatrix * mvPosition;
vTexture = aTexture;
int i;
for (i = 0; i < 16; i++) {
vec3 lightDirection = normalize(uPointLightingLocation[i] - mvPosition.xyz);
vec4 transformedNormal = uNMatrix * vec4(aNormal, 1.0);
float directionalLightWeighting = max(dot(transformedNormal.xyz, lightDirection), 0.0);
if (i == 0) {
vLightWeighting = uAmbientColor + uPointLightingColor[i] * directionalLightWeighting;
} else {
vLightWeighting = vLightWeighting * (uAmbientColor + uPointLightingColor[i] * directionalLightWeighting);
}
}
}
codice che mostra solo l'ultima luce:
for (var light in this.lightsDirection) {
gl.uniform3fv(this.shaderProgram.pointLightingLocationUniform, this.lightsDirection[light]);
gl.uniform3fv(this.shaderProgram.pointLightingColorUniform, this.lightsColor[light]);
}
Come l'uniforme uPointLightingLocation
è una matrice vec3 con le dimensioni di 16, ho pensato che sarebbe stato possibile passare l'array completo alla divisa, ma non ho una soluzione funzionante.
Quando provo a passare l'array completo this.lightsColor
(senza l'indice) non vedo alcuna luce.
Non vedo perché questa domanda è stata respinta. Sembra perfettamente ragionevole. –