}
private final Vector3 tmpV1 = new Vector3();
protected void bindLights (final Renderable renderable) {
final Environment lights = renderable.environment;
final Array<DirectionalLight> dirs = lights.directionalLights;
final Array<PointLight> points = lights.pointLights;
if (dirLightsLoc >= 0) {
for (int i = 0; i < directionalLights.length; i++) {
if (dirs == null || i >= dirs.size) {
if (lightsSet && directionalLights[i].color.r == 0f && directionalLights[i].color.g == 0f
&& directionalLights[i].color.b == 0f) continue;
directionalLights[i].color.set(0, 0, 0, 1);
} else if (lightsSet && directionalLights[i].equals(dirs.get(i)))
continue;
else
directionalLights[i].set(dirs.get(i));
int idx = dirLightsLoc + i * dirLightsSize;
program.setUniformf(idx + dirLightsColorOffset, directionalLights[i].color.r, directionalLights[i].color.g,
directionalLights[i].color.b);
program.setUniformf(idx + dirLightsDirectionOffset, directionalLights[i].direction);
if (dirLightsSize <= 0) break;
}
}
if (pointLightsLoc >= 0) {
for (int i = 0; i < pointLights.length; i++) {
if (points == null || i >= points.size) {
if (lightsSet && pointLights[i].intensity == 0f) continue;
pointLights[i].intensity = 0f;
} else if (lightsSet && pointLights[i].equals(points.get(i)))
continue;
else
pointLights[i].set(points.get(i));
int idx = pointLightsLoc + i * pointLightsSize;
program.setUniformf(idx + pointLightsColorOffset, pointLights[i].color.r * pointLights[i].intensity,
pointLights[i].color.g * pointLights[i].intensity, pointLights[i].color.b * pointLights[i].intensity);
program.setUniformf(idx + pointLightsPositionOffset, pointLights[i].position);
if (pointLightsSize <= 0) break;
}
}
if (lights.has(ColorAttribute.Fog)) {
set(u_fogColor, ((ColorAttribute)lights.get(ColorAttribute.Fog)).color);
}
if (lights.shadowMap != null) {
set(u_shadowMapProjViewTrans, lights.shadowMap.getProjViewTrans());
set(u_shadowTexture, lights.shadowMap.getDepthMap());