public static void Mask(Light2D light, LightCollider2D id, LayerSetting layerSetting) { if (id.InLight(light) == false) { return; } int shapeCount = id.shapes.Count; for (int i = 0; i < shapeCount; i++) { LightColliderShape shape = id.shapes[i]; List <MeshObject> meshObjects = shape.GetMeshes(); if (meshObjects == null) { return; } Vector2 position = shape.transform2D.position - light.transform2D.position; Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position; GL.Color(LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency)); GLExtended.DrawMeshPass(meshObjects, position, shape.transform.lossyScale, shape.transform2D.rotation); } }
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; }
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; }
static public void MaskShape(Light2D light, LightTilemapCollider2D id, LayerSetting layerSetting) { Vector2 lightPosition = -light.transform.position; LightTilemapCollider.Base tilemap = id.GetCurrentTilemap(); bool isGrid = !tilemap.IsPhysicsShape(); Vector2 scale = tilemap.TileWorldScale(); float rotation = id.transform.eulerAngles.z; MeshObject tileMesh = null; if (isGrid) { tileMesh = LightTile.GetStaticMesh(tilemap); } int count = tilemap.chunkManager.GetTiles(light.GetWorldRect()); for (int i = 0; i < count; i++) { LightTile tile = tilemap.chunkManager.display[i]; Vector2 tilePosition = tilemap.TileWorldPosition(tile); tilePosition += lightPosition; if (tile.NotInRange(tilePosition, light.size)) { continue; } if (isGrid == false) { tileMesh = null; tileMesh = tile.GetDynamicMesh(); } if (tileMesh == null) { continue; } Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1? GL.Color(color); GLExtended.DrawMeshPass(tileMesh, tilePosition, scale, rotation + tile.rotation); } GL.Color(Color.white); }
public static void Mask(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting) { if (id.InLight(light) == false) { return; } Texture2D currentTexture = null; Color currentColor = Color.black; GL.Begin(GL.QUADS); foreach (LightColliderShape shape in id.shapes) { UnityEngine.SpriteRenderer spriteRenderer = shape.spriteShape.GetSpriteRenderer(); Sprite sprite = shape.spriteShape.GetOriginalSprite(); if (sprite == null || spriteRenderer == null) { continue; } if (sprite.texture == null) { continue; } Vector2 position = shape.transform2D.position - light.transform2D.position; Color color = LayerSettingColor.Get(shape, position, layerSetting, id.maskEffect, id.maskTranslucency); if (currentTexture != sprite.texture || currentColor != color) { currentTexture = sprite.texture; currentColor = color; material.mainTexture = currentTexture; material.color = currentColor; material.SetPass(0); } Rendering.Universal.Sprite.FullRect.DrawPass(id.spriteMeshObject, spriteRenderer, position, shape.transform2D.scale, shape.transform2D.rotation); } GL.End(); material.mainTexture = null; material.color = Color.white; }
public static void Mask(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting) { if (id.InLight(light) == false) { return; } foreach (LightColliderShape shape in id.shapes) { SkinnedMeshRenderer skinnedMeshRenderer = shape.skinnedMeshShape.GetSkinnedMeshRenderer(); if (skinnedMeshRenderer == null) { return; } List <MeshObject> meshObject = shape.GetMeshes(); if (meshObject == null) { return; } if (skinnedMeshRenderer.sharedMaterial != null) { material.mainTexture = skinnedMeshRenderer.sharedMaterial.mainTexture; } else { material.mainTexture = null; } Vector2 position = shape.transform2D.position - light.transform2D.position; Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position; material.color = LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency); material.SetPass(0); GLExtended.DrawMesh(meshObject, position, id.mainShape.transform2D.scale, shape.transform2D.rotation); material.mainTexture = null; } }
static public void BumpedSprite(Light2D light, LightTilemapCollider2D id, Material material, LayerSetting layerSetting) { Texture bumpTexture = id.bumpMapMode.GetBumpTexture(); if (bumpTexture == null) { return; } material.SetTexture("_Bump", bumpTexture); Vector2 lightPosition = -light.transform.position; LightTilemapCollider.Base tilemap = id.GetCurrentTilemap(); Vector2 scale = tilemap.TileWorldScale(); Texture2D currentTexture = null; GL.Begin(GL.QUADS); foreach (LightTile tile in tilemap.mapTiles) { if (tile.GetOriginalSprite() == null) { return; } Vector2 tilePosition = tilemap.TileWorldPosition(tile); tilePosition += lightPosition; if (tile.NotInRange(tilePosition, light.size)) { continue; } virtualSpriteRenderer.sprite = tile.GetOriginalSprite(); if (virtualSpriteRenderer.sprite.texture == null) { continue; } if (currentTexture != virtualSpriteRenderer.sprite.texture) { currentTexture = virtualSpriteRenderer.sprite.texture; material.mainTexture = currentTexture; material.SetPass(0); } Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1 GLExtended.SetColor(color); Universal.Sprite.FullRect.Simple.DrawPass(tile.spriteMeshObject, virtualSpriteRenderer, tilePosition, scale, tile.worldRotation); } GL.End(); material.mainTexture = null; }
public static void MaskNormalMap(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting) { if (id.InLight(light) == false) { return; } Texture normalTexture = id.bumpMapMode.GetBumpTexture(); if (normalTexture == null) { return; } float rotation; material.SetTexture("_Bump", normalTexture); foreach (LightColliderShape shape in id.shapes) { MeshRenderer meshRenderer = id.mainShape.meshShape.GetMeshRenderer(); if (meshRenderer == null) { return; } List <MeshObject> meshObjects = id.mainShape.GetMeshes(); if (meshObjects == null) { return; } if (meshRenderer.sharedMaterial != null) { material.mainTexture = meshRenderer.sharedMaterial.mainTexture; } else { material.mainTexture = null; } Vector2 position = shape.transform2D.position - light.transform2D.position; Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position; material.color = LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency); float color = material.color.r; switch (id.bumpMapMode.type) { case NormalMapType.ObjectToLight: rotation = Mathf.Atan2(light.transform2D.position.y - shape.transform2D.position.y, light.transform2D.position.x - shape.transform2D.position.x); rotation -= Mathf.Deg2Rad * (shape.transform2D.rotation); material.SetFloat("_LightRX", Mathf.Cos(rotation) * 2); material.SetFloat("_LightRY", Mathf.Sin(rotation) * 2); material.SetFloat("_LightColor", color); break; case NormalMapType.PixelToLight: material.SetFloat("_LightColor", color); rotation = shape.transform2D.rotation * Mathf.Deg2Rad; Vector2 sc = shape.transform2D.scale; sc = sc.normalized; material.SetFloat("_LightX", Mathf.Cos(rotation) * sc.x); material.SetFloat("_LightY", Mathf.Cos(rotation) * sc.y); material.SetFloat("_Depth", id.bumpMapMode.depth); if (id.bumpMapMode.invertX) { material.SetFloat("_InvertX", -1); } else { material.SetFloat("_InvertX", 1); } if (id.bumpMapMode.invertY) { material.SetFloat("_InvertY", -1); } else { material.SetFloat("_InvertY", 1); } break; } material.SetPass(0); GLExtended.DrawMesh(meshObjects, position, id.mainShape.transform2D.scale, shape.transform2D.rotation); material.mainTexture = null; } }
public static void MaskNormalMap(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting) { if (id.InLight(light) == false) { return; } Texture normalTexture = id.bumpMapMode.GetBumpTexture(); if (normalTexture == null) { return; } float rotation; material.SetTexture("_Bump", normalTexture); foreach (LightColliderShape shape in id.shapes) { UnityEngine.SpriteRenderer spriteRenderer = shape.spriteShape.GetSpriteRenderer(); if (spriteRenderer == null) { continue; } Sprite sprite = shape.spriteShape.GetOriginalSprite(); if (sprite == null) { continue; } if (sprite.texture == null) { continue; } Vector2 position = shape.transform2D.position - light.transform2D.position; material.mainTexture = sprite.texture; material.color = LayerSettingColor.Get(position, layerSetting, id.maskEffect, id.maskTranslucency); float color = material.color.r; switch (id.bumpMapMode.type) { case NormalMapType.ObjectToLight: rotation = Mathf.Atan2(light.transform2D.position.y - shape.transform2D.position.y, light.transform2D.position.x - shape.transform2D.position.x); rotation -= Mathf.Deg2Rad * (shape.transform2D.rotation); material.SetFloat("_LightRX", Mathf.Cos(rotation) * 2); material.SetFloat("_LightRY", Mathf.Sin(rotation) * 2); material.SetFloat("_LightColor", color); break; case NormalMapType.PixelToLight: material.SetFloat("_LightColor", color); rotation = shape.transform2D.rotation * Mathf.Deg2Rad; Vector2 sc = shape.transform2D.scale; sc = sc.normalized; material.SetFloat("_LightX", Mathf.Cos(rotation) * sc.x); material.SetFloat("_LightY", Mathf.Cos(rotation) * sc.y); material.SetFloat("_Depth", id.bumpMapMode.depth); if (id.bumpMapMode.invertX) { material.SetFloat("_InvertX", -1); } else { material.SetFloat("_InvertX", 1); } if (id.bumpMapMode.invertY) { material.SetFloat("_InvertY", -1); } else { material.SetFloat("_InvertY", 1); } break; } Rendering.Universal.Sprite.FullRect.Draw(id.spriteMeshObject, material, spriteRenderer, position, shape.transform2D.scale, shape.transform2D.rotation); } }