public static SunlightParameters LerpSunlightParameters(SunlightParameters from, SunlightParameters to, float weight)
        {
            var lerpSunlightParameters = new SunlightParameters();

            //Orientation
            lerpSunlightParameters.orientationParameters.lattitude = Mathf.Lerp(from.orientationParameters.lattitude, to.orientationParameters.lattitude, weight);
            lerpSunlightParameters.orientationParameters.yAxis     = Mathf.Lerp(from.orientationParameters.yAxis, to.orientationParameters.yAxis, weight);
            lerpSunlightParameters.orientationParameters.timeOfDay = Mathf.Lerp(from.orientationParameters.timeOfDay, to.orientationParameters.timeOfDay, weight);
            lerpSunlightParameters.orientationParameters.roll      = Mathf.Lerp(from.orientationParameters.roll, to.orientationParameters.roll, weight);

            lerpSunlightParameters.lightParameters = LightingUtilities.LerpLightParameters(from.lightParameters, to.lightParameters, weight);

            return(lerpSunlightParameters);
        }
示例#2
0
        public override void ProcessFrame(Playable handle, FrameData info, object playerData)
        {
            var count = handle.GetInputCount();

            var cineLight = lightTargetGO.GetComponent <CineLight>();

            GameObject attachmentTransform = playerData as GameObject;

            if (attachmentTransform != null)
            {
                attachmentPosition = attachmentTransform.transform.position;
                cineLight.SetAttachmentTransform(attachmentTransform, true);
                lightTargetGO.transform.position = attachmentPosition;
            }

            light = cineLight.GetComponentInChildren <Light>();

            globalUseShadowCaster = false;

            List <float>           inputWeights               = new List <float>();
            CineLightParameters    fromCineLightParameters    = new CineLightParameters();
            LightParameters        fromLightParameters        = new LightParameters();
            ShadowCasterParameters fromShadowCasterParameters = new ShadowCasterParameters();
            float fadeWeight = new float();

            CineLightParameters    toCineLightParameters    = new CineLightParameters();
            LightParameters        toLightParameters        = new LightParameters();
            ShadowCasterParameters toShadowCasterParameters = new ShadowCasterParameters();
            float crossFadeWeight = new float();

            //Short loop, feed data for most cases
            for (var i = 0; i < count; i++)
            {
                var inputHandle = handle.GetInput(i);
                var weight      = handle.GetInputWeight(i);

                if (inputHandle.IsValid() &&
                    inputHandle.GetPlayState() == PlayState.Playing &&
                    weight > 0)
                {
                    var data = ((ScriptPlayable <CineLightClipPlayable>)inputHandle).GetBehaviour();
                    if (data != null)
                    {
                        if (weight > 0)
                        {
                            inputWeights.Add(weight);
                            if (inputWeights.Count == 1)
                            {
                                fromCineLightParameters    = CineLightParameters.DeepCopy(data.cinelightParameters);
                                fromLightParameters        = LightParameters.DeepCopy(data.lightParameters);
                                fromShadowCasterParameters = ShadowCasterParameters.DeepCopy(data.shadowCasterParameters);
                                fadeWeight = weight;
                            }
                            if (inputWeights.Count == 2)
                            {
                                toCineLightParameters    = CineLightParameters.DeepCopy(data.cinelightParameters);
                                toLightParameters        = LightParameters.DeepCopy(data.lightParameters);
                                toShadowCasterParameters = ShadowCasterParameters.DeepCopy(data.shadowCasterParameters);
                                crossFadeWeight          = weight;
                            }
                            if (data.shadowCasterParameters.useShadowCaster == true)
                            {
                                globalUseShadowCaster = true;
                            }
                        }
                        if (inputWeights.Count > 2)
                        {
                            break;
                        }
                    }
                }
            }

            if (inputWeights.Count == 1)
            {
                isFading      = true;
                isCrossFading = false;
            }
            else if (inputWeights.Count == 2)
            {
                isFading      = false;
                isCrossFading = true;
            }
            else
            {
                isFading      = false;
                isCrossFading = false;
            }

            if (isFading == true)
            {
                DoSingleClip(fromCineLightParameters, fromLightParameters, fromShadowCasterParameters, fadeWeight);
            }

            if (isCrossFading == true)
            {
                DoCrossFadeSettings(fromCineLightParameters, fromLightParameters, fromShadowCasterParameters, toCineLightParameters, toLightParameters, toShadowCasterParameters, crossFadeWeight, cineLight);
            }

            if (isFading == false && isCrossFading == false)
            {
                DoLongLoop(cineLight, handle, count);
            }

            mixedLightParameters.fadeDistance       = 99999;
            mixedLightParameters.shadowFadeDistance = 99999;
            mixedLightParameters.mode = LightmapPresetBakeType.Realtime;

            LightingUtilities.ApplyLightParameters(light, mixedLightParameters);
            CineLightUtilities.ApplyCineLightParameters(cineLight, mixedCineLightParameters);

            if (globalUseShadowCaster && cineLight.shadowCasterGO == null)
            {
                cineLight.useShadowCaster = true;
                cineLight.ApplyShadowCaster();
            }

            if (cineLight.shadowCasterGO != null)
            {
                cineLight.shadowCasterGO.GetComponent <MeshRenderer>().enabled = mixedShadowCasterParameters.useShadowCaster;
                cineLight.shadowCasterGO.transform.localScale    = new Vector3(mixedShadowCasterParameters.shadowCasterSize.x, mixedShadowCasterParameters.shadowCasterSize.y, 1);
                cineLight.shadowCasterGO.transform.localPosition = new Vector3(mixedShadowCasterParameters.shadowCasterOffset.x, mixedShadowCasterParameters.shadowCasterOffset.y, -mixedShadowCasterParameters.shadowCasterDistance);
            }

            lightTargetGO.SetActive(mixedLightParameters.intensity == 0 ? false : true);
        }
