public static void DrawShadowsWithoutAtlas(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(); #if UNITY_2018_1_OR_NEWER tilemapList = LightingTilemapCollider2D.GetList(); #endif manager.materials.GetAtlasMaterial().SetPass(0); GL.Begin(GL.TRIANGLES); for (int id = 0; id < colliderList.Count; id++) { if ((int)colliderList[id].lightingCollisionLayer != layer) { continue; } 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; } LightingBufferTilemapRectangle.Shadow(buffer, tilemapList[id], lightSizeSquared, z); } #endif GL.End(); }
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(); }
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 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; } } }