예제 #1
0
        public static void Mask(Light2D light, LightCollider2D id, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            int shapeCount = id.shapes.Count;

            for (int i = 0; i < shapeCount; i++)
            {
                LightColliderShape shape = id.shapes[i];

                List <MeshObject> meshObjects = shape.GetMeshes();

                if (meshObjects == null)
                {
                    return;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;

                Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position;
                GL.Color(LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency));

                GLExtended.DrawMeshPass(meshObjects, position, shape.transform.lossyScale, shape.transform2D.rotation);
            }
        }
예제 #2
0
            private static void DrawSprite(Pass pass)
            {
                int colliderCount = pass.layerMaskList.Count;

                if (colliderCount < 1)
                {
                    return;
                }

                for (int id = 0; id < colliderCount; id++)
                {
                    LightCollider2D collider = pass.layerMaskList[id];

                    switch (collider.mainShape.maskType)
                    {
                    case LightCollider2D.MaskType.Sprite:
                        SpriteRenderer2D.Mask(pass.light, collider, pass.materialWhite, pass.layer);
                        break;

                    case LightCollider2D.MaskType.BumpedSprite:

                        Material material = collider.bumpMapMode.SelectMaterial(pass.materialNormalMap_PixelToLight, pass.materialNormalMap_ObjectToLight);
                        SpriteRenderer2D.MaskNormalMap(pass.light, collider, material, pass.layer);

                        break;
                    }
                }
            }
    private void OnEnable()
    {
        lightCollider2D = target as LightCollider2D;

        InitProperties();

        Undo.undoRedoPerformed += RefreshAll;
    }
예제 #4
0
    private void OnEnable()
    {
        lightCollider = GetComponent <LightCollider2D>();

        if (lightCollider != null)
        {
            lightCollider.AddEvent(CollisionEvent);
        }
    }
예제 #5
0
    public LightCollision2D(bool _active)
    {
        light = null;

        collider = null;

        points = null;

        state = LightEventState.None;
    }
예제 #6
0
  static void CreateLightCollider()
  {
      GameObject newGameObject = new GameObject("Light Collider 2D");

      newGameObject.AddComponent <PolygonCollider2D>();
      LightCollider2D collider = newGameObject.AddComponent <LightCollider2D>();

      collider.maskType   = LightCollider2D.MaskType.Collider2D;
      collider.shadowType = LightCollider2D.ShadowType.Collider2D;
      collider.Initialize();

      newGameObject.transform.position = GetCameraPoint();
  }
예제 #7
0
        public static void Mask(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            Texture2D currentTexture = null;
            Color     currentColor   = Color.black;

            GL.Begin(GL.QUADS);

            foreach (LightColliderShape shape in id.shapes)
            {
                UnityEngine.SpriteRenderer spriteRenderer = shape.spriteShape.GetSpriteRenderer();

                Sprite sprite = shape.spriteShape.GetOriginalSprite();
                if (sprite == null || spriteRenderer == null)
                {
                    continue;
                }

                if (sprite.texture == null)
                {
                    continue;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;
                Color   color    = LayerSettingColor.Get(shape, position, layerSetting, id.maskEffect, id.maskTranslucency);

                if (currentTexture != sprite.texture || currentColor != color)
                {
                    currentTexture = sprite.texture;
                    currentColor   = color;

                    material.mainTexture = currentTexture;
                    material.color       = currentColor;

                    material.SetPass(0);
                }

                Rendering.Universal.Sprite.FullRect.DrawPass(id.spriteMeshObject, spriteRenderer, position, shape.transform2D.scale, shape.transform2D.rotation);
            }

            GL.End();

            material.mainTexture = null;
            material.color       = Color.white;
        }
예제 #8
0
        public void Add(LightCollider2D collider2D, float dist)
        {
            if (count < list.Length)
            {
                list[count].value = dist;

                list[count].type        = SortObject.Type.Collider;
                list[count].lightObject = (object)collider2D;

                count++;
            }
            else
            {
                Debug.LogError("Collider Depth Overhead!");
            }
        }
예제 #9
0
        public static void Draw(Light2D light, LightCollider2D id)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            light.AddCollider(id);

            foreach (LightColliderShape shape in id.shapes)
            {
                List <Polygon2> polygons = shape.GetPolygonsWorld();

                ShadowEngine.Draw(polygons, shape.shadowDistance, id.shadowTranslucency);
            }
        }
