protected int updateLightListUniforms(Shader shader, Geometry g, LightList lightList, int numLights, RenderManager rm, int startIndex, int lastTexUnit) {
        if (numLights == 0) { // this shader does not do lighting, ignore.
            return 0;
        }

        Uniform lightData = shader.getUniform("g_LightData");
        lightData.setVector4Length(numLights * 3);//8 lights * max 3
        Uniform ambientColor = shader.getUniform("g_AmbientLightColor");

        // Matrix4f
        Uniform lightProbeData = shader.getUniform("g_LightProbeData");
        Uniform lightProbeData2 = shader.getUniform("g_LightProbeData2");
        Uniform lightProbeData3 = shader.getUniform("g_LightProbeData3");

        Uniform shCoeffs = shader.getUniform("g_ShCoeffs");
        Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
        Uniform shCoeffs2 = shader.getUniform("g_ShCoeffs2");
        Uniform lightProbePemMap2 = shader.getUniform("g_PrefEnvMap2");
        Uniform shCoeffs3 = shader.getUniform("g_ShCoeffs3");
        Uniform lightProbePemMap3 = shader.getUniform("g_PrefEnvMap3");

        lightProbes.clear();
        if (startIndex != 0) {
            // apply additive blending for 2nd and future passes
            rm.getRenderer().applyRenderState(ADDITIVE_LIGHT);
            ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
        } else {
            extractIndirectLights(lightList,true);
            ambientColor.setValue(VarType.Vector4, ambientLightColor);
        }

        //If there is a lightProbe in the list we force its render on the first pass
        if (!lightProbes.isEmpty()) {
            LightProbe lightProbe = lightProbes.get(0);
            lastTexUnit = setProbeData(rm, lastTexUnit, lightProbeData, shCoeffs, lightProbePemMap, lightProbe);
            if (lightProbes.size() > 1) {
                lightProbe = lightProbes.get(1);
                lastTexUnit = setProbeData(rm, lastTexUnit, lightProbeData2, shCoeffs2, lightProbePemMap2, lightProbe);
            }
            if (lightProbes.size() > 2) {
                lightProbe = lightProbes.get(2);
                setProbeData(rm, lastTexUnit, lightProbeData3, shCoeffs3, lightProbePemMap3, lightProbe);
            }
        } else {
            //Disable IBL for this pass
            lightProbeData.setValue(VarType.Matrix4, LightProbe.FALLBACK_MATRIX);
        }

        int lightDataIndex = 0;
        TempVars vars = TempVars.get();
        Vector4f tmpVec = vars.vect4f1;
        int curIndex;
        int endIndex = numLights + startIndex;
        for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
            Light l = lightList.get(curIndex);
            if(l.getType() == Light.Type.Ambient){
                endIndex++;
                continue;
            }
            ColorRGBA color = l.getColor();
            //Color

            if(l.getType() != Light.Type.Probe){
                lightData.setVector4InArray(color.getRed(),
                        color.getGreen(),
                        color.getBlue(),
                        l.getType().getId(),
                        lightDataIndex);
                lightDataIndex++;
            }

            switch (l.getType()) {
                case Directional:
                    DirectionalLight dl = (DirectionalLight) l;
                    Vector3f dir = dl.getDirection();
                    //Data directly sent in view space to avoid a matrix mult for each pixel
                    tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
                    lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
                    lightDataIndex++;
                    //PADDING
                    lightData.setVector4InArray(0,0,0,0, lightDataIndex);
                    lightDataIndex++;
                    break;
                case Point:
                    PointLight pl = (PointLight) l;
                    Vector3f pos = pl.getPosition();
                    float invRadius = pl.getInvRadius();
                    tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);

                    lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
                    lightDataIndex++;
                    //PADDING
                    lightData.setVector4InArray(0,0,0,0, lightDataIndex);
                    lightDataIndex++;
                    break;
                case Spot:
                    SpotLight sl = (SpotLight) l;
                    Vector3f pos2 = sl.getPosition();
                    Vector3f dir2 = sl.getDirection();
                    float invRange = sl.getInvSpotRange();
                    float spotAngleCos = sl.getPackedAngleCos();
                    tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(),  1.0f);

                    lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
                    lightDataIndex++;

                    tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(),  0.0f);
                    lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
                    lightDataIndex++;
                    break;
                default:
                    throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
            }
        }
        vars.release();

        // pad unused buffer space
        while (lightDataIndex < numLights * 3) {
            lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex);
            lightDataIndex++;
        }
        return curIndex;
    }
Uploads the lights in the light list as two uniform arrays.
<p>
<code>uniform vec4 g_LightColor[numLights];</code> //
g_LightColor.rgb is the diffuse/specular color of the light. //
g_LightColor.a is the type of light, 0 = Directional, 1 = Point, 2 = Spot.
<code>uniform vec4 g_LightPosition[numLights];</code> //
g_LightPosition.xyz is the position of the light (for point lights)
// or the direction of the light (for directional lights). //
g_LightPosition.w is the inverse radius (1/r) of the light (for
attenuation) </p>

@param shader the Shader being used
@param g the Geometry being rendered
@param lightList the list of lights
@param numLights the number of lights to upload
@param rm to manage rendering
@param startIndex the starting index in the LightList
@param lastTexUnit the index of the most recently-used texture unit
@return the next starting index in the LightList
jme3-core/src/main/java/com/jme3/material/logic/SinglePassAndImageBasedLightingLogic.java