Exemplo n.º 1
0
        public static float GetInterpolatedOcclusion(Vector3 position)
        {
            Profiler.BeginSample("Ambient Probes: GetInterpolatedOcclusion");
            ProbeInterpolation data = GetInterpolationData(position);

            if (!data.group)
            {
                return(1);
            }

            //If one of the other is null
            if (data.dest == null && data.source != null)
            {
                return(data.source.occlusion);
            }
            if (data.source == null && data.dest != null)
            {
                return(data.dest.occlusion);
            }
            float occlusion = Mathf.Lerp(data.dest.occlusion, data.source.occlusion, data.dist01);

            Profiler.EndSample();

            return(occlusion);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return a struct with the nearest and 2nd nearest probe if the position is within any group's bounds
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public static ProbeInterpolation GetInterpolationData(Vector3 position)
        {
            ProbeInterpolation data = new ProbeInterpolation();

            AmbientProbeGroup nearestGroup = GetNearestGroup(position);

            if (!nearestGroup)
            {
                return(data);
            }

            data.group = nearestGroup;

            data.source = GetNearestProbe(nearestGroup, position);
            data.dest   = GetNearestProbe(nearestGroup, position, data.source);

            //Distance value can exceed 1, but this is fine, the lerp will still return the destination
            if (data.source != null && data.dest != null)
            {
                data.dist01 = (data.dest.position - position).magnitude / (data.dest.position - data.source.position).magnitude;
            }
            data.dist01 = Mathf.Abs(data.dist01);

            return(data);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Front end function to get ambient color at any position in world-space
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public static Color GetInterpolatedColor(Vector3 position)
        {
            Profiler.BeginSample("Ambient Probes: GetInterpolatedColor");
            ProbeInterpolation data = GetInterpolationData(position);

            //if (!data.group) return RenderSettings.ambientSkyColor;
            if (!data.group)
            {
                return(Color.white);             //don't use the ambient sky color when multiplying to indirect light color. it'll ended up similar to multiplying itself making it more darker.
            }
            //If one of the other is null
            if (data.dest == null && data.source != null)
            {
                return(data.source.color * data.source.occlusion);
            }
            if (data.source == null && data.dest != null)
            {
                return(data.dest.color * data.dest.occlusion);
            }
            //if (data.source == null && data.dest == null) return RenderSettings.ambientSkyColor;
            if (data.source == null && data.dest == null)
            {
                return(Color.white);                                          //don't use the ambient sky color when multiplying to indirect light color. it'll ended up similar to multiplying itself making it more darker.
            }
            Color src = data.source.overriden ? data.source.color : data.group.color;

            if (data.source.global)
            {
                src = RenderSettings.ambientSkyColor;
            }

            Color dst = data.dest.overriden ? data.dest.color : data.group.color;

            if (data.dest.global)
            {
                dst = RenderSettings.ambientSkyColor;
            }

            //Lerp
            Color ambient = Color.Lerp(dst, src, data.dist01);

            //float occlusion = Mathf.Lerp(data.dest.occlusion, data.source.occlusion, data.dist01);

            Profiler.EndSample();

            //return ambient * occlusion;
            return(ambient);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Front end function to get ambient color at any position in world-space
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public static Color GetInterpolatedColor(Vector3 position)
        {
            Profiler.BeginSample("Ambient Probes: GetInterpolatedColor");
            ProbeInterpolation data = GetInterpolationData(position);

            if (!data.group)
            {
                return(RenderSettings.ambientSkyColor);
            }

            //If one of the other is null
            if (data.dest == null && data.source != null)
            {
                return(data.source.color * data.source.occlusion);
            }
            if (data.source == null && data.dest != null)
            {
                return(data.dest.color * data.dest.occlusion);
            }
            if (data.source == null && data.dest == null)
            {
                return(RenderSettings.ambientSkyColor);
            }

            Color src = data.source.overriden ? data.source.color : data.group.color;

            if (data.source.global)
            {
                src = RenderSettings.ambientSkyColor;
            }

            Color dst = data.dest.overriden ? data.dest.color : data.group.color;

            if (data.dest.global)
            {
                dst = RenderSettings.ambientSkyColor;
            }

            //Lerp
            Color ambient   = Color.Lerp(dst, src, data.dist01);
            float occlusion = Mathf.Lerp(data.dest.occlusion, data.source.occlusion, data.dist01);

            Profiler.EndSample();

            return(ambient * occlusion);
        }