예제 #10
0
        public static void Mask(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            foreach (LightColliderShape shape in id.shapes)
            {
                SkinnedMeshRenderer skinnedMeshRenderer = shape.skinnedMeshShape.GetSkinnedMeshRenderer();

                if (skinnedMeshRenderer == null)
                {
                    return;
                }

                List <MeshObject> meshObject = shape.GetMeshes();

                if (meshObject == null)
                {
                    return;
                }

                if (skinnedMeshRenderer.sharedMaterial != null)
                {
                    material.mainTexture = skinnedMeshRenderer.sharedMaterial.mainTexture;
                }
                else
                {
                    material.mainTexture = null;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;

                Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position;
                material.color = LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency);

                material.SetPass(0);

                GLExtended.DrawMesh(meshObject, position, id.mainShape.transform2D.scale, shape.transform2D.rotation);

                material.mainTexture = null;
            }
        }
예제 #11
0
        public static void GenerateEffectLayers()
        {
            int layerID = (int)ShadowEngine.effectLayer;

            foreach (LightCollider2D c in LightCollider2D.GetShadowList((layerID)))
            {
                List <Polygon2> polygons = c.mainShape.GetPolygonsWorld();

                if (polygons == null)
                {
                    continue;
                }

                if (c.InLight(light))
                {
                    effectPolygons.Add(polygons);
                }
            }
        }
예제 #12
0
            private static void DrawCollider(Pass pass)
            {
                int colliderCount = pass.layerMaskList.Count;

                if (colliderCount < 1)
                {
                    return;
                }

                for (int id = 0; id < colliderCount; id++)
                {
                    LightCollider2D collider = pass.layerMaskList[id];

                    switch (collider.mainShape.maskType)
                    {
                    case LightCollider2D.MaskType.SpritePhysicsShape:
                    case LightCollider2D.MaskType.CompositeCollider2D:
                    case LightCollider2D.MaskType.Collider2D:
                    case LightCollider2D.MaskType.Collider3D:
                        Shape.Mask(pass.light, collider, pass.layer);
                        break;
                    }
                }
            }
예제 #13
0
            private static void DrawCollider(Pass pass)
            {
                int colliderCount = pass.layerShadowList.Count;

                if (colliderCount < 1)
                {
                    return;
                }

                for (int id = 0; id < colliderCount; id++)
                {
                    LightCollider2D collider = pass.layerShadowList[id];

                    if (collider.ShadowDisabled())
                    {
                        continue;
                    }

                    // Shadow Projection Sprite
                    ShadowEngine.spriteProjection = collider.mainShape.spriteShape.GetOriginalSprite();

                    Shadow.Shape.Draw(pass.light, collider);
                }
            }