示例#3
0
        //Not sure I want to support blending more than 2 lights
        private void DoLongLoop(CineLight cineLight, Playable handle, int count)
        {
            //Check if this ever happens
            Debug.Log("Blending more than 2 lights on the timeline");

            for (var i = 0; i < count; i++)
            {
                var inputHandle = handle.GetInput(i);
                var weight      = handle.GetInputWeight(i);

                if (inputHandle.IsValid() &&
                    inputHandle.GetPlayState() == PlayState.Playing &&
                    weight > 0)
                {
                    var data = ((ScriptPlayable <CineLightClipPlayable>)inputHandle).GetBehaviour();
                    if (data != null)
                    {
                        var lerpedLightParameters = new LightParameters();
                        lerpedLightParameters = LightingUtilities.LerpLightParameters(neutralLightParameters, data.lightParameters, isFading ? 1 : weight);

                        //Not using shortest path
                        mixedCineLightParameters.Yaw                 += Mathf.Lerp(neutralCineLightParameters.Yaw, data.cinelightParameters.Yaw, isFading ? 1 : weight);
                        mixedCineLightParameters.Pitch               += Mathf.Lerp(neutralCineLightParameters.Pitch, data.cinelightParameters.Pitch, isFading ? 1 : weight);
                        mixedCineLightParameters.Roll                += Mathf.Lerp(neutralCineLightParameters.Roll, data.cinelightParameters.Roll, isFading ? 1 : weight);
                        mixedCineLightParameters.distance            += Mathf.Lerp(neutralCineLightParameters.distance, data.cinelightParameters.distance, isFading ? 1 : weight);
                        mixedCineLightParameters.offset              += Vector3.Lerp(neutralCineLightParameters.offset, data.cinelightParameters.offset, isFading ? 1 : weight);
                        mixedCineLightParameters.linkToCameraRotation = data.cinelightParameters.linkToCameraRotation;
                        if (weight > 0.5f)
                        {
                            cineLight.drawGizmo = data.cinelightParameters.drawGizmo;
                        }
                        if (weight == 1 || isFading)
                        {
                            mixedLightParameters.shadows = data.lightParameters.shadows;
                        }

                        mixedLightParameters.intensity          += Mathf.Lerp(neutralLightParameters.intensity, data.lightParameters.intensity, weight);
                        mixedLightParameters.range              += lerpedLightParameters.range;
                        mixedLightParameters.colorFilter        += lerpedLightParameters.colorFilter;
                        mixedLightParameters.lightAngle         += lerpedLightParameters.lightAngle;
                        mixedLightParameters.cullingMask         = lerpedLightParameters.cullingMask;
                        mixedLightParameters.shadowQuality       = lerpedLightParameters.shadowQuality;
                        mixedLightParameters.affectDiffuse       = lerpedLightParameters.affectDiffuse;
                        mixedLightParameters.affectSpecular      = lerpedLightParameters.affectSpecular;
                        mixedLightParameters.normalBias         += lerpedLightParameters.normalBias;
                        mixedLightParameters.ShadowNearClip     += lerpedLightParameters.ShadowNearClip;
                        mixedLightParameters.viewBiasMin        += lerpedLightParameters.viewBiasMin;
                        mixedLightParameters.viewBiasScale      += lerpedLightParameters.viewBiasScale;
                        mixedLightParameters.shadowStrength     += lerpedLightParameters.shadowStrength;
                        mixedLightParameters.shadowResolution   += lerpedLightParameters.shadowResolution;
                        mixedLightParameters.innerSpotPercent   += lerpedLightParameters.innerSpotPercent;
                        mixedLightParameters.maxSmoothness      += lerpedLightParameters.maxSmoothness;
                        mixedLightParameters.fadeDistance       += lerpedLightParameters.fadeDistance;
                        mixedLightParameters.shadowFadeDistance += lerpedLightParameters.shadowFadeDistance;

                        mixedShadowCasterParameters.shadowCasterDistance += Mathf.Lerp(0, data.shadowCasterParameters.shadowCasterDistance, isFading ? 1 : weight);
                        mixedShadowCasterParameters.shadowCasterOffset   += Vector2.Lerp(Vector2.zero, data.shadowCasterParameters.shadowCasterOffset, isFading ? 1 : weight);
                        mixedShadowCasterParameters.shadowCasterSize     += Vector2.Lerp(Vector2.zero, data.shadowCasterParameters.shadowCasterSize, isFading ? 1 : weight);

                        if (weight > 0.5 || isFading)
                        {
                            mixedShadowCasterParameters.useShadowCaster = data.shadowCasterParameters.useShadowCaster;
                            mixedCineLightParameters.drawGizmo          = data.cinelightParameters.drawGizmo;
                            mixedLightParameters.lightCookie            = data.lightParameters.lightCookie;
                        }
                    }
                }
            }
        }