public static void DrawWithAtlas(LightingBuffer2D buffer, int layer) { float lightSizeSquared = Mathf.Sqrt(buffer.lightSource.lightSize * buffer.lightSource.lightSize + buffer.lightSource.lightSize * buffer.lightSource.lightSize); float z = buffer.transform.position.z; offset.x = -buffer.lightSource.transform.position.x; offset.y = -buffer.lightSource.transform.position.y; manager = LightingManager2D.Get(); colliderList = LightingCollider2D.GetList(); LayerSetting layerSetting = buffer.lightSource.layerSetting[layer]; bool maskEffect = (layerSetting.effect == LightingLayerEffect.InvisibleBellow); #if UNITY_2018_1_OR_NEWER tilemapList = LightingTilemapCollider2D.GetList(); #endif // Shadow Fill manager.materials.GetAtlasMaterial().SetPass(0); GL.Begin(GL.TRIANGLES); if (drawShadows) { for (int id = 0; id < colliderList.Count; id++) { if ((int)colliderList[id].lightingCollisionLayer != layer) { continue; } // Collider Shadow LightingBufferMesh.Shadow(buffer, colliderList[id], lightSizeSquared, z); LightingBufferShape.Shadow(buffer, colliderList[id], lightSizeSquared, z, offset); } #if UNITY_2018_1_OR_NEWER for (int id = 0; id < tilemapList.Count; id++) { if ((int)tilemapList[id].lightingCollisionLayer != layer) { continue; } // Tilemap Shadow LightingBufferTilemapRectangle.Shadow(buffer, tilemapList[id], lightSizeSquared, z); } #endif } if (drawMask) { if (colliderList.Count > 0) { for (int id = 0; id < colliderList.Count; id++) { if ((int)colliderList[id].lightingMaskLayer != layer) { continue; } // Collider Shape Mask LightingBufferShape.Mask(buffer, colliderList[id], layerSetting, offset, z); // Collider Sprite Mask LightingBufferSprite.MaskWithAtlas(buffer, colliderList[id], offset, z); } } #if UNITY_2018_1_OR_NEWER for (int id = 0; id < tilemapList.Count; id++) { if ((int)tilemapList[id].lightingMaskLayer != layer) { continue; } // Tilemap Shape Mask LightingBufferTilemapRectangle.MaskShape(buffer, tilemapList[id], offset, z); // Tilemap Sprite Mask LightingBufferTilemapRectangle.MaskSpriteWithAtlas(buffer, tilemapList[id], offset, z); } #endif } GL.End(); // Partialy Batched (Default Edition) if (buffer.partiallyBatchedList_Collider.Count > 0) { Material materialWhite = manager.materials.GetWhiteSprite(); Material materialBlack = manager.materials.GetBlackSprite(); Material material; PartiallyBatched_Collider batch; materialWhite.mainTexture = SpriteAtlasManager.Get().atlasTexture.texture; materialWhite.SetPass(0); for (int i = 0; i < buffer.partiallyBatchedList_Collider.Count; i++) { batch = buffer.partiallyBatchedList_Collider[i]; material = materialWhite; if (maskEffect && colliderList[i].transform.position.y < buffer.lightSource.transform.position.y) { material = materialBlack; } LightingBufferSprite.MaskWithoutAtlas(buffer, batch.collider2D, material, offset, z); } materialWhite.mainTexture = null; buffer.partiallyBatchedList_Collider.Clear(); } if (buffer.partiallyBatchedList_Tilemap.Count > 0) { Material materialWhite = manager.materials.GetWhiteSprite(); Material materialBlack = manager.materials.GetBlackSprite(); PartiallyBatched_Tilemap batch; Material material; // Draw Each Partialy Batched for (int i = 0; i < buffer.partiallyBatchedList_Tilemap.Count; i++) { batch = buffer.partiallyBatchedList_Tilemap[i]; material = materialWhite; if (maskEffect && batch.polyOffset.y < 0) { material = materialBlack; } material.mainTexture = batch.virtualSpriteRenderer.sprite.texture; Max2D.DrawSprite(material, batch.virtualSpriteRenderer, batch.polyOffset, batch.tileSize, 0, z); material.mainTexture = null; } buffer.partiallyBatchedList_Tilemap.Clear(); } }
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(); }
static public void DrawMaskWithoutAtlas(LightingBuffer2D buffer, int layer) { float z = buffer.transform.position.z; offset.x = -buffer.lightSource.transform.position.x; offset.y = -buffer.lightSource.transform.position.y; manager = LightingManager2D.Get(); colliderList = LightingCollider2D.GetList(); LayerSetting layerSetting = buffer.lightSource.layerSetting[layer]; bool maskEffect = (layerSetting.effect == LightingLayerEffect.InvisibleBellow); Material materialWhite = manager.materials.GetWhiteSprite(); Material materialBlack = manager.materials.GetBlackSprite(); Material material; #if UNITY_2018_1_OR_NEWER tilemapList = LightingTilemapCollider2D.GetList(); #endif //materialWhite.SetPass(0); manager.materials.GetAtlasMaterial().SetPass(0); GL.Begin(GL.TRIANGLES); GL.Color(Color.white); // Collider Shape Mask for (int id = 0; id < colliderList.Count; id++) { if ((int)colliderList[id].lightingMaskLayer != layer) { continue; } LightingBufferShape.Mask(buffer, colliderList[id], layerSetting, offset, z); } GL.Color(Color.white); // Tilemap Shape Mask #if UNITY_2018_1_OR_NEWER for (int id = 0; id < tilemapList.Count; id++) { if ((int)tilemapList[id].lightingMaskLayer != layer) { continue; } LightingBufferTilemapRectangle.MaskShape(buffer, tilemapList[id], offset, z); } #endif GL.End(); // Collider Sprite Mask if (colliderList.Count > 0) { for (int id = 0; id < colliderList.Count; id++) { if ((int)colliderList[id].lightingMaskLayer != layer) { continue; } material = materialWhite; if (colliderList[id].maskMode == LightingMaskMode.Invisible) { material = materialBlack; } else if (maskEffect && colliderList[id].transform.position.y < buffer.lightSource.transform.position.y) { material = materialBlack; } LightingBufferSprite.MaskWithoutAtlas(buffer, colliderList[id], material, offset, z); } } // Tilemap Sprite Mask #if UNITY_2018_1_OR_NEWER for (int id = 0; id < tilemapList.Count; id++) { if ((int)tilemapList[id].lightingMaskLayer != layer) { continue; } LightingBufferTilemapRectangle.MaskSpriteWithoutAtlas(buffer, tilemapList[id], materialWhite, materialBlack, offset, z); } #endif }
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; } } }