예제 #14
0
    override public void OnInspectorGUI()
    {
        if (lightCollider2D == null)
        {
            return;
        }

        // Warning
        // Debug.Log(lightCollider2D.mainShape.spriteShape.GetOriginalSprite().packingMode);

        // Shadow Properties

        EditorGUILayout.PropertyField(shadowType, new GUIContent("Shadow Type"));

        EditorGUI.BeginDisabledGroup(shadowType.intValue == (int)LightCollider2D.ShadowType.None);

        shadowLayer.intValue = EditorGUILayout.Popup("Shadow Layer (Light)", shadowLayer.intValue, Lighting2D.Profile.layers.lightLayers.GetNames());

        string shadowDistanceName = "Shadow Distance";

        if (shadowDistance.floatValue == 0)
        {
            shadowDistanceName = "Shadow Distance (infinite)";
        }

        EditorGUILayout.PropertyField(shadowDistance, new GUIContent(shadowDistanceName));

        EditorGUILayout.PropertyField(shadowTranslucency, new GUIContent("Shadow Translucency"));

        EditorGUI.EndDisabledGroup();

        EditorGUILayout.Space();

        // Mask Properties

        EditorGUILayout.PropertyField(maskType, new GUIContent("Mask Type"));

        EditorGUI.BeginDisabledGroup(maskType.intValue == (int)LightCollider2D.MaskType.None);

        maskLayer.intValue = EditorGUILayout.Popup("Mask Layer (Light)", maskLayer.intValue, Lighting2D.Profile.layers.lightLayers.GetNames());

        EditorGUILayout.PropertyField(maskEffect, new GUIContent("Mask Effect"));

        EditorGUILayout.PropertyField(maskPivot, new GUIContent("Mask Pivot"));

        EditorGUILayout.PropertyField(maskTranslucency, new GUIContent("Mask Translucency"));

        EditorGUI.EndDisabledGroup();

        if (lightCollider2D.maskType == LightCollider2D.MaskType.BumpedSprite || lightCollider2D.maskType == LightCollider2D.MaskType.BumpedMeshRenderer)
        {
            GUIBumpMapMode.Draw(serializedObject, lightCollider2D);
        }

        EditorGUILayout.Space();

        // Apply to Children

        EditorGUILayout.PropertyField(applyToChildren, new GUIContent("Apply to Children"));

        serializedObject.ApplyModifiedProperties();


        EditorGUILayout.Space();

        // Update

        if (GUILayout.Button("Update"))
        {
            SpriteExtension.PhysicsShapeManager.Clear();

            foreach (Object target in targets)
            {
                LightCollider2D lightCollider2D = target as LightCollider2D;
                lightCollider2D.Initialize();
            }

            LightingManager2D.ForceUpdate();
        }

        if (GUI.changed)
        {
            foreach (Object target in targets)
            {
                LightCollider2D lightCollider2D = target as LightCollider2D;
                lightCollider2D.Initialize();
                lightCollider2D.UpdateNearbyLights();

                if (EditorApplication.isPlaying == false)
                {
                    EditorUtility.SetDirty(target);
                }
            }

            if (EditorApplication.isPlaying == false)
            {
                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
            }

            LightingManager2D.ForceUpdate();
        }
    }
예제 #15
0
        public static void MaskNormalMap(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            Texture normalTexture = id.bumpMapMode.GetBumpTexture();

            if (normalTexture == null)
            {
                return;
            }

            float rotation;

            material.SetTexture("_Bump", normalTexture);

            foreach (LightColliderShape shape in id.shapes)
            {
                MeshRenderer meshRenderer = id.mainShape.meshShape.GetMeshRenderer();

                if (meshRenderer == null)
                {
                    return;
                }

                List <MeshObject> meshObjects = id.mainShape.GetMeshes();

                if (meshObjects == null)
                {
                    return;
                }

                if (meshRenderer.sharedMaterial != null)
                {
                    material.mainTexture = meshRenderer.sharedMaterial.mainTexture;
                }
                else
                {
                    material.mainTexture = null;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;

                Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position;
                material.color = LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency);

                float color = material.color.r;

                switch (id.bumpMapMode.type)
                {
                case NormalMapType.ObjectToLight:
                    rotation  = Mathf.Atan2(light.transform2D.position.y - shape.transform2D.position.y, light.transform2D.position.x - shape.transform2D.position.x);
                    rotation -= Mathf.Deg2Rad * (shape.transform2D.rotation);

                    material.SetFloat("_LightRX", Mathf.Cos(rotation) * 2);
                    material.SetFloat("_LightRY", Mathf.Sin(rotation) * 2);
                    material.SetFloat("_LightColor", color);

                    break;

                case NormalMapType.PixelToLight:
                    material.SetFloat("_LightColor", color);

                    rotation = shape.transform2D.rotation * Mathf.Deg2Rad;

                    Vector2 sc = shape.transform2D.scale;
                    sc = sc.normalized;

                    material.SetFloat("_LightX", Mathf.Cos(rotation) * sc.x);
                    material.SetFloat("_LightY", Mathf.Cos(rotation) * sc.y);

                    material.SetFloat("_Depth", id.bumpMapMode.depth);

                    if (id.bumpMapMode.invertX)
                    {
                        material.SetFloat("_InvertX", -1);
                    }
                    else
                    {
                        material.SetFloat("_InvertX", 1);
                    }

                    if (id.bumpMapMode.invertY)
                    {
                        material.SetFloat("_InvertY", -1);
                    }
                    else
                    {
                        material.SetFloat("_InvertY", 1);
                    }

                    break;
                }

                material.SetPass(0);

                GLExtended.DrawMesh(meshObjects, position, id.mainShape.transform2D.scale, shape.transform2D.rotation);

                material.mainTexture = null;
            }
        }
