コード例 #1
0
    static public void DrawMask(LightingBuffer2D buffer, LightingTile tile, LightingLayerEffect maskEffect, Material materialA, Material materialB, Vector2D polyOffset, LightingTilemapCollider2D tilemap, float lightSizeSquared, float z)
    {
        VirtualSpriteRenderer spriteRenderer = new VirtualSpriteRenderer();

        spriteRenderer.sprite = tile.GetOriginalSprite();

        if (spriteRenderer.sprite == null)
        {
            return;
        }

        Vector3 rot = Math2D.GetPitchYawRollRad(tilemap.transform.rotation);

        float rotationYScale = Mathf.Sin(rot.x + Mathf.PI / 2);
        float rotationXScale = Mathf.Sin(rot.y + Mathf.PI / 2);

        float scaleX = tilemap.transform.lossyScale.x * rotationXScale * tilemap.cellSize.x;
        float scaleY = tilemap.transform.lossyScale.y * rotationYScale * tilemap.cellSize.y;

        Vector2 tileSize = new Vector2(scaleX / tilemap.cellSize.x, scaleY / tilemap.cellSize.y);

        Material material = materialA;

        if (tilemap.maskMode == LightingMaskMode.Invisible || (maskEffect == LightingLayerEffect.InvisibleBellow && polyOffset.y < 0))
        {
            material = materialB;
        }

        material.mainTexture = spriteRenderer.sprite.texture;

        Max2D.DrawSprite(material, spriteRenderer, polyOffset.ToVector2(), tileSize, 0, z);

        material.mainTexture = null;

        LightingDebug.maskGenerations++;
    }
コード例 #2
0
    public static void MaskDepthWithAtlas(LightingBuffer2D buffer, LightingLayerEffect lightingLayerEffect, LightingCollider2D id, Vector2D offset, float z)
    {
        if (id.shape.maskType == LightingCollider2D.MaskType.None)
        {
            return;
        }

        if (id.shape.maskType != LightingCollider2D.MaskType.Sprite)
        {
            return;
        }

        if (id.isVisibleForLight(buffer) == false)
        {
            return;
        }

        Sprite sprite = id.shape.GetAtlasSprite();

        if (id.spriteRenderer == null)
        {
            return;
        }

        if (sprite == null)
        {
            Sprite reqSprite = SpriteAtlasManager.RequestSprite(id.shape.GetOriginalSprite(), SpriteRequest.Type.WhiteMask);
            if (reqSprite == null)
            {
                PartiallyBatched_Collider batched = new PartiallyBatched_Collider();

                batched.collider2D = id;

                buffer.partiallyBatchedList_Collider.Add(batched);
                return;
            }
            else
            {
                id.shape.SetAtlasSprite(reqSprite);
                sprite = reqSprite;
            }
        }

        GL.Color(Color.white);
        if (lightingLayerEffect == LightingLayerEffect.InvisibleBellow && buffer.lightSource.transform.position.y > id.transform.position.y)
        {
            GL.Color(Color.black);
        }

        Vector2 p = id.transform.position;

        p.x += (float)offset.x;
        p.y += (float)offset.y;

        Vector2 scale = id.transform.lossyScale;

        spriteRenderer.sprite = sprite;

        Max2D.DrawSpriteBatched_Tris(spriteRenderer, buffer.lightSource.layerSetting[0], id.maskMode, p, scale, id.transform.rotation.eulerAngles.z, z);

        LightingDebug.maskGenerations++;
    }