예제 #1
0
        static public void Sprite(Light2D light, LightTilemapCollider2D id, Material material, LayerSetting layerSetting)
        {
            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemap = id.GetCurrentTilemap();
            Vector2 scale    = tilemap.TileWorldScale();
            float   rotation = id.transform.eulerAngles.z;

            int count = tilemap.chunkManager.GetTiles(light.GetWorldRect());

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

            GL.Begin(GL.QUADS);

            for (int i = 0; i < count; i++)
            {
                LightTile tile = tilemap.chunkManager.display[i];

                if (tile.GetOriginalSprite() == null)
                {
                    return;
                }

                Vector2 tilePosition = tile.GetWorldPosition(tilemap);

                tilePosition += lightPosition;

                if (tile.NotInRange(tilePosition, light.size))
                {
                    continue;
                }

                virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

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

                Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1?

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

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

                    material.SetPass(0);
                }

                Universal.Sprite.FullRect.Simple.Draw(tile.spriteMeshObject, material, virtualSpriteRenderer, tilePosition, scale * tile.scale, rotation + tile.rotation);
            }

            GL.End();

            material.mainTexture = null;
        }
예제 #2
0
            public static void Draw(Camera camera, LightTilemapRoom2D id, Material material)
            {
                Vector2 cameraPosition = -camera.transform.position;

                float cameraRadius = CameraTransform.GetRadius(camera);

                LightTilemapCollider.Base tilemapCollider = id.GetCurrentTilemap();

                material.mainTexture = null;

                Texture2D currentTexture = null;

                GL.Begin(GL.QUADS);

                int count = tilemapCollider.chunkManager.GetTiles(CameraTransform.GetWorldRect(camera));

                for (int i = 0; i < count; i++)
                {
                    LightTile tile = tilemapCollider.chunkManager.display[i];
                    if (tile.GetOriginalSprite() == null)
                    {
                        continue;
                    }

                    Vector2 tilePosition = tile.GetWorldPosition(tilemapCollider);

                    tilePosition += cameraPosition;

                    if (tile.NotInRange(tilePosition, cameraRadius))
                    {
                        continue;
                    }

                    spriteRenderer.sprite = tile.GetOriginalSprite();

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

                    if (currentTexture != spriteRenderer.sprite.texture)
                    {
                        currentTexture       = spriteRenderer.sprite.texture;
                        material.mainTexture = currentTexture;

                        material.SetPass(0);
                    }

                    Universal.Sprite.FullRect.Simple.DrawPass(tile.spriteMeshObject, spriteRenderer, tilePosition, tile.worldScale, tile.worldRotation);
                }

                GL.End();

                material.mainTexture = null;
            }
예제 #3
0
        static public void MaskSprite(LightTile tile, LayerSetting layerSetting, Material material, LightTilemapCollider2D tilemap, float lightSizeSquared)
        {
            virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

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

            LightTilemapCollider.Base tilemapBase = tilemap.GetCurrentTilemap();

            Vector2 tilePosition = tile.GetWorldPosition(tilemapBase) - ShadowEngine.light.transform2D.position;

            material.color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1);             // 1?

            material.mainTexture = virtualSpriteRenderer.sprite.texture;

            Vector2 scale = tile.worldScale * tile.scale;

            GLExtended.SetColor(Color.white);

            tilePosition += ShadowEngine.drawOffset;

            Universal.Sprite.FullRect.Simple.Draw(tile.spriteMeshObject, material, virtualSpriteRenderer, tilePosition, scale, tile.worldRotation);

            material.mainTexture = null;
        }