function _getDirectColor(matrixWorld, lightDirection, raycaster, scene, localPoint, face, bary, l, color, deltaDiv, lightDecay, lightCutoff) {
        var lightDistance, intersections, intersectBeforeLight, intensity;
        var visDebugThis;
        var deltaColor;
        var isVisible;
        var normalMatrix, normalizedSurfaceNormal;
        var calculatedSurfaceNormal = new THREE.Vector3();
        var attenuation;

        normalMatrix = (new THREE.Matrix3()).getNormalMatrix(matrixWorld);
        normalizedSurfaceNormal = face.normal.clone().applyMatrix3(normalMatrix);
        visDebugThis = (_config.debugVisualRT && _config.debugVisualIsSelectedMesh && Math.random() < _config.debugVisualProbabilityFilter);

        // hack to not waste more cpu power
        intensity = normalizedSurfaceNormal.dot(lightDirection) / (normalizedSurfaceNormal.length() * lightDirection.length());

        if (intensity > 0) {

            isVisible = true;

            lightDistance = lightDirection.length();
            raycaster.set(localPoint, lightDirection.normalize());

            intersections = raycasterFun.intersectObjects(raycaster, true);

            if (intersections.length > 0) {

                intersectBeforeLight = anyIntersectionBeforeLight(intersections, lightDistance);

                if (intersectBeforeLight) {

                    isVisible = false;

                }

            }

            if (isVisible) {

                // interpolation technique
                switch (_config.shading) {

                    case THREE.LightBaking.ShadingEnum.FLAT:
                    case THREE.LightBaking.ShadingEnum.FLATFAST:

                        calculatedSurfaceNormal.copy(normalizedSurfaceNormal);

                        break;

                    case THREE.LightBaking.ShadingEnum.PHONG:

                        calculatedSurfaceNormal = getPhongShading(face, _config.globalAmbient, bary.coords, lightDirection, __lights[l].color, normalMatrix);

                        break;

                }

                // illumination model
                switch (_config.illuminationModel) {

                    case THREE.LightBaking.IlluminationModelEnum.LAMBERT:

                        attenuation = calcLightAttenuation(lightDistance, lightCutoff, lightDecay);
                        deltaColor = getLambert(calculatedSurfaceNormal, lightDirection, _config.globalAmbient, __lights[l].color);
                        deltaColor.multiplyScalar(deltaDiv * attenuation);

                        break;

                }

                color.add(deltaColor);

            }


            if (visDebugThis) {

                visDebugThisFun(localPoint, color);

            }

        }

    }
/**
     * This method is used by the previous method to calculate the direct light color.
     * It was refactored in order to support multiple shadow samples.
     * @param matrixWorld
     * @param lightDirection
     * @param raycaster
     * @param scene
     * @param localPoint
     * @param face
     * @param bary
     * @param l
     * @param color
     * @param deltaDiv
     * @param lightDecay
     * @param lightCutoff
     */