예제 #16
0
        public void Update(Light2D light, EventPreset eventPreset)
        {
            if (light == null)
            {
                return;
            }

            listenersInLight.Clear();

            // Get Event Receivers
            LightCollider.GetCollisions(listenersInLight, light);

            // Remove Event Receiver Vertices with Shadows
            LightCollider.RemoveHiddenCollisions(listenersInLight, light, eventPreset);
            LightTilemap.RemoveHiddenCollisions(listenersInLight, light, eventPreset);

            if (listenersInLight.Count < 1)
            {
                for (int i = 0; i < listenersCache.Count; i++)
                {
                    LightCollider2D collider = listenersCache[i];

                    LightCollision2D collision = new LightCollision2D();
                    collision.light    = light;
                    collision.collider = collider;
                    collision.points   = null;
                    collision.state    = LightEventState.OnCollisionExit;

                    collider.CollisionEvent(collision);
                }

                listenersCache.Clear();

                return;
            }

            listenersInLightColliders.Clear();

            foreach (LightCollision2D collision in listenersInLight)
            {
                listenersInLightColliders.Add(collision.collider);
            }

            for (int i = 0; i < listenersCache.Count; i++)
            {
                LightCollider2D collider = listenersCache[i];
                if (listenersInLightColliders.Contains(collider) == false)
                {
                    LightCollision2D collision = new LightCollision2D();
                    collision.light    = light;
                    collision.collider = collider;
                    collision.points   = null;
                    collision.state    = LightEventState.OnCollisionExit;

                    collider.CollisionEvent(collision);

                    listenersCache.Remove(collider);
                }
            }

            for (int i = 0; i < listenersInLight.Count; i++)
            {
                LightCollision2D collision = listenersInLight[i];

                if (listenersCache.Contains(collision.collider))
                {
                    collision.state = LightEventState.OnCollision;
                }
                else
                {
                    collision.state = LightEventState.OnCollisionEnter;
                    listenersCache.Add(collision.collider);
                }

                collision.collider.CollisionEvent(collision);
            }
        }
예제 #17
0
        private static void DrawCollider(Pass pass)
        {
            LightCollider2D collider = (LightCollider2D)pass.sortPass.sortObject.lightObject;

            if (collider.shadowLayer == pass.layerID && pass.drawShadows)
            {
                if (collider.ShadowDisabled() == false)
                {
                    ShadowEngine.GetMaterial().SetPass(0);

                    GL.Begin(GL.TRIANGLES);

                    Shadow.Shape.Draw(pass.light, collider);

                    GL.End();
                }
            }

            // Masking
            if (collider.maskLayer == pass.layerID && pass.drawMask)
            {
                pass.materialWhite.color = Color.white;

                switch (collider.mainShape.maskType)
                {
                case LightCollider2D.MaskType.SpritePhysicsShape:
                case LightCollider2D.MaskType.Collider2D:
                case LightCollider2D.MaskType.Collider3D:
                case LightCollider2D.MaskType.CompositeCollider2D:

                    pass.materialWhite.SetPass(0);
                    GL.Begin(GL.TRIANGLES);
                    Shape.Mask(pass.light, collider, pass.layer);
                    GL.End();

                    break;

                case LightCollider2D.MaskType.Sprite:

                    SpriteRenderer2D.Mask(pass.light, collider, pass.materialWhite, pass.layer);

                    break;

                case LightCollider2D.MaskType.BumpedSprite:

                    Material material = collider.bumpMapMode.SelectMaterial(pass.materialNormalMap_PixelToLight, pass.materialNormalMap_ObjectToLight);
                    SpriteRenderer2D.MaskNormalMap(pass.light, collider, material, pass.layer);

                    break;

                case LightCollider2D.MaskType.MeshRenderer:

                    pass.materialWhite.SetPass(0);
                    GL.Begin(GL.TRIANGLES);
                    Mesh.Mask(pass.light, collider, pass.materialWhite, pass.layer);
                    GL.End();

                    break;

                case LightCollider2D.MaskType.BumpedMeshRenderer:

                    Material material2 = collider.bumpMapMode.SelectMaterial(pass.materialNormalMap_PixelToLight, pass.materialNormalMap_ObjectToLight);
                    material2.SetPass(0);
                    GL.Begin(GL.TRIANGLES);
                    Mesh.MaskNormalMap(pass.light, collider, material2, pass.layer);
                    GL.End();

                    break;

                case LightCollider2D.MaskType.SkinnedMeshRenderer:

                    pass.materialWhite.SetPass(0);
                    GL.Begin(GL.TRIANGLES);
                    SkinnedMesh.Mask(pass.light, collider, pass.materialWhite, pass.layer);
                    GL.End();

                    break;
                }
            }
        }
