// Post-Render Mode Drawing public static void PostRender(LightingMainBuffer2D mainBuffer) { Camera camera = mainBuffer.cameraSettings.GetCamera(); if (camera == null) { return; } if (mainBuffer.cameraSettings.renderMode == CameraSettings.RenderMode.Disabled) { return; } if (Lighting2D.RenderingMode != RenderingMode.OnPostRender) { return; } if (Camera.current != camera) { return; } Rendering.Universal.Texture.Draw(mainBuffer.GetMaterial(), LightingPosition.GetCameraPlanePosition(camera), GetSize(camera), camera.transform.eulerAngles.z, LightingPosition.GetCameraPlanePosition(camera).z); }
public static OnRenderMode Get(LightingMainBuffer2D buffer) { foreach (OnRenderMode meshModeObject in List) { if (meshModeObject.mainBuffer == buffer) { return(meshModeObject); } } GameObject meshRendererMode = new GameObject("On Render"); OnRenderMode onRenderMode = meshRendererMode.AddComponent <OnRenderMode>(); onRenderMode.mainBuffer = buffer; onRenderMode.Initialize(buffer); onRenderMode.UpdateLayer(); if (Lighting2D.ProjectSettings.managerInternal == LightingSettings.ManagerInternal.HideInHierarchy) { meshRendererMode.hideFlags = meshRendererMode.hideFlags | HideFlags.HideInHierarchy; } onRenderMode.name = "On Render: " + buffer.name; return(onRenderMode); }
static public void RenderTexture(LightingMainBuffer2D buffer) { Vector2Int screen = GetScreenResolution(buffer); if (screen.x > 0 && screen.y > 0) { Camera camera = buffer.cameraSettings.GetCamera(); if (buffer.renderTexture == null || screen.x != buffer.renderTexture.width || screen.y != buffer.renderTexture.height) { switch (camera.cameraType) { case CameraType.Game: Rendering.LightingMainBuffer.InitializeRenderTexture(buffer); break; case CameraType.SceneView: // Scene view pixel rect is constantly changing (Unity Bug?) int differenceX = Mathf.Abs(screen.x - buffer.renderTexture.width); int differenceY = Mathf.Abs(screen.y - buffer.renderTexture.height); if (differenceX > 5 || differenceY > 5) { Rendering.LightingMainBuffer.InitializeRenderTexture(buffer); } break; } } } }
static public LightingMainBuffer2D Get(CameraSettings cameraSettings) { if (cameraSettings.GetCamera() == null) { return(null); } foreach (LightingMainBuffer2D mainBuffer in List) { if (mainBuffer.cameraSettings.GetCamera() == cameraSettings.GetCamera() && mainBuffer.cameraSettings.bufferID == cameraSettings.bufferID) { return(mainBuffer); } } if (Lighting2D.BufferPresets.Length <= cameraSettings.bufferID) { Debug.LogWarning("Lighting2D: Not enough buffer settings initialized"); return(null); } Buffers.Get(); LightingMainBuffer2D buffer = new LightingMainBuffer2D(); buffer.cameraSettings = cameraSettings; Rendering.LightingMainBuffer.InitializeRenderTexture(buffer); return(buffer); }
public static void Update(LightingMainBuffer2D buffer) { BufferPreset bufferPreset = buffer.GetBufferPreset(); if (bufferPreset == null) { buffer.DestroySelf(); return; } if (Rendering.LightingMainBuffer.Check.CameraSettings(buffer) == false) { buffer.DestroySelf(); return; } Camera camera = buffer.cameraSettings.GetCamera(); if (camera == null) { return; } Rendering.LightingMainBuffer.Check.RenderTexture(buffer); }
static public void InitializeRenderTexture(LightingMainBuffer2D buffer) { Vector2Int screen = GetScreenResolution(buffer); if (screen.x > 0 && screen.y > 0) { string idName = ""; int bufferID = buffer.cameraSettings.bufferID; if (bufferID < Lighting2D.BufferPresets.Length) { idName = Lighting2D.BufferPresets[bufferID].name + ", "; } Camera camera = buffer.cameraSettings.GetCamera(); buffer.name = "Camera Buffer (" + idName + "Id: " + (bufferID + 1) + ", Camera: " + camera.name + " )"; RenderTextureFormat format = RenderTextureFormat.Default; format = RenderTextureFormat.RGB565; if (SystemInfo.SupportsTextureFormat(TextureFormat.RGBAHalf)) { if (Lighting2D.QualitySettings.HDR) { format = RenderTextureFormat.DefaultHDR; format = RenderTextureFormat.RGB111110Float; } } buffer.renderTexture = new LightTexture(screen.x, screen.y, 0, format); buffer.renderTexture.Create(); } }
public bool InCamera() { float cameraSize = LightingMainBuffer2D.Get().cameraSize; Camera camera = LightingManager2D.Get().GetCamera(); return(Vector2.Distance(transform.position, camera.transform.position) < Mathf.Sqrt((cameraSize * 2f) * (cameraSize * 2f)) + shape.GetFrustumDistance(transform)); }
public static void Render(LightingMainBuffer2D buffer) { Camera camera = buffer.cameraSettings.GetCamera(); if (camera == null) { return; } float cameraRotation = LightingPosition.GetCameraRotation(camera); Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, cameraRotation), Vector3.one); float sizeY = camera.orthographicSize; float sizeX = sizeY * ((float)camera.pixelWidth / camera.pixelHeight); GL.LoadPixelMatrix(-sizeX, sizeX, -sizeY, sizeY); GL.MultMatrix(matrix); GL.PushMatrix(); BufferPreset bufferPreset = buffer.GetBufferPreset(); Rendering.Day.Main.Draw(camera, bufferPreset); Rendering.Night.Main.Draw(camera, bufferPreset); GL.PopMatrix(); }
public void Initialize() { instance = this; // Lighting Materials additiveMaterial = new Material(Shader.Find(Max2D.shaderPath + "Particles/Additive")); penumbraMaterial = new Material(Shader.Find(Max2D.shaderPath + "Particles/Multiply")); penumbraMaterial.mainTexture = Resources.Load("textures/penumbra") as Texture; occlusionEdgeMaterial = new Material(Shader.Find(Max2D.shaderPath + "Particles/Multiply")); occlusionEdgeMaterial.mainTexture = Resources.Load("textures/occlusionedge") as Texture; shadowBlurMaterial = new Material(Shader.Find(Max2D.shaderPath + "Particles/Multiply")); shadowBlurMaterial.mainTexture = Resources.Load("textures/shadowblur") as Texture; occlusionBlurMaterial = new Material(Shader.Find(Max2D.shaderPath + "Particles/Multiply")); occlusionBlurMaterial.mainTexture = Resources.Load("textures/occlussionblur") as Texture; whiteSpriteMaterial = new Material(Shader.Find("SmartLighting2D/SpriteWhite")); blackSpriteMaterial = new Material(Shader.Find("SmartLighting2D/SpriteBlack")); transform.position = Vector3.zero; mainBuffer = LightingMainBuffer2D.Get(); fboManager = FBOManager.Get(); version = VERSION; }
public void OnRenderObject() { if (enable == false) { return; } if (Camera.current != Camera.main) { return; } if (mainBuffer == null) { mainBuffer = LightingMainBuffer2D.Get(); return; } if (mainBuffer.bufferCamera == null) { return; } LightingDebug.LightMainCameraUpdates += 1; float sizeX = mainBuffer.bufferCamera.orthographicSize * ((float)Screen.width / Screen.height); Vector2 size = new Vector2(sizeX, mainBuffer.bufferCamera.orthographicSize); size.x *= ((float)Screen.width / (float)Screen.height) / (size.x / size.y); Vector3 pos = Camera.main.transform.position; pos.z += 1; Max2D.iDrawImage2(mainBuffer.material, pos, size, Camera.main.transform.eulerAngles.z, pos.z); }
public void UpdateMaterials() { if (Lighting2D.materials.Initialize(Lighting2D.QualitySettings.HDR)) { LightingMainBuffer2D.Clear(); LightingBuffer2D.Clear(); Light2D.ForceUpdateAll(); } }
public bool InCamera() { float cameraSize = LightingMainBuffer2D.Get().cameraSize * 1.25f; float verticalSize = cameraSize; float horizontalSize = cameraSize * ((float)Screen.width / Screen.height); Camera camera = LightingManager2D.Get().GetCamera(); return(Vector2.Distance(transform.position, camera.transform.position) < Mathf.Sqrt((verticalSize) * (horizontalSize)) + GetSize() * 2); }
override public void OnInspectorGUI() { LightingTilemapCollider2D script = target as LightingTilemapCollider2D; script.mapType = (LightingTilemapCollider2D.MapType)EditorGUILayout.EnumPopup("Tilemap Type", script.mapType); script.colliderType = (LightingTilemapCollider2D.ColliderType)EditorGUILayout.EnumPopup("Collision Type", script.colliderType); script.lightingCollisionLayer = (LightingLayer)EditorGUILayout.EnumPopup("Collision Layer", script.lightingCollisionLayer); script.maskType = (LightingTilemapCollider2D.MaskType)EditorGUILayout.EnumPopup("Mask Type", script.maskType); if (script.maskType != LightingTilemapCollider2D.MaskType.None) { script.lightingMaskLayer = (LightingLayer)EditorGUILayout.EnumPopup("Mask Layer", script.lightingMaskLayer); script.maskMode = (LightingMaskMode)EditorGUILayout.EnumPopup("Mask Mode", script.maskMode); } else { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Mask Layer", script.lightingMaskLayer); EditorGUILayout.EnumPopup("Mask Mode", script.maskMode); EditorGUI.EndDisabledGroup(); } script.dayHeight = EditorGUILayout.Toggle("Day Height", script.dayHeight); if (script.dayHeight) { script.height = EditorGUILayout.FloatField("Height", script.height); } //script.ambientOcclusion = EditorGUILayout.Toggle("Ambient Occlusion", script.ambientOcclusion); //if (script.ambientOcclusion) { // script.occlusionSize = EditorGUILayout.FloatField("Occlussion Size", script.occlusionSize); //} if (GUILayout.Button("Update Collisions")) { script.Initialize(); foreach (LightingSource2D light in LightingSource2D.GetList()) { light.movement.ForceUpdate(); } LightingMainBuffer2D.ForceUpdate(); } if (GUI.changed && EditorApplication.isPlaying == false) { EditorUtility.SetDirty(target); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } }
static public void DrawTint() { float ratio = (float)Screen.width / Screen.height; Camera camera = LightingManager2D.Get().GetCamera(); Camera bufferCamera = LightingMainBuffer2D.Get().bufferCamera; Vector2 size = new Vector2(bufferCamera.orthographicSize * ratio, bufferCamera.orthographicSize); Vector3 pos = camera.transform.position; LightingManager2D manager = LightingManager2D.Get(); Max2D.DrawImage(manager.materials.GetAdditive(), new Vector2D(pos), new Vector2D(size), pos.z); }
public static void DrawPost(LightingMainBuffer2D buffer) { if (buffer.cameraSettings.renderMode != CameraSettings.RenderMode.Draw) { return; } if (Lighting2D.RenderingMode != RenderingMode.OnPostRender) { return; } LightingRender2D.PostRender(buffer); }
public bool InCamera() { Camera camera = LightingManager2D.Get().GetCamera(); float cameraSize = LightingMainBuffer2D.Get().cameraSize; if (camera == null) { return(false); } else { return(Vector2.Distance(transform.position, camera.transform.position) < Mathf.Sqrt((cameraSize * 2f) * (cameraSize * 2f)) + lightSize); } }
// Mesh-Render Mode Drawing static public void OnRender(LightingMainBuffer2D mainBuffer) { Camera camera = mainBuffer.cameraSettings.GetCamera(); if (camera == null) { return; } if (mainBuffer.cameraSettings.renderMode == CameraSettings.RenderMode.Disabled) { return; } if (Lighting2D.RenderingMode != RenderingMode.OnRender) { return; } OnRenderMode onRenderMode = OnRenderMode.Get(mainBuffer); if (onRenderMode == null) { return; } onRenderMode.UpdatePosition(); if (onRenderMode.meshRenderer != null) { if (mainBuffer.cameraSettings.renderMode == CameraSettings.RenderMode.Hidden) { onRenderMode.meshRenderer.enabled = false; return; } onRenderMode.meshRenderer.enabled = true; if (onRenderMode.meshRenderer.sharedMaterial != mainBuffer.GetMaterial()) { onRenderMode.meshRenderer.sharedMaterial = mainBuffer.GetMaterial(); } if (onRenderMode.meshRenderer.sharedMaterial == null) { onRenderMode.meshRenderer.sharedMaterial = mainBuffer.GetMaterial(); } } }
public void Initialize() { instance = this; transform.position = Vector3.zero; mainBuffer = LightingMainBuffer2D.Get(); fboManager = FBOManager.Get(); spriteAtlas = SpriteAtlasManager.Get(); meshRendererManager = MeshRendererManager.Get(); version = VERSION; }
public static void DrawOn(LightingMainBuffer2D buffer) { if (buffer.cameraSettings.renderMode != CameraSettings.RenderMode.Draw) { return; } switch (Lighting2D.RenderingMode) { case RenderingMode.OnRender: LightingRender2D.OnRender(buffer); break; case RenderingMode.OnPreRender: LightingRender2D.PreRender(buffer); break; } }
public bool Render_Check() { if (darknessBuffer == false) { return(false); } if (mainBuffer == null) { mainBuffer = LightingMainBuffer2D.Get(); return(false); } if (mainBuffer.bufferCamera == null) { return(false); } return(true); }
override public void OnInspectorGUI() { LightingManager2D script = target as LightingManager2D; script.enable = EditorGUILayout.Toggle("Enable", script.enable); EditorGUI.BeginDisabledGroup(script.enable == false); script.preset = (LightingManager2D.Preset)EditorGUILayout.EnumPopup("Preset", script.preset); Color newDarknessColor = EditorGUILayout.ColorField("Darkness Color", script.darknessColor); if (script.darknessColor.Equals(newDarknessColor) == false) { script.darknessColor = newDarknessColor; LightingMainBuffer2D.ForceUpdate(); } float newShadowDarkness = EditorGUILayout.Slider("Shadow Darkness", script.shadowDarkness, 0, 1); if (newShadowDarkness != script.shadowDarkness) { script.shadowDarkness = newShadowDarkness; LightingMainBuffer2D.ForceUpdate(); } float newSunDirection = EditorGUILayout.FloatField("Sun Rotation", script.sunDirection); if (newSunDirection != script.sunDirection) { script.sunDirection = newSunDirection; LightingMainBuffer2D.ForceUpdate(); } script.debug = EditorGUILayout.Toggle("Debug", script.debug); EditorGUI.EndDisabledGroup(); }
static public bool CameraSettings(LightingMainBuffer2D buffer) { LightingManager2D manager = LightingManager2D.Get(); int settingsID = buffer.cameraSettings.id; if (settingsID >= manager.cameraSettings.Length) { return(false); } CameraSettings cameraSetting = manager.cameraSettings[settingsID]; if (cameraSetting.Equals(buffer.cameraSettings) == false) { return(false); } buffer.cameraSettings.renderMode = cameraSetting.renderMode; return(true); }
// Graphics.Draw() Mode Drawing static public void PreRender(LightingMainBuffer2D mainBuffer) { Camera camera = mainBuffer.cameraSettings.GetCamera(); if (camera == null) { return; } if (mainBuffer.cameraSettings.renderMode == CameraSettings.RenderMode.Disabled) { return; } if (Lighting2D.RenderingMode != RenderingMode.OnPreRender) { return; } Graphics.DrawMesh(LightingRender2D.GetMesh(), Matrix4x4.TRS(LightingPosition.GetCameraPlanePosition(camera), camera.transform.rotation, GetSize(camera)), mainBuffer.GetMaterial(), 0, camera); }
void Start() { instance = this; // Lighting Materials additiveMaterial = new Material(Shader.Find("Particles/Additive")); //additiveMaterial.mainTexture = Resources.Load ("textures/additive") as Texture; penumbraMaterial = new Material(Shader.Find("Particles/Multiply")); penumbraMaterial.mainTexture = Resources.Load("textures/penumbra") as Texture; occlusionEdgeMaterial = new Material(Shader.Find("Particles/Multiply")); occlusionEdgeMaterial.mainTexture = Resources.Load("textures/occlusionedge") as Texture; shadowBlurMaterial = new Material(Shader.Find("Particles/Multiply")); shadowBlurMaterial.mainTexture = Resources.Load("textures/shadowedge") as Texture; transform.position = Vector3.zero; mainBuffer = LightingMainBuffer2D.Get(); }
static public void OnGUI() { if (timer == null) { LightingDebug.timer = TimerHelper.Create(); } if (timer.GetMillisecs() > 1000) { ShowLightBufferUpdates = LightBufferUpdates; LightBufferUpdates = 0; ShowLightMainBufferUpdates = LightMainBufferUpdates; LightMainBufferUpdates = 0; ShowLightMainCameraUpdates = LightMainCameraUpdates; LightMainCameraUpdates = 0; timer = TimerHelper.Create(); } ShowLightSourceDrawn = LightSourceDrawn; LightSourceDrawn = 0; GUI.Label(new Rect(10, 10, 200, 20), "Light Buffer Updates: " + ShowLightBufferUpdates); GUI.Label(new Rect(10, 30, 200, 20), "Light Main Buffer Updates: " + ShowLightMainBufferUpdates); GUI.Label(new Rect(10, 50, 200, 20), "Light Main Camera Updates: " + ShowLightMainCameraUpdates); GUI.Label(new Rect(10, 70, 200, 20), "Light Buffer Count: " + LightingBuffer2D.GetList().Count); GUI.Label(new Rect(10, 90, 200, 20), "Light Collider Count: " + LightingCollider2D.GetList().Count); Texture texture = LightingMainBuffer2D.Get().bufferCamera.activeTexture; GUI.Label(new Rect(10, 110, 200, 20), "Main Buffer Resolution: " + texture.width + "x" + texture.height); GUI.Label(new Rect(10, 130, 200, 20), "Light Sources Drawn: " + ShowLightSourceDrawn); }
static public Vector2Int GetScreenResolution(LightingMainBuffer2D buffer) { BufferPreset bufferPreset = buffer.GetBufferPreset(); if (bufferPreset == null) { return(Vector2Int.zero); } Camera camera = buffer.cameraSettings.GetCamera(); if (camera == null) { return(Vector2Int.zero); } float resolution = bufferPreset.lightingResolution; int screenWidth = (int)(camera.pixelRect.width * resolution); int screenHeight = (int)(camera.pixelRect.height * resolution); return(new Vector2Int(screenWidth, screenHeight)); }
public void Initialize(LightingMainBuffer2D mainBuffer) { gameObject.transform.parent = Buffers.Get().transform; meshRenderer = gameObject.AddComponent <MeshRenderer>(); meshRenderer.sharedMaterial = mainBuffer.GetMaterial(); BufferPreset bufferPreset = mainBuffer.GetBufferPreset(); bufferPreset.sortingLayer.ApplyToMeshRenderer(meshRenderer); // Disable Mesh Renderer Settings meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.receiveShadows = false; meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; meshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; meshRenderer.allowOcclusionWhenDynamic = false; UpdatePosition(); meshFilter = gameObject.AddComponent <MeshFilter>(); meshFilter.mesh = LightingRender2D.GetMesh(); }
static public LightingMainBuffer2D Get() { if (instance != null) { return(instance); } foreach (LightingMainBuffer2D mainBuffer in Object.FindObjectsOfType(typeof(LightingMainBuffer2D))) { instance = mainBuffer; return(instance); } GameObject setMainBuffer = new GameObject(); setMainBuffer.transform.parent = LightingManager2D.Get().transform; setMainBuffer.name = "Main Buffer"; setMainBuffer.layer = LightingManager2D.lightingLayer; instance = setMainBuffer.AddComponent <LightingMainBuffer2D> (); instance.Initialize(); return(instance); }
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; } if (id.colliderType == LightingCollider2D.ColliderType.Mesh) { continue; } List <Polygon2D> polygons = null; switch (id.colliderType) { case LightingCollider2D.ColliderType.Collider: polygons = id.GetColliderPolygons(); break; case LightingCollider2D.ColliderType.SpriteCustomPhysicsShape: polygons = id.GetShapePolygons(); break; } Polygon2D poly; Vector3 vecA; Vector3 vecB; Vector3 vecC; foreach (Polygon2D polygon in polygons) { poly = polygon.ToWorldSpace(id.gameObject.transform); Polygon2D convexHull = Polygon2D.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection, id.height); Mesh mesh = convexHull.CreateMesh(Vector2.zero, Vector2.zero); for (int i = 0; i < mesh.triangles.GetLength(0); i = i + 3) { vecA = mesh.vertices [mesh.triangles [i]]; vecB = mesh.vertices [mesh.triangles [i + 1]]; vecC = mesh.vertices [mesh.triangles [i + 2]]; Max2DMatrix.DrawTriangle(vecA.x, vecA.y, vecB.x, vecB.y, vecC.x, vecC.y, offset, z); } } } GL.End(); GL.PopMatrix(); GL.PushMatrix(); // Null Check? 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; } if (id.colliderType == LightingCollider2D.ColliderType.Mesh) { continue; } List <Polygon2D> polygons = null; switch (id.colliderType) { case LightingCollider2D.ColliderType.Collider: polygons = id.GetColliderPolygons(); break; case LightingCollider2D.ColliderType.SpriteCustomPhysicsShape: polygons = id.GetShapePolygons(); break; } foreach (Polygon2D polygon in polygons) { Polygon2D poly = polygon.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(); #if UNITY_2018_1_OR_NEWER GL.PushMatrix(); Max2D.defaultMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); GL.Color(Color.black); // Day Soft Shadows foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList()) { if (id.map == null) { continue; } if (id.dayHeight == false) { continue; } for (int x = 0; x < id.area.size.x; x++) { for (int y = 0; y < id.area.size.y; y++) { if (id.map[x, y] == null) { DrawSoftShadowTile(offset + new Vector2D(x, y), z, id.height); } } } } GL.End(); GL.PopMatrix(); GL.PushMatrix(); LightingManager2D.Get().shadowBlurMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); Max2D.SetColor(Color.white); // Day Soft Shadows foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList()) { if (id.map == null) { continue; } if (id.dayHeight == false) { continue; } for (int x = 0; x < id.area.size.x; x++) { for (int y = 0; y < id.area.size.y; y++) { if (id.map[x, y] == null) { DrawSoftShadowTileBlur(offset + new Vector2D(x, y), z, id.height); } } } } GL.End(); GL.PopMatrix(); #endif /* * * 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); * } */ 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.DrawImage(LightingManager2D.Get().additiveMaterial, new Vector2D(pos), new Vector2D(size), pos.z); // Day Lighting Masking foreach (LightingCollider2D id in LightingCollider2D.GetList()) { if (id.generateDayMask == false) { continue; } switch (id.maskType) { case LightingCollider2D.MaskType.SpriteCustomPhysicsShape: Max2D.SetColor(Color.white); Max2D.DrawMesh(Max2D.defaultMaterial, id.GetShapeMesh(), id.transform, offset, z); break; case LightingCollider2D.MaskType.Collider: Max2D.SetColor(Color.white); Max2D.DrawMesh(Max2D.defaultMaterial, id.GetColliderMesh(), id.transform, offset, z); break; case LightingCollider2D.MaskType.Sprite: if (id.spriteRenderer == null || id.spriteRenderer.sprite == null) { break; } Material material = LightingManager2D.Get().whiteSpriteMaterial; material.mainTexture = id.spriteRenderer.sprite.texture; Max2D.DrawSprite(material, id.spriteRenderer, new Vector2(id.transform.position.x, id.transform.position.y) + offset.ToVector2(), new Vector2(1, 1), id.transform.rotation.eulerAngles.z, z); break; } } }
override public void OnInspectorGUI() { LightingManager2D script = target as LightingManager2D; script.cameraType = (LightingManager2D.CameraType)EditorGUILayout.EnumPopup("Camera Type", script.cameraType); if (script.cameraType == LightingManager2D.CameraType.Custom) { script.customCamera = (Camera)EditorGUILayout.ObjectField(script.customCamera, typeof(Camera), true); } script.renderingMode = (LightingManager2D.RenderingMode)EditorGUILayout.EnumPopup("Rendering Mode", script.renderingMode); if (script.renderingMode == LightingManager2D.RenderingMode.OnRender) { foldout_sortingLayer = EditorGUILayout.Foldout(foldout_sortingLayer, "Sorting Layer"); if (foldout_sortingLayer) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; script.sortingLayerID = (int)EditorGUILayout.Slider("Sorting Layer ID", script.sortingLayerID, 0, 31); script.sortingLayerOrder = EditorGUILayout.IntField("Sorting Layer Order", script.sortingLayerOrder); script.sortingLayerName = EditorGUILayout.TextField("Sorting Layer Name", script.sortingLayerName); EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } } foldout_settings = EditorGUILayout.Foldout(foldout_settings, "Settings"); if (foldout_settings) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; Color newDarknessColor = EditorGUILayout.ColorField("Darkness Color", script.darknessColor); if (script.darknessColor.Equals(newDarknessColor) == false) { script.darknessColor = newDarknessColor; LightingMainBuffer2D.ForceUpdate(); } script.drawAdditiveLights = EditorGUILayout.Toggle("Draw Additive Lights", script.drawAdditiveLights); script.drawPenumbra = EditorGUILayout.Toggle("Draw Penumbra", script.drawPenumbra); script.drawRooms = EditorGUILayout.Toggle("Draw Rooms", script.drawRooms); script.drawOcclusion = EditorGUILayout.Toggle("Draw Occlusion", script.drawOcclusion); script.darknessBuffer = EditorGUILayout.Toggle("Draw Darkness Buffer", script.darknessBuffer); script.drawSceneView = EditorGUILayout.Toggle("Draw Scene View", script.drawSceneView); EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } foldout_lightingBuffers = EditorGUILayout.Foldout(foldout_lightingBuffers, "Lighting Buffers"); if (foldout_lightingBuffers) { script.lightingResolution = EditorGUILayout.Slider("Lighting Resolution", script.lightingResolution, 0.125f, 1.0f); script.textureFormat = (RenderTextureFormat)EditorGUILayout.EnumPopup("Light Texture Format", script.textureFormat); script.fixedLightBufferSize = EditorGUILayout.Toggle("Fixed Light Buffer", script.fixedLightBufferSize); if (script.fixedLightBufferSize) { script.fixedLightTextureSize = (LightingSourceTextureSize)EditorGUILayout.EnumPopup("Fixed Light Buffer Size", script.fixedLightTextureSize); script.lightingBufferPreload = EditorGUILayout.Toggle("Pre Load Lights", script.lightingBufferPreload); script.lightingBufferPreloadCount = (int)EditorGUILayout.Slider("Pre Load Count", script.lightingBufferPreloadCount, 1, 50); } else { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Fixed Light Buffer Size", script.fixedLightTextureSize); EditorGUILayout.Toggle("Pre Load Lights", script.lightingBufferPreload); EditorGUILayout.Slider("Pre Load Count", script.lightingBufferPreloadCount, 1, 50); EditorGUI.EndDisabledGroup(); } } foldout_daylighting = EditorGUILayout.Foldout(foldout_daylighting, "Day Lighting"); if (foldout_daylighting) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; // Day Lighting Settings EditorGUI.BeginDisabledGroup(true); script.preset = LightingManager2D.DayLightingPreset.Default; EditorGUILayout.EnumPopup("Preset", LightingManager2D.DayLightingPreset.Default); EditorGUI.EndDisabledGroup(); float newSunDirection = EditorGUILayout.FloatField("Sun Rotation", script.sunDirection); if (newSunDirection != script.sunDirection) { script.sunDirection = newSunDirection; LightingMainBuffer2D.ForceUpdate(); } script.drawDayShadows = EditorGUILayout.Toggle("Cast Shadows", script.drawDayShadows); float newShadowDarkness = EditorGUILayout.Slider("Shadow Darkness", script.shadowDarkness, 0, 1); if (newShadowDarkness != script.shadowDarkness) { script.shadowDarkness = newShadowDarkness; LightingMainBuffer2D.ForceUpdate(); } EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } foldout_lightingAtlas = EditorGUILayout.Foldout(foldout_lightingAtlas, "Lighting Atlas"); if (foldout_lightingAtlas) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; script.lightingSpriteAtlas = EditorGUILayout.Toggle("Enable Atlas", script.lightingSpriteAtlas); script.spriteAtlasScale = (SpriteAtlasScale)EditorGUILayout.EnumPopup("Sprites Scaling", script.spriteAtlasScale); script.spriteAtlasPreloadFoldersCount = EditorGUILayout.IntField("Folder Count", script.spriteAtlasPreloadFoldersCount); EditorGUI.indentLevel = EditorGUI.indentLevel + 1; for (int i = 0; i < script.spriteAtlasPreloadFoldersCount; i++) { if (script.spriteAtlasPreloadFolders.Length <= i) { System.Array.Resize(ref script.spriteAtlasPreloadFolders, i + 1); } // if (script.spriteAtlasPreloadFolders[i] == null) { // script.spriteAtlasPreloadFolders[i] = ""; //} script.spriteAtlasPreloadFolders[i] = EditorGUILayout.TextField("Folder (" + (i + 1) + ")", script.spriteAtlasPreloadFolders[i]); } EditorGUI.indentLevel = EditorGUI.indentLevel - 1; EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } script.debug = EditorGUILayout.Toggle("Debug", script.debug); script.disableEngine = EditorGUILayout.Toggle("Disable Engine", script.disableEngine); string buttonName = "Re-Initialize"; if (script.version < LightingManager2D.VERSION) { buttonName += " (Outdated)"; GUI.backgroundColor = Color.red; } if (GUILayout.Button(buttonName)) { if (script.mainBuffer != null && script.fboManager != null && script.meshRendererMode != null) { DestroyImmediate(script.mainBuffer.gameObject); DestroyImmediate(script.fboManager.gameObject); DestroyImmediate(script.meshRendererMode.gameObject); script.Initialize(); } else { DestroyImmediate(script.gameObject); LightingManager2D.Get(); } LightingMainBuffer2D.ForceUpdate(); } if (GUI.changed && EditorApplication.isPlaying == false) { if (target != null) { EditorUtility.SetDirty(target); } EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } }