Exemplo n.º 1
0
    static void DrawWithAtlas(LightingBuffer2D buffer, int layer)
    {
        manager.materials.GetAtlasMaterial().SetPass(0);
        GL.Begin(GL.TRIANGLES);

        Material materialWhite = manager.materials.GetWhiteSprite();
        Material materialBlack = manager.materials.GetBlackSprite();
        Material material;

        PartiallyBatched_Collider batch_collider;
        PartiallyBatched_Tilemap  batch_tilemap;

        LayerSetting layerSetting = buffer.lightSource.layerSetting[layer];
        bool         maskEffect   = (layerSetting.effect == LightingLayerEffect.InvisibleBellow);

        for (int i = 0; i < list.count; i++)
        {
            depth = list.list[i];

            switch (depth.type)
            {
            case ColliderDepth.Type.Collider:
                if ((int)depth.collider.lightingCollisionLayer == layer && drawShadows)
                {
                    LightingBufferShape.Shadow(buffer, depth.collider, lightSizeSquared, z, offset);
                }

                if ((int)depth.collider.lightingMaskLayer == layer && drawMask)
                {
                    LightingBufferSprite.MaskDepthWithAtlas(buffer, layerSettings.effect, depth.collider, offset, z);

                    LightingBufferShape.Mask(buffer, depth.collider, layerSetting, offset, z);

                    // Partialy Batched (Depth Edition)
                    if (buffer.partiallyBatchedList_Collider.Count > 0)
                    {
                        GL.End();

                        for (int s = 0; s < buffer.partiallyBatchedList_Collider.Count; s++)
                        {
                            batch_collider = buffer.partiallyBatchedList_Collider[s];

                            material = materialWhite;

                            if (batch_collider.collider2D.maskMode == LightingMaskMode.Invisible || (maskEffect && buffer.lightSource.transform.position.y > batch_collider.collider2D.transform.position.y))
                            {
                                material = materialBlack;
                            }

                            LightingBufferSprite.MaskDepthWithoutAtlas(buffer, batch_collider.collider2D, material, offset, z);
                        }
                        buffer.partiallyBatchedList_Collider.Clear();

                        manager.materials.GetAtlasMaterial().SetPass(0);
                        GL.Begin(GL.TRIANGLES);
                    }
                }

                break;

            case ColliderDepth.Type.Tile:
                if ((int)depth.tilemap.lightingCollisionLayer == layer && drawShadows)
                {
                    GL.Color(Color.black);
                    LightingBufferTile.DrawShadow(buffer, depth.tile, depth.polyOffset, depth.tilemap, lightSizeSquared, z);
                }

                if ((int)depth.tilemap.lightingMaskLayer == layer && drawMask)
                {
                    LightingBufferTile.MaskSpriteDepthWithAtlas(buffer, depth.tile, layerSettings, depth.tilemap, depth.polyOffset, z);

                    // GL.Color(Color.white);
                    // depth.tile.MaskShapeDepthWithAtlas(buffer, order, depth.tilemap, depth.polyOffset, z);

                    // Partialy Batched (Depth Edition)
                    if (buffer.partiallyBatchedList_Tilemap.Count > 0)
                    {
                        GL.End();

                        for (int s = 0; s < buffer.partiallyBatchedList_Tilemap.Count; s++)
                        {
                            batch_tilemap = buffer.partiallyBatchedList_Tilemap[s];
                            LightingBufferTile.DrawMask(buffer, depth.tile, layerSettings.effect, materialWhite, materialBlack, new Vector2D(batch_tilemap.polyOffset), batch_tilemap.tilemap, lightSizeSquared, z);
                        }
                        buffer.partiallyBatchedList_Tilemap.Clear();

                        manager.materials.GetAtlasMaterial().SetPass(0);
                        GL.Begin(GL.TRIANGLES);
                    }
                }

                break;
            }
        }

        GL.End();
    }
Exemplo n.º 2
0
    static void DrawWithoutAtlas(LightingBuffer2D buffer, int layer)
    {
        Material materialWhite = manager.materials.GetWhiteSprite();
        Material materialBlack = manager.materials.GetBlackSprite();
        Material material;

        LayerSetting layerSetting = buffer.lightSource.layerSetting[layer];
        bool         maskEffect   = layerSetting.effect == LightingLayerEffect.InvisibleBellow;

        for (int i = 0; i < list.count; i++)
        {
            depth = list.list[i];

            switch (depth.type)
            {
            case ColliderDepth.Type.Collider:
                if ((int)depth.collider.lightingCollisionLayer == layer && drawShadows)
                {
                    manager.materials.GetAtlasMaterial().SetPass(0);

                    GL.Begin(GL.TRIANGLES);

                    LightingBufferShape.Shadow(buffer, depth.collider, lightSizeSquared, z, offset);

                    GL.End();
                }

                if ((int)depth.collider.lightingMaskLayer == layer && drawMask)
                {
                    // Masking
                    material = materialWhite;

                    if (depth.collider.maskMode == LightingMaskMode.Invisible || (maskEffect && buffer.lightSource.transform.position.y > depth.collider.transform.position.y))
                    {
                        material = materialBlack;
                    }

                    LightingBufferSprite.MaskDepthWithoutAtlas(buffer, depth.collider, material, offset, z);

                    materialWhite.SetPass(0);

                    GL.Begin(GL.TRIANGLES);

                    GL.Color(Color.white);
                    LightingBufferShape.Mask(buffer, depth.collider, layerSetting, offset, z);

                    GL.End();
                }

                break;

            case ColliderDepth.Type.Tile:
                manager.materials.GetAtlasMaterial().SetPass(0);

                GL.Begin(GL.TRIANGLES);

                if ((int)depth.tilemap.lightingCollisionLayer == layer && drawShadows)
                {
                    LightingBufferTile.DrawShadow(buffer, depth.tile, depth.polyOffset, depth.tilemap, lightSizeSquared, z);
                }

                GL.End();

                if ((int)depth.tilemap.lightingMaskLayer == layer && drawMask)
                {
                    // Sprite, But What About Shape?
                    LightingBufferTile.DrawMask(buffer, depth.tile, layerSettings.effect, materialWhite, materialBlack, depth.polyOffset, depth.tilemap, lightSizeSquared, z);
                }

                break;
            }
        }
    }