diff --git a/scatterer/.vs/scatterer/v16/.suo b/scatterer/.vs/scatterer/v16/.suo index caa055df..88d88038 100644 Binary files a/scatterer/.vs/scatterer/v16/.suo and b/scatterer/.vs/scatterer/v16/.suo differ diff --git a/scatterer/Effects/SunFlare/SunFlare.cs b/scatterer/Effects/SunFlare/SunFlare.cs index f99aca3a..61dbc574 100644 --- a/scatterer/Effects/SunFlare/SunFlare.cs +++ b/scatterer/Effects/SunFlare/SunFlare.cs @@ -1,7 +1,7 @@ //rendering steps //scaledSpaceCamera.OnPrecull -> skynodes update the extinction texture one after one //camerahook on the relevant scaledSpace or farCamera -> clear the extinction texture before the next frame -// while taking care of keeping it around until the rendering has finished (either unifiedCamera or scaledCamera) +// while taking care of keeping it around until the rendering has finished (either nearCamera or scaledCamera) using UnityEngine; @@ -19,7 +19,7 @@ namespace scatterer { public class SunFlare : MonoBehaviour - { + { [Persistent] public string assetPath; @@ -30,21 +30,21 @@ public class SunFlare : MonoBehaviour public Transform sourceScaledTransform; Texture2D sunSpikes, sunFlare; - Texture2D sunGhost1,sunGhost2,sunGhost3; + Texture2D sunGhost1, sunGhost2, sunGhost3; public RenderTexture extinctionTexture; int waitBeforeReloadCnt = 0; - SunflareCameraHook unifiedCameraHook, scaledCameraHook; + SunflareCameraHook nearCameraHook, scaledCameraHook; - Vector3 sunViewPortPos=Vector3.zero; + Vector3 sunViewPortPos = Vector3.zero; RaycastHit hit; - bool hitStatus=false; - bool eclipse=false; + bool hitStatus = false; + bool eclipse = false; - float sunGlareScale=1; - float sunGlareFade=1; - float ghostFade=1; + float sunGlareScale = 1; + float sunGlareFade = 1; + float ghostFade = 1; Mesh screenMesh; GameObject sunflareGameObject; @@ -59,21 +59,21 @@ public class SunFlare : MonoBehaviour Vector3 flareSettings = Vector3.zero; [Persistent] Vector3 spikesSettings = Vector3.zero; - + [Persistent] - List ghost1SettingsList1=new List{}; + List ghost1SettingsList1 = new List { }; [Persistent] - List ghost1SettingsList2=new List{}; + List ghost1SettingsList2 = new List { }; [Persistent] - List ghost2SettingsList1=new List{}; + List ghost2SettingsList1 = new List { }; [Persistent] - List ghost2SettingsList2=new List{}; + List ghost2SettingsList2 = new List { }; [Persistent] - List ghost3SettingsList1=new List{}; + List ghost3SettingsList1 = new List { }; [Persistent] - List ghost3SettingsList2=new List{}; + List ghost3SettingsList2 = new List { }; [Persistent] public Vector3 flareColor = Vector3.one; @@ -81,137 +81,145 @@ public class SunFlare : MonoBehaviour public void start() { - LoadConfigNode (); + LoadConfigNode(); - sunglareMaterial = new Material (ShaderReplacer.Instance.LoadedShaders["Scatterer/sunFlare"]); - sunglareMaterial.SetOverrideTag ("IGNOREPROJECTOR", "True"); - sunglareMaterial.SetOverrideTag ("IgnoreProjector", "True"); + sunglareMaterial = new Material(ShaderReplacer.Instance.LoadedShaders["Scatterer/sunFlare"]); + sunglareMaterial.SetOverrideTag("IGNOREPROJECTOR", "True"); + sunglareMaterial.SetOverrideTag("IgnoreProjector", "True"); //Size is loaded automatically from the files - sunSpikes = new Texture2D (1, 1); - sunFlare = new Texture2D (1, 1); - sunGhost1 = new Texture2D (1, 1); - sunGhost2 = new Texture2D (1, 1); - sunGhost3 = new Texture2D (1, 1); - - sunSpikes.LoadImage (System.IO.File.ReadAllBytes (String.Format ("{0}/{1}", Utils.GameDataPath + assetPath, "sunSpikes.png"))); + sunSpikes = new Texture2D(1, 1); + sunFlare = new Texture2D(1, 1); + sunGhost1 = new Texture2D(1, 1); + sunGhost2 = new Texture2D(1, 1); + sunGhost3 = new Texture2D(1, 1); + + sunSpikes.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", Utils.GameDataPath + assetPath, "sunSpikes.png"))); sunSpikes.wrapMode = TextureWrapMode.Clamp; - sunFlare.LoadImage (System.IO.File.ReadAllBytes (String.Format ("{0}/{1}", Utils.GameDataPath + assetPath, "sunFlare.png"))); + sunFlare.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", Utils.GameDataPath + assetPath, "sunFlare.png"))); sunFlare.wrapMode = TextureWrapMode.Clamp; - sunGhost1.LoadImage (System.IO.File.ReadAllBytes (String.Format ("{0}/{1}", Utils.GameDataPath + assetPath, "Ghost1.png"))); + sunGhost1.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", Utils.GameDataPath + assetPath, "Ghost1.png"))); sunGhost1.wrapMode = TextureWrapMode.Clamp; - sunGhost2.LoadImage (System.IO.File.ReadAllBytes (String.Format ("{0}/{1}", Utils.GameDataPath + assetPath, "Ghost2.png"))); + sunGhost2.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", Utils.GameDataPath + assetPath, "Ghost2.png"))); sunGhost2.wrapMode = TextureWrapMode.Clamp; - sunGhost3.LoadImage (System.IO.File.ReadAllBytes (String.Format ("{0}/{1}", Utils.GameDataPath + assetPath, "Ghost3.png"))); + sunGhost3.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", Utils.GameDataPath + assetPath, "Ghost3.png"))); sunGhost3.wrapMode = TextureWrapMode.Clamp; -// sunglareMaterial.SetTexture ("_Sun_Glare", sunGlare); - sunglareMaterial.SetTexture ("sunSpikes", sunSpikes); - sunglareMaterial.SetTexture ("sunFlare", sunFlare); - sunglareMaterial.SetTexture ("sunGhost1", sunGhost1); - sunglareMaterial.SetTexture ("sunGhost2", sunGhost2); - sunglareMaterial.SetTexture ("sunGhost3", sunGhost3); + // sunglareMaterial.SetTexture ("_Sun_Glare", sunGlare); + sunglareMaterial.SetTexture("sunSpikes", sunSpikes); + sunglareMaterial.SetTexture("sunFlare", sunFlare); + sunglareMaterial.SetTexture("sunGhost1", sunGhost1); + sunglareMaterial.SetTexture("sunGhost2", sunGhost2); + sunglareMaterial.SetTexture("sunGhost3", sunGhost3); - if (!(HighLogic.LoadedScene == GameScenes.TRACKSTATION)) - sunglareMaterial.SetTexture ("_customDepthTexture", Scatterer.Instance.bufferManager.depthTexture); + if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && !(MapView.MapIsEnabled)) + sunglareMaterial.SetTexture("_customDepthTexture", Scatterer.Instance.bufferManager.depthTexture); else - sunglareMaterial.SetTexture ("_customDepthTexture", Texture2D.whiteTexture); + sunglareMaterial.SetTexture("_customDepthTexture", Texture2D.whiteTexture); sunglareMaterial.renderQueue = 3100; - screenMesh = MeshFactory.MakePlane (2, 2, MeshFactory.PLANE.XY, false, false); - screenMesh.bounds = new Bounds (Vector4.zero, new Vector3 (Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); + screenMesh = MeshFactory.MakePlane(2, 2, MeshFactory.PLANE.XY, false, false); + screenMesh.bounds = new Bounds(Vector4.zero, new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); - sunflareGameObject = new GameObject (); + sunflareGameObject = new GameObject(); MeshFilter sunflareGameObjectMeshFilter; - if (sunflareGameObject.GetComponent ()) - sunflareGameObjectMeshFilter = sunflareGameObject.GetComponent (); + if (sunflareGameObject.GetComponent()) + sunflareGameObjectMeshFilter = sunflareGameObject.GetComponent(); else sunflareGameObjectMeshFilter = sunflareGameObject.AddComponent(); - - sunflareGameObjectMeshFilter.mesh.Clear (); + + sunflareGameObjectMeshFilter.mesh.Clear(); sunflareGameObjectMeshFilter.mesh = screenMesh; - + MeshRenderer sunflareGameObjectMeshRenderer; - if (sunflareGameObject.GetComponent ()) - sunflareGameObjectMeshRenderer = sunflareGameObject.GetComponent (); + if (sunflareGameObject.GetComponent()) + sunflareGameObjectMeshRenderer = sunflareGameObject.GetComponent(); else sunflareGameObjectMeshRenderer = sunflareGameObject.AddComponent(); - + sunflareGameObjectMeshRenderer.sharedMaterial = sunglareMaterial; sunflareGameObjectMeshRenderer.material = sunglareMaterial; - + sunflareGameObjectMeshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; sunflareGameObjectMeshRenderer.receiveShadows = false; sunflareGameObjectMeshRenderer.enabled = true; - + sunflareGameObject.layer = 10; //start in scaledspace //didn't want to serialize the matrices directly as the result is pretty unreadable //sorry about the mess, I'll make a cleaner way later //ghost 1 Matrix4x4 ghost1Settings1 = Matrix4x4.zero; - for (int i=0; i 1.25*sunglareFadeDistance -->1 //if dist < 0.25*sunglareFadeDistance -->0 //else values smoothstepped in between - sunGlareFade = Mathf.SmoothStep(0,1,(dist/sunGlareFadeDistance)-0.25f); + sunGlareFade = Mathf.SmoothStep(0, 1, (dist / sunGlareFadeDistance) - 0.25f); //if dist < 0.5 * ghostFadeDistance -->1 //if dist > 1.5 * ghostFadeDistance -->0 //else values smoothstepped in between - ghostFade = Mathf.SmoothStep(0,1,(dist-0.5f*ghostFadeDistance)/(ghostFadeDistance)); + ghostFade = Mathf.SmoothStep(0, 1, (dist - 0.5f * ghostFadeDistance) / ghostFadeDistance); ghostFade = 1 - ghostFade; - hitStatus=false; - if (!MapView.MapIsEnabled && !(HighLogic.LoadedScene == GameScenes.TRACKSTATION)) - //if (!MapView.MapIsEnabled) + hitStatus = false; + //if (!MapView.MapIsEnabled && !(HighLogic.LoadedScene == GameScenes.TRACKSTATION)) + if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && !(MapView.MapIsEnabled)) { - - hitStatus = Physics.Raycast (Scatterer.Instance.ReturnProperCamera(true, false).transform.position, - (source.transform.position- Scatterer.Instance.ReturnProperCamera(false, false).transform.position).normalized, - out hit, Mathf.Infinity, (int)((1 << 15) + (1 << 0))); - if(!hitStatus) + + hitStatus = Physics.Raycast(Scatterer.Instance.ReturnProperCamera(true, false).transform.position, + (source.transform.position - Scatterer.Instance.ReturnProperCamera(true,false).transform.position).normalized, + out hit, Mathf.Infinity, (int)((1 << 15) + (1 << 0))); + if (!hitStatus) { - hitStatus = Physics.Raycast (Scatterer.Instance.scaledSpaceCamera.transform.position, - (ScaledSpace.LocalToScaledSpace(source.transform.position)- Scatterer.Instance.scaledSpaceCamera.transform.position) - .normalized,out hit, Mathf.Infinity, (int)((1 << 10))); + hitStatus = Physics.Raycast(Scatterer.Instance.scaledSpaceCamera.transform.position, + (ScaledSpace.LocalToScaledSpace(source.transform.position) - Scatterer.Instance.scaledSpaceCamera.transform.position) + .normalized, out hit, Mathf.Infinity, (int)(1 << 10)); } } else { - hitStatus = Physics.Raycast (Scatterer.Instance.scaledSpaceCamera.transform.position, (ScaledSpace.LocalToScaledSpace(source.transform.position) - - Scatterer.Instance.transform.position).normalized,out hit, Mathf.Infinity, (int)((1 << 10))); + hitStatus = Physics.Raycast(Scatterer.Instance.scaledSpaceCamera.transform.position, (ScaledSpace.LocalToScaledSpace(source.transform.position) + - Scatterer.Instance.transform.position).normalized, out hit, Mathf.Infinity, (int)(1 << 10)); } - if(hitStatus) + if (hitStatus) { //if sun visible, draw sunflare - if(hit.transform == sourceScaledTransform) - hitStatus=false; + if (hit.transform == sourceScaledTransform) + hitStatus = false; } eclipse = hitStatus; - sunglareMaterial.SetFloat("renderSunFlare", (!eclipse && (sunViewPortPos.z > 0) && !Scatterer.Instance.scattererCelestialBodiesManager.underwater ) ? 1.0f : 0.0f); + sunglareMaterial.SetFloat("renderSunFlare", (!eclipse && (sunViewPortPos.z > 0) && !Scatterer.Instance.scattererCelestialBodiesManager.underwater) ? 1.0f : 0.0f); - sunglareMaterial.SetVector ("sunViewPortPos", sunViewPortPos); - sunglareMaterial.SetFloat ("aspectRatio", Scatterer.Instance.scaledSpaceCamera.aspect); - sunglareMaterial.SetFloat ("sunGlareScale", sunGlareScale); - sunglareMaterial.SetFloat ("sunGlareFade", sunGlareFade); - sunglareMaterial.SetFloat ("ghostFade", ghostFade); + sunglareMaterial.SetVector("sunViewPortPos", sunViewPortPos); + sunglareMaterial.SetFloat("aspectRatio", Scatterer.Instance.scaledSpaceCamera.aspect); + sunglareMaterial.SetFloat("sunGlareScale", sunGlareScale); + sunglareMaterial.SetFloat("sunGlareFade", sunGlareFade); + sunglareMaterial.SetFloat("ghostFade", ghostFade); - if (!(HighLogic.LoadedScene == GameScenes.TRACKSTATION)) - sunglareMaterial.SetTexture ("_customDepthTexture", Scatterer.Instance.bufferManager.depthTexture); - } + if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && !(MapView.MapIsEnabled)) + sunglareMaterial.SetTexture("_customDepthTexture", Scatterer.Instance.bufferManager.depthTexture); + } public void Update() { @@ -289,53 +297,68 @@ public void Update() waitBeforeReloadCnt = 0; } } - unifiedCameraHook.enabled = true; - sunflareGameObject.layer = 10; + //enable or disable scaled or near script depending on trackstation or mapview + //if (!MapView.MapIsEnabled && !(HighLogic.LoadedScene == GameScenes.TRACKSTATION)) + if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && !(MapView.MapIsEnabled)) + { + nearCameraHook.enabled = true; + scaledCameraHook.enabled = false; + sunflareGameObject.layer = 15; + } + else + { + if (nearCameraHook) + nearCameraHook.enabled = false; + + scaledCameraHook.enabled = true; + sunflareGameObject.layer = 10; + } } public void ClearExtinction() { - RenderTexture rt=RenderTexture.active; - RenderTexture.active= extinctionTexture; + RenderTexture rt = RenderTexture.active; + RenderTexture.active = extinctionTexture; - GL.Clear(false,true,Color.white); + GL.Clear(false, true, Color.white); //restore active rendertexture - RenderTexture.active=rt; - } + RenderTexture.active = rt; + } public void CleanUp() { - if (unifiedCameraHook) + if (nearCameraHook) { - Component.Destroy (unifiedCameraHook); - UnityEngine.Object.Destroy (unifiedCameraHook); + Component.Destroy(nearCameraHook); + UnityEngine.Object.Destroy(nearCameraHook); } if (scaledCameraHook) { Component.Destroy(scaledCameraHook); UnityEngine.Object.Destroy(scaledCameraHook); } - if (extinctionTexture) + + if (extinctionTexture) { extinctionTexture.Release(); - UnityEngine.Object.Destroy (extinctionTexture); + UnityEngine.Object.Destroy(extinctionTexture); } } - public void LoadConfigNode () + public void LoadConfigNode() { - ConfigNode cnToLoad = new ConfigNode (); + ConfigNode cnToLoad = new ConfigNode(); foreach (ConfigNode _cn in Scatterer.Instance.planetsConfigsReader.sunflareConfigs) { if (_cn.TryGetNode(sourceName, ref cnToLoad)) { - Utils.LogDebug("Sunflare config found for "+sourceName); + Utils.LogDebug("Sunflare config found for " + sourceName); break; } - } - ConfigNode.LoadObjectFromConfig (this, cnToLoad); + } + ConfigNode.LoadObjectFromConfig(this, cnToLoad); } public void Configure(CelestialBody source, string sourceName, Transform sourceScaledTransform) diff --git a/scatterer/Scatterer.cs b/scatterer/Scatterer.cs index 066b32c7..1f0e141e 100644 --- a/scatterer/Scatterer.cs +++ b/scatterer/Scatterer.cs @@ -47,7 +47,7 @@ public partial class Scatterer : MonoBehaviour bool coreInitiated = false; public bool isActive = false; - public string versionNumber = "0.055_UFCRTBDEV_RC1_1_50"; + public string versionNumber = "0.055_UFCRTBDEV_UR_1_50"; void Awake() {