예제 #18
0
 void RefreshAll()
 {
     LightCollider2D.ForceUpdateAll();
 }
예제 #19
0
        void AddColliders()
        {
            for (int id = 0; id < pass.colliderList.Count; id++)
            {
                LightCollider2D collider = pass.colliderList[id];

                if (collider.shadowLayer != pass.layerID && collider.maskLayer != pass.layerID)
                {
                    continue;
                }

                if (collider.InLight(pass.light) == false)
                {
                    continue;
                }

                switch (pass.layer.sorting)
                {
                case LightLayerSorting.Isometric:
                    Vector2 lightPos    = pass.light.transform.position;
                    Vector2 colliderPos = collider.mainShape.GetPivotPoint();
                    Vector2 position    = colliderPos - lightPos;

                    float x = position.y + position.x / 2;
                    float y = -(position.x / 2 - position.y);

                    if (x > 0)
                    {
                        sortList.Add(collider, x);
                    }
                    else
                    {
                        sortList.Add(collider, -x + 10000);
                    }

                    break;

                case LightLayerSorting.SortingLayerAndOrder:
                    sortList.Add(collider, collider.mainShape.GetSortingOrder() + collider.mainShape.GetSortingLayer() * 1000);
                    break;

                case LightLayerSorting.ZAxisLower:
                    if (pass.layer.sortingIgnore == LightLayerSortingIgnore.IgnoreAbove)
                    {
                        if (collider.transform.position.z >= pass.light.transform.position.z)
                        {
                            sortList.Add(collider, -collider.transform.position.z);
                        }
                    }
                    else
                    {
                        sortList.Add(collider, -collider.transform.position.z);
                    }

                    break;

                case LightLayerSorting.ZAxisHigher:
                    if (pass.layer.sortingIgnore == LightLayerSortingIgnore.IgnoreAbove)
                    {
                        if (collider.transform.position.z <= pass.light.transform.position.z)
                        {
                            sortList.Add(collider, collider.transform.position.z);
                        }
                    }
                    else
                    {
                        sortList.Add(collider, collider.transform.position.z);
                    }

                    break;

                case LightLayerSorting.YAxisLower:
                    sortList.Add(collider, -collider.transform.position.y);
                    break;

                case LightLayerSorting.YAxisHigher:
                    sortList.Add(collider, collider.transform.position.y);
                    break;

                case LightLayerSorting.DistanceToLight:
                    sortList.Add(collider, -Vector2.Distance(collider.transform.position, pass.light.transform.position));
                    break;

                case LightLayerSorting.YDistanceToLight:
                    sortList.Add(collider, -Mathf.Abs(collider.transform.position.y - pass.light.transform.position.y));
                    break;
                }
            }
        }