This method is used by the previous method to calculate the direct light color.
It was refactored in order to support multiple shadow samples.
This method is used by the previous method to calculate the direct light color . It was refactored in order to support multiple shadow samples .
function _getDirectColor(matrixWorld, lightDirection, raycaster, scene, localPoint, face, bary, l, color, deltaDiv, lightDecay, lightCutoff) {
        var lightDistance, intersections, intersectBeforeLight, intensity;
        var visDebugThis;
        var deltaColor;
        var isVisible;
        var normalMatrix, normalizedSurfaceNormal;
        var calculatedSurfaceNormal = new THREE.Vector3();
        var attenuation;
        normalMatrix = (new THREE.Matrix3()).getNormalMatrix(matrixWorld);
        normalizedSurfaceNormal = face.normal.clone().applyMatrix3(normalMatrix);
        visDebugThis = (_config.debugVisualRT && _config.debugVisualIsSelectedMesh && Math.random() < _config.debugVisualProbabilityFilter);
        intensity = normalizedSurfaceNormal.dot(lightDirection) / (normalizedSurfaceNormal.length() * lightDirection.length());
        if (intensity > 0) {
            isVisible = true;
            lightDistance = lightDirection.length();
            raycaster.set(localPoint, lightDirection.normalize());
            intersections = raycasterFun.intersectObjects(raycaster, true);
            if (intersections.length > 0) {
                intersectBeforeLight = anyIntersectionBeforeLight(intersections, lightDistance);
                if (intersectBeforeLight) {
                    isVisible = false;
                }
            }
            if (isVisible) {
                switch (_config.shading) {
                    case THREE.LightBaking.ShadingEnum.FLAT:
                    case THREE.LightBaking.ShadingEnum.FLATFAST:
                        calculatedSurfaceNormal.copy(normalizedSurfaceNormal);
                        break;
                    case THREE.LightBaking.ShadingEnum.PHONG:
                        calculatedSurfaceNormal = getPhongShading(face, _config.globalAmbient, bary.coords, lightDirection, __lights[l].color, normalMatrix);
                        break;
                }
                switch (_config.illuminationModel) {
                    case THREE.LightBaking.IlluminationModelEnum.LAMBERT:
                        attenuation = calcLightAttenuation(lightDistance, lightCutoff, lightDecay);
                        deltaColor = getLambert(calculatedSurfaceNormal, lightDirection, _config.globalAmbient, __lights[l].color);
                        deltaColor.multiplyScalar(deltaDiv * attenuation);
                        break;
                }
                color.add(deltaColor);
            }
            if (visDebugThis) {
                visDebugThisFun(localPoint, color);
            }
        }
    }
function _getDirectColor ( matrixWorld , lightDirection , raycaster , scene , localPoint , face , bary , l , color , deltaDiv , lightDecay , lightCutoff ) { var lightDistance , intersections , intersectBeforeLight , intensity ; var visDebugThis ; var deltaColor ; var isVisible ; var normalMatrix , normalizedSurfaceNormal ; var calculatedSurfaceNormal = new THREE . Vector3 ( ) ; var attenuation ; normalMatrix = ( new THREE . Matrix3 ( ) ) . getNormalMatrix ( matrixWorld ) ; normalizedSurfaceNormal = face . normal . clone ( ) . applyMatrix3 ( normalMatrix ) ; visDebugThis = ( _config . debugVisualRT && _config . debugVisualIsSelectedMesh && Math . random ( ) < _config . debugVisualProbabilityFilter ) ; intensity = normalizedSurfaceNormal . dot ( lightDirection ) / ( normalizedSurfaceNormal . length ( ) * lightDirection . length ( ) ) ; if ( intensity > 0 ) { isVisible = true ; lightDistance = lightDirection . length ( ) ; raycaster . set ( localPoint , lightDirection . normalize ( ) ) ; intersections = raycasterFun . intersectObjects ( raycaster , true ) ; if ( intersections . length > 0 ) { intersectBeforeLight = anyIntersectionBeforeLight ( intersections , lightDistance ) ; if ( intersectBeforeLight ) { isVisible = false ; } } if ( isVisible ) { switch ( _config . shading ) { case THREE . LightBaking . ShadingEnum . FLAT : case THREE . LightBaking . ShadingEnum . FLATFAST : calculatedSurfaceNormal . copy ( normalizedSurfaceNormal ) ; break ; case THREE . LightBaking . ShadingEnum . PHONG : calculatedSurfaceNormal = getPhongShading ( face , _config . globalAmbient , bary . coords , lightDirection , __lights [ l ] . color , normalMatrix ) ; break ; } switch ( _config . illuminationModel ) { case THREE . LightBaking . IlluminationModelEnum . LAMBERT : attenuation = calcLightAttenuation ( lightDistance , lightCutoff , lightDecay ) ; deltaColor = getLambert ( calculatedSurfaceNormal , lightDirection , _config . globalAmbient , __lights [ l ] . color ) ; deltaColor . multiplyScalar ( deltaDiv * attenuation ) ; break ; } color . add ( deltaColor ) ; } if ( visDebugThis ) { visDebugThisFun ( localPoint , color ) ; } } }
This method is used by the previous method to calculate the direct light color.
This method is used by the previous method to calculate the direct light color .
// hack to not waste more cpu power // interpolation technique // illumination model