public static void Draw(Vector2D offset, float z) { spriteRendererList = LightingSpriteRenderer2D.GetList(); manager = LightingManager2D.Get(); GL.PushMatrix(); if (manager.lightingSpriteAtlas) { DrawWithAtlas(offset, z); } else { DrawWithoutAtlas(offset, z); } GL.PopMatrix(); }
public static void Draw(Vector2D offset, float z) { float sunDirection = LightingManager2D.GetSunDirection(); // Day Soft Shadows GL.PushMatrix(); Max2D.defaultMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); GL.Color(Color.black); foreach (LightingCollider2D id in LightingCollider2D.GetList()) { if (id.dayHeight == false || id.height <= 0) { continue; } List <Polygon2D> polygons = id.GetPolygons(); foreach (Polygon2D polygon in polygons) { Polygon2D poly = polygon; poly = poly.ToWorldSpace(id.gameObject.transform); foreach (Pair2D p in Pair2D.GetList(poly.pointsList)) { Vector2D vA = p.A.Copy(); Vector2D vB = p.B.Copy(); vA.Push(sunDirection, id.height); vB.Push(sunDirection, id.height); Max2DMatrix.DrawTriangle(p.A, p.B, vA, offset, z); Max2DMatrix.DrawTriangle(vA, vB, p.B, offset, z); } } } GL.End(); GL.PopMatrix(); GL.PushMatrix(); LightingManager2D.Get().shadowBlurMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); Max2D.SetColor(Color.white); foreach (LightingCollider2D id in LightingCollider2D.GetList()) { if (id.dayHeight == false || id.height <= 0) { continue; } List <Polygon2D> polygons = id.GetPolygons(); foreach (Polygon2D polygon in polygons) { Polygon2D poly = polygon; poly = poly.ToWorldSpace(id.gameObject.transform); Polygon2D convexHull = Polygon2D.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection, id.height); foreach (DoublePair2D p in DoublePair2D.GetList(convexHull.pointsList)) { Vector2D zA = new Vector2D(p.A + offset); Vector2D zB = new Vector2D(p.B + offset); Vector2D zC = zB.Copy(); Vector2D pA = zA.Copy(); Vector2D pB = zB.Copy(); zA.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f); zB.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f); zC.Push(Vector2D.Atan2(p.B, p.C) + pi2, .5f); GL.TexCoord2(uv0, uv0); Max2D.Vertex3(pB, z); GL.TexCoord2(0.5f - uv0, uv0); Max2D.Vertex3(pA, z); GL.TexCoord2(0.5f - uv0, uv1); Max2D.Vertex3(zA, z); GL.TexCoord2(uv0, uv1); Max2D.Vertex3(zA, z); GL.TexCoord2(0.5f - uv0, uv1); Max2D.Vertex3(zB, z); GL.TexCoord2(0.5f - uv0, uv0); Max2D.Vertex3(pB, z); GL.TexCoord2(uv0, uv1); Max2D.Vertex3(zB, z); GL.TexCoord2(0.5f - uv0, uv0); Max2D.Vertex3(pB, z); GL.TexCoord2(0.5f - uv0, uv1); Max2D.Vertex3(zC, z); } } } GL.End(); GL.PopMatrix(); GL.PushMatrix(); Max2D.defaultMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); GL.Color(Color.black); GL.End(); GL.PopMatrix(); GL.PushMatrix(); LightingManager2D.Get().shadowBlurMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); Max2D.SetColor(Color.white); GL.End(); GL.PopMatrix(); Material material = LightingManager2D.Get().whiteSpriteMaterial; foreach (LightingSprite2D id in LightingSprite2D.GetList()) { if (id.GetSpriteRenderer() == null) { continue; } material.mainTexture = id.GetSpriteRenderer().sprite.texture; //Debug.Log(sprite.pivot); Vector2 p = id.transform.position; Vector2 scale = id.transform.lossyScale; if (id.GetSpriteRenderer().flipX) { scale.x = -scale.x; } if (id.GetSpriteRenderer().flipY) { scale.y = -scale.y; } Max2D.DrawImage(material, offset.ToVector2() + p, scale, id.transform.rotation.eulerAngles.z, z); } material = LightingManager2D.Get().additiveMaterial; foreach (LightingSpriteRenderer2D id in LightingSpriteRenderer2D.GetList()) { if (id.sprite == null) { continue; } material.mainTexture = id.sprite.texture; //Debug.Log(sprite.pivot); Vector2 position = id.transform.position; Vector2 scale = id.transform.lossyScale; float scaleX = (float)id.sprite.texture.width / (id.sprite.pixelsPerUnit * 2); float scaleY = (float)id.sprite.texture.width / (id.sprite.pixelsPerUnit * 2); //Debug.Log(scaleX + " " + scaleY); scale.x *= scaleX; scale.y *= scaleY; scale.x *= id.scale.x; scale.y *= id.scale.y; if (id.flipX) { scale.x = -scale.x; } if (id.flipY) { scale.y = -scale.y; } //material.color = id.color; Color color = id.color; color.a = id.alpha; material.SetColor("_TintColor", color); Max2D.DrawImage(material, offset.ToVector2() + position + id.offset, scale, id.transform.rotation.eulerAngles.z, z); } material.mainTexture = null; float ratio = (float)Screen.width / Screen.height; Camera bufferCamera = LightingMainBuffer2D.Get().bufferCamera; Vector2 size = new Vector2(bufferCamera.orthographicSize * ratio, bufferCamera.orthographicSize); Vector3 pos = Camera.main.transform.position; Max2D.iDrawImage(LightingManager2D.Get().additiveMaterial, new Vector2D(pos), new Vector2D(size), pos.z); }
public static void Draw(Vector2D offset, float z) { List <LightingSpriteRenderer2D> list = LightingSpriteRenderer2D.GetList(); LightingSpriteRenderer2D id; Material material; Vector2 position, scale; float rot; Color color; for (int i = 0; i < list.Count; i++) { id = list[i]; if (id.GetSprite() == null) { continue; } if (id.InCamera() == false) { continue; } LightingManager2D.LightingDebug.SpriteRenderersDrawn++; position = id.transform.position; scale = id.transform.lossyScale; scale.x *= id.offsetScale.x; scale.y *= id.offsetScale.y; rot = id.offsetRotation; if (id.applyTransformRotation) { rot += id.transform.rotation.eulerAngles.z; } switch (id.type) { case LightingSpriteRenderer2D.Type.Particle: color = id.color; color.a = id.alpha; material = LightingManager2D.Get().additiveMaterial; material.mainTexture = id.GetSprite().texture; material.SetColor("_TintColor", color); Max2D.DrawSpriteRenderer(material, id.spriteRenderer, offset.ToVector2() + position + id.offsetPosition, scale, rot, z); material.mainTexture = null; break; case LightingSpriteRenderer2D.Type.WhiteMask: material = LightingManager2D.Get().whiteSpriteMaterial; material.mainTexture = id.GetSprite().texture; Max2D.DrawSpriteRenderer(material, id.spriteRenderer, offset.ToVector2() + position + id.offsetPosition, scale, rot, z); material.mainTexture = null; break; case LightingSpriteRenderer2D.Type.BlackMask: material = LightingManager2D.Get().blackSpriteMaterial; material.mainTexture = id.sprite.texture; Max2D.DrawSpriteRenderer(material, id.spriteRenderer, offset.ToVector2() + position + id.offsetPosition, scale, rot, z); material.mainTexture = null; break; } } }