예제 #1
0
        public void Resize(int width, int height)
        {
            Width  = width;
            Height = height;

            Lights       = new LightSet[width, height];
            EndingLights = new LightSet[width, height];
            Cells        = new Cell[width, height];
        }
    LightSet CalcLight(LightSet lightSet)
    {
        Light light  = lightSet.light;
        float inView = 1.1f;
        float dist;

        if (!light.isActiveAndEnabled)
        {
            lightSet.atten = 0f;
            return(lightSet);
        }

        switch (light.type)
        {
        case LightType.Directional:
            lightSet.dir   = light.transform.forward * -1f;
            inView         = TestInView(lightSet.dir, 100f);
            lightSet.color = light.color * light.intensity;
            lightSet.atten = 1f;
            break;

        case LightType.Point:
            lightSet.dir   = light.transform.position - posAbs;
            dist           = Mathf.Clamp01(lightSet.dir.magnitude / light.range);
            inView         = TestInView(lightSet.dir, lightSet.dir.magnitude);
            lightSet.atten = CalcAttenuation(dist);
            lightSet.color = light.color * lightSet.atten * light.intensity * 0.1f;
            break;

        case LightType.Spot:
            lightSet.dir = light.transform.position - posAbs;
            dist         = Mathf.Clamp01(lightSet.dir.magnitude / light.range);
            float angle   = Vector3.Angle(light.transform.forward * -1f, lightSet.dir.normalized);
            float inFront = Mathf.Lerp(0f, 1f, (light.spotAngle - angle * 2f) / lightSet.dir.magnitude);         // More edge fade when far away from light source
            inView         = inFront * TestInView(lightSet.dir, lightSet.dir.magnitude);
            lightSet.atten = CalcAttenuation(dist);
            lightSet.color = light.color * lightSet.atten * light.intensity * 0.05f;
            break;

        default:
            Debug.Log("Lighting type '" + light.type + "' not supported by Awesome Toon Helper (" + light.name + ").");
            lightSet.atten = 0f;
            break;
        }

        // Slowly fade lights on and off
        float fadeSpeed = (Application.isEditor && !Application.isPlaying)
                ? raycastFadeSpeed / 60f
                : raycastFadeSpeed * Time.deltaTime;

        lightSet.inView = Mathf.Lerp(lightSet.inView, inView, fadeSpeed);
        lightSet.color *= Mathf.Clamp01(lightSet.inView);

        return(lightSet);
    }
예제 #3
0
파일: Scene.cs 프로젝트: kgfathur/nzy3d-api
 public Scene(Graph graph)
 {
     _graph   = graph;
     _lighSet = new LightSet();
     _views   = new List <View>();
 }
예제 #4
0
파일: Scene.cs 프로젝트: kgfathur/nzy3d-api
 public Scene(bool graphsort)
 {
     _graph   = new Graph(this, Factories.OrderingStrategyFactory.getInstance(), graphsort);
     _lighSet = new LightSet();
     _views   = new List <View>();
 }
예제 #5
0
        public void Refresh()
        {
            lazyCells.Clear();
            Lights       = new LightSet[Width, Height];
            EndingLights = new LightSet[Width, Height];
            var queue = new Queue <Light>();

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Cells[x, y]?.Reset();
                    if (Cells[x, y] is LightSource lightSource)
                    {
                        lazyCells.Add(lightSource);
                    }
                }
            }

            while (lazyCells.Count > 0)
            {
                foreach (var cell in lazyCells)
                {
                    var lights = cell.Apply(null);
                    if (lights != null)
                    {
                        foreach (var light in lights)
                        {
                            queue.Enqueue(light);
                        }
                    }
                }
                lazyCells.Clear();

                while (queue.Count > 0)
                {
                    var light     = queue.Dequeue();
                    var newLights = light.Handle(this);
                    if (newLights != null)
                    {
                        foreach (var newLight in newLights)
                        {
                            queue.Enqueue(newLight);
                        }
                    }
                }
            }

            bool success = true;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (Cells[x, y] is TargetCell target)
                    {
                        target.SetActivated(Lights[x, y], EndingLights[x, y]);
                        if (!target.Success)
                        {
                            success = false;
                        }
                    }
                }
            }
            MissionComplete = success;
            RefreshCompleted?.Invoke(this, success);
        }