예제 #20
0
        public static void MaskNormalMap(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            Texture normalTexture = id.bumpMapMode.GetBumpTexture();

            if (normalTexture == null)
            {
                return;
            }

            float rotation;

            material.SetTexture("_Bump", normalTexture);

            foreach (LightColliderShape shape in id.shapes)
            {
                UnityEngine.SpriteRenderer spriteRenderer = shape.spriteShape.GetSpriteRenderer();

                if (spriteRenderer == null)
                {
                    continue;
                }

                Sprite sprite = shape.spriteShape.GetOriginalSprite();
                if (sprite == null)
                {
                    continue;
                }

                if (sprite.texture == null)
                {
                    continue;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;

                material.mainTexture = sprite.texture;
                material.color       = LayerSettingColor.Get(position, layerSetting, id.maskEffect, id.maskTranslucency);

                float color = material.color.r;

                switch (id.bumpMapMode.type)
                {
                case NormalMapType.ObjectToLight:
                    rotation  = Mathf.Atan2(light.transform2D.position.y - shape.transform2D.position.y, light.transform2D.position.x - shape.transform2D.position.x);
                    rotation -= Mathf.Deg2Rad * (shape.transform2D.rotation);

                    material.SetFloat("_LightRX", Mathf.Cos(rotation) * 2);
                    material.SetFloat("_LightRY", Mathf.Sin(rotation) * 2);
                    material.SetFloat("_LightColor", color);

                    break;

                case NormalMapType.PixelToLight:
                    material.SetFloat("_LightColor", color);

                    rotation = shape.transform2D.rotation * Mathf.Deg2Rad;

                    Vector2 sc = shape.transform2D.scale;
                    sc = sc.normalized;

                    material.SetFloat("_LightX", Mathf.Cos(rotation) * sc.x);
                    material.SetFloat("_LightY", Mathf.Cos(rotation) * sc.y);

                    material.SetFloat("_Depth", id.bumpMapMode.depth);

                    if (id.bumpMapMode.invertX)
                    {
                        material.SetFloat("_InvertX", -1);
                    }
                    else
                    {
                        material.SetFloat("_InvertX", 1);
                    }

                    if (id.bumpMapMode.invertY)
                    {
                        material.SetFloat("_InvertY", -1);
                    }
                    else
                    {
                        material.SetFloat("_InvertY", 1);
                    }

                    break;
                }

                Rendering.Universal.Sprite.FullRect.Draw(id.spriteMeshObject, material, spriteRenderer, position, shape.transform2D.scale, shape.transform2D.rotation);
            }
        }
예제 #21
0
        public bool Setup(Light2D light, LayerSetting setLayer)
        {
            // Layer ID
            layerID = setLayer.GetLayerID();
            if (layerID < 0)
            {
                return(false);
            }

            layer = setLayer;

            // Calculation Setup
            this.light       = light;
            lightSizeSquared = Mathf.Sqrt(light.size * light.size + light.size * light.size);

            colliderList = LightCollider2D.List;

            layerShadowList = LightCollider2D.GetShadowList(layerID);
            layerMaskList   = LightCollider2D.GetMaskList(layerID);

            #if UNITY_2017_4_OR_NEWER
            tilemapList = LightTilemapCollider2D.GetList();
            #endif

            // Draw Mask & Shadows?
            drawMask    = (layer.type != LightLayerType.ShadowOnly);
            drawShadows = (layer.type != LightLayerType.MaskOnly);

            // Materials
            materialWhite = Lighting2D.materials.GetMask();

            if (materialWhite != null)
            {
                materialWhite.SetFloat("translucency", (light.maskTranslucency * 100) / light.size);

                materialWhite.SetFloat("intensity", light.maskTranslucencyIntensity);

                if (light.maskTranslucency > 0)
                {
                    if (light.Buffer.collisionTexture != null)
                    {
                        materialWhite.SetTexture("_SecTex", light.Buffer.collisionTexture.renderTexture);

                        materialWhite.SetFloat("textureSize", light.GetTextureSize().x);
                    }
                }
            }

            materialNormalMap_PixelToLight = Lighting2D.materials.GetNormalMapSpritePixelToLight();

            if (materialNormalMap_PixelToLight != null)
            {
                materialNormalMap_PixelToLight.SetFloat("translucency", (light.maskTranslucency * 100) / light.size);

                materialNormalMap_PixelToLight.SetFloat("intensity", light.maskTranslucencyIntensity);

                if (light.maskTranslucency > 0)
                {
                    if (light.Buffer.collisionTexture != null)
                    {
                        materialNormalMap_PixelToLight.SetTexture("_SecTex", light.Buffer.collisionTexture.renderTexture);

                        materialNormalMap_PixelToLight.SetFloat("textureSize", light.GetTextureSize().x);
                    }
                }
            }

            materialNormalMap_ObjectToLight = Lighting2D.materials.GetNormalMapSpriteObjectToLight();

            if (materialNormalMap_ObjectToLight != null)
            {
                materialNormalMap_ObjectToLight.SetFloat("translucency", (light.maskTranslucency * 100) / light.size);

                if (light.maskTranslucency > 0)
                {
                    if (light.Buffer.collisionTexture != null)
                    {
                        materialNormalMap_ObjectToLight.SetTexture("_SecTex", light.Buffer.collisionTexture.renderTexture);

                        materialNormalMap_ObjectToLight.SetFloat("textureSize", light.GetTextureSize().x);
                    }
                }
            }


            materialNormalMap_PixelToLight.SetFloat("_LightSize", light.size);
            materialNormalMap_PixelToLight.SetFloat("_LightIntensity", light.bumpMap.intensity);
            materialNormalMap_PixelToLight.SetFloat("_LightZ", light.bumpMap.depth);

            materialNormalMap_ObjectToLight.SetFloat("_LightSize", light.size);
            materialNormalMap_ObjectToLight.SetFloat("_LightIntensity", light.bumpMap.intensity);
            materialNormalMap_ObjectToLight.SetFloat("_LightZ", light.bumpMap.depth);

            sortPass.pass = this;

            // Sort
            sortPass.Clear();

            return(true);
        }
예제 #22
0
        public static List <LightCollision2D> RemoveHiddenCollisions(List <LightCollision2D> collisions, Light2D light, EventPreset eventPreset)
        {
            float  lightSize = Mathf.Sqrt(light.size * light.size + light.size * light.size);
            double rotLeft, rotRight;

            Polygon2D testPolygon = GetPolygon();

            Vector2 lightPosition = -light.transform.position;
            int     next;

            for (int iid = 0; iid < eventPreset.layerSetting.list.Length; iid++)
            {
                int layerId = eventPreset.layerSetting.list[iid].layerID;

                List <LightCollider2D> colliderList = LightCollider2D.GetShadowList(layerId);

                foreach (LightCollider2D id in colliderList)
                {
                    if (id.InLight(light) == false)
                    {
                        continue;
                    }

                    if (id.mainShape.shadowType == LightCollider2D.ShadowType.None)
                    {
                        continue;
                    }

                    List <Polygon2> polygons = id.mainShape.GetPolygonsWorld();

                    if (polygons.Count < 1)
                    {
                        continue;
                    }

                    removePointsColliding.Clear();
                    removeCollisions.Clear();

                    for (int i = 0; i < polygons.Count; i++)
                    {
                        Vector2[] pointsList  = polygons[i].points;
                        int       pointsCount = pointsList.Length;

                        for (int x = 0; x < pointsCount; x++)
                        {
                            next = (x + 1) % pointsCount;

                            Vector2 left  = pointsList[x];
                            Vector2 right = pointsList[next];

                            edgeLeft.x = left.x + lightPosition.x;
                            edgeLeft.y = left.y + lightPosition.y;

                            edgeRight.x = right.x + lightPosition.x;
                            edgeRight.y = right.y + lightPosition.y;

                            rotLeft  = System.Math.Atan2(edgeLeft.y, edgeLeft.x);
                            rotRight = System.Math.Atan2(edgeRight.y, edgeRight.x);

                            projectionLeft.x = edgeLeft.x + System.Math.Cos(rotLeft) * lightSize;
                            projectionLeft.y = edgeLeft.y + System.Math.Sin(rotLeft) * lightSize;

                            projectionRight.x = edgeRight.x + System.Math.Cos(rotRight) * lightSize;
                            projectionRight.y = edgeRight.y + System.Math.Sin(rotRight) * lightSize;

                            testPolygon.pointsList[0].x = projectionLeft.x;
                            testPolygon.pointsList[0].y = projectionLeft.y;

                            testPolygon.pointsList[1].x = projectionRight.x;
                            testPolygon.pointsList[1].y = projectionRight.y;

                            testPolygon.pointsList[2].x = edgeRight.x;
                            testPolygon.pointsList[2].y = edgeRight.y;

                            testPolygon.pointsList[3].x = edgeLeft.x;
                            testPolygon.pointsList[3].y = edgeLeft.y;

                            foreach (LightCollision2D col in collisions)
                            {
                                if (col.collider == id)
                                {
                                    continue;
                                }

                                foreach (Vector2 point in col.points)
                                {
                                    if (testPolygon.PointInPoly(point))
                                    {
                                        removePointsColliding.Add(point);
                                    }
                                }

                                foreach (Vector2 point in removePointsColliding)
                                {
                                    col.points.Remove(point);
                                }

                                removePointsColliding.Clear();

                                if (col.points.Count < 1)
                                {
                                    removeCollisions.Add(col);
                                }
                            }

                            foreach (LightCollision2D col in removeCollisions)
                            {
                                collisions.Remove(col);
                            }

                            removeCollisions.Clear();
                        }
                    }
                }
            }

            return(collisions);
        }