public virtual void UpdateNode() { if ((m_manager.m_skyNode.farCamera)) { if (!oceanupdater) { oceanupdater = (OceanUpdateAtCameraRythm)m_manager.m_skyNode.farCamera.gameObject.AddComponent(typeof(OceanUpdateAtCameraRythm)); oceanupdater.m_oceanNode = this; oceanupdater.farCamera = m_manager.m_skyNode.farCamera; oceanupdater.nearCamera = m_manager.m_skyNode.nearCamera; oceanupdater.oceanMaterialFar = m_oceanMaterialFar; // oceanupdater.oceanMaterialNear = m_oceanMaterialNear; oceanupdater.m_manager = m_manager; } } m_drawOcean = m_manager.m_skyNode.trueAlt < fakeOceanAltitude; if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && m_drawOcean) { // foreach (Mesh mesh in m_screenGrids) // { // // Graphics.DrawMesh (mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15, // m_manager.m_skyNode.farCamera, 0, null, false, false); // // Graphics.DrawMesh (mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15, // m_manager.m_skyNode.nearCamera, 0, null, false, false); // // } } // m_oceanMaterialNear.renderQueue = m_manager.Core.Instance.oceanRenderQueue; m_oceanMaterialFar.renderQueue = Core.Instance.oceanRenderQueue; }
public virtual void UpdateNode() { if ((m_manager.m_skyNode.farCamera)) { if (!oceanupdater) { oceanupdater = (OceanUpdateAtCameraRythm)m_manager.m_skyNode.farCamera.gameObject.AddComponent(typeof(OceanUpdateAtCameraRythm)); oceanupdater.m_oceanNode = this; oceanupdater.farCamera = m_manager.m_skyNode.farCamera; oceanupdater.nearCamera = m_manager.m_skyNode.nearCamera; oceanupdater.oceanMaterialFar = m_oceanMaterialFar; oceanupdater.oceanMaterialNear = m_oceanMaterialNear; oceanupdater.m_manager = m_manager; } } m_drawOcean = m_manager.m_skyNode.trueAlt < fakeOceanAltitude; // if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && (m_manager.m_skyNode.trueAlt < fakeOceanAltitude)) { if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && m_drawOcean) { foreach (Mesh mesh in m_screenGrids) { // Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15, m_manager.m_skyNode.farCamera); // Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15, m_manager.m_skyNode.nearCamera); Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15, m_manager.m_skyNode.farCamera, 0, null, false, false); Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15, m_manager.m_skyNode.nearCamera, 0, null, false, false); } // Graphics.DrawMesh (fakeOceanMesh, Vector3.zero, Quaternion.identity, newMat, 15, // m_manager.m_skyNode.farCamera, 0, null, false, false); } if (!ocean && stockOceanExists) { PQS pqs = m_manager.parentCelestialBody.pqsController; // //// Debug.Log("PQS.childspheres count"+pqs.ChildSpheres.Length); // // // Debug.Log ("childspheres length"+pqs.ChildSpheres.Length.ToString()); if (pqs.ChildSpheres [0]) { // Debug.Log("pqs.ChildSpheres [0] found"); ocean = pqs.ChildSpheres [0]; emptyMaterial = new Material(ShaderTool.GetMatFromShader2("EmptyShader.shader")); // fakeOceanMaterial = new Material (ShaderTool.GetMatFromShader2 ("CompiledFakeOcean.shader")); // m_manager.m_skyNode.InitUniforms(fakeOceanMaterial); // m_manager.m_skyNode.InitPostprocessMaterial(fakeOceanMaterial); // Debug.Log ("fake ocean mat set"); ocean.surfaceMaterial = emptyMaterial; ocean.fallbackMaterial = emptyMaterial; // ocean.surfaceMaterial = fakeOceanMaterial; // ocean.fallbackMaterial = fakeOceanMaterial; ocean.useSharedMaterial = false; // oceanPC = new SimplePostProcessCube (20000, fakeOceanMaterial); // fakeOceanObject = oceanPC.GameObject; // fakeOceanObject.layer = 15; // fakeOceanMR = oceanPC.GameObject.GetComponent < MeshRenderer > (); // fakeOceanMR.material = fakeOceanMaterial; // oceanPC.GameObject.GetComponent < MeshFilter > ().mesh.Clear(); // oceanPC.GameObject.GetComponent < MeshFilter > ().mesh = isosphere.Create(10000); // // ///Thanks to rbray89 for this snippet that disables the stock ocean in a clean way // GameObject container = ocean.gameObject; // // FakeOceanPQS fakeOcean1 = new GameObject().AddComponent<FakeOceanPQS>(); // // fakeOcean1.CloneFrom(ocean); // Destroy(ocean); // // FakeOceanPQS fakeOcean = container.AddComponent<FakeOceanPQS>(); // fakeOcean.CloneFrom(fakeOcean1); // // Destroy(fakeOcean1); // // FieldInfo field = typeof(PQS).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First( // f => f.FieldType == typeof(PQS[])); // field.SetValue(pqs, new PQS[] {fakeOcean }); // // PQSMod_CelestialBodyTransform cbt = pqs.GetComponentsInChildren<PQSMod_CelestialBodyTransform>()[0]; // cbt.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[] { }; stockOceanExists = false; } else { stockOceanExists = false; Debug.Log("[Scatterer] Stock ocean doesn't exist for " + m_manager.parentCelestialBody.name); } } if (ocean) { ocean.surfaceMaterial = emptyMaterial; ocean.fallbackMaterial = emptyMaterial; ocean.useSharedMaterial = false; // ocean.surfaceMaterial = fakeOceanMaterial; // ocean.fallbackMaterial = fakeOceanMaterial; // ocean.useSharedMaterial = false; // fakeOceanMaterial.SetVector ("_planetPos", m_manager.parentCelestialBody.transform.position); // fakeOceanMaterial.SetVector ("_cameraPos", m_manager.GetCore().farCamera.transform.position - m_manager.parentCelestialBody.transform.position); // fakeOceanMaterial.SetVector ("_Ocean_Color", new Color (m_oceanUpwellingColor.x, m_oceanUpwellingColor.y, m_oceanUpwellingColor.z) * 0.1f); // fakeOceanMaterial.SetFloat ("_Ocean_Sigma", GetMaxSlopeVariance ()); //// fakeOceanMaterial.SetMatrix ("_PlanetToWorld", m_manager.parentCelestialBody.transform.localToWorldMatrix); // // // // // //// fakeOceanMaterial.SetMatrix ("_PlanetToWorld", camToLocal.ToMatrix4x4()); // fakeOceanMaterial.SetMatrix ("_WorldToPlanet", m_manager.parentCelestialBody.transform.worldToLocalMatrix); // // //// fakeOceanMaterial.SetVector ("SUN_DIR", m_manager.GetSunNodeDirection ()); // m_manager.m_skyNode.SetUniforms(fakeOceanMaterial); // m_manager.m_skyNode.InitPostprocessMaterial(fakeOceanMaterial); // m_manager.m_skyNode.UpdatePostProcessMaterial(fakeOceanMaterial); // // // fakeOceanObject.transform.position= FlightGlobals.ActiveVessel.transform.position; } m_oceanMaterialNear.renderQueue = m_manager.GetCore().oceanRenderQueue; m_oceanMaterialFar.renderQueue = m_manager.GetCore().oceanRenderQueue; if (stockOceanExists) { //This causes problems later on // ocean.quadAllowBuild = false; // int deletedQuads=ocean.quads.Length; // // if (deletedQuads>0){ // // for (int i=0;i<ocean.quads.Length;i++) // { // if (ocean.quads[i]) // UnityEngine.Object.Destroy(ocean.quads[i]); // } // // ocean.quads = Array.FindAll(ocean.quads, PQisNotNull); //// deletedQuads-=ocean.quads.Length; // // Debug.Log("[Scatterer] Destroyed "+deletedQuads.ToString()+" stock ocean quads on " // +m_manager.parentCelestialBody.name); // // } // ocean.quads= new PQ[10]; // ocean.DeactivateSphere(); // ocean.DisableSphere(); // ocean.surfaceMaterial=new Material(ShaderTool.GetMatFromShader2("EmptyShader.shader")); // Debug.Log("ocean.subdivisionThreshold"+ ocean.subdivisionThreshold.ToString()); // Debug.Log("ocean.maxDetailDistance"+ ocean.maxDetailDistance.ToString()); } // //// ocean.quadAllowBuild=false; // Debug.Log("ocean.visRad"+ ocean.visRad); // Debug.Log("ocean.visibleRadius"+ ocean.visibleRadius.ToString()); // Debug.Log("ocean.visibleAltitude"+ ocean.visibleAltitude.ToString()); //// Debug.Log("ocean.useSharedMaterial"+ ocean.useSharedMaterial.ToString()); //// Debug.Log("ocean.surfaceMaterial"+ ocean.surfaceMaterial.ToString()); // Debug.Log("ocean.subdivisionThresholds"+ ocean.subdivisionThresholds.ToString()); // Debug.Log("ocean.subdivisionThreshold"+ ocean.subdivisionThreshold.ToString()); //// Debug.Log("ocean.radiusMi"+ ocean.radiusMin.ToString()); //// Debug.Log("ocean.radiusMax"+ ocean.radiusMax.ToString()); //// Debug.Log("ocean.quadAllowBuild"+ ocean.quadAllowBuild.ToString()); // Debug.Log("ocean.maxDetailDistance"+ ocean.maxDetailDistance.ToString()); // Debug.Log("ocean.detailAltitudeMax"+ ocean.detailAltitudeMax.ToString()); //// } // ocean.isDisabled = true; // ocean.DisableSphere (); // ocean.isDisabled = !m_core.stockOcean; // // if (!m_core.stockOcean) // { // ocean.DisableSphere (); // } // else // { // ocean.EnableSphere (); // } // for(int i = 0; i < numGrids; i++) // { // waterMeshRenderersNear[i].enabled=!m_core.stockOcean && !MapView.MapIsEnabled; // waterMeshRenderersFar[i].enabled=!m_core.stockOcean && !MapView.MapIsEnabled ; // } }
public virtual void UpdateNode () { if ((m_manager.m_skyNode.farCamera)) { if (!oceanupdater) { oceanupdater = (OceanUpdateAtCameraRythm)m_manager.m_skyNode.farCamera.gameObject.AddComponent (typeof(OceanUpdateAtCameraRythm)); oceanupdater.m_oceanNode = this; oceanupdater.farCamera = m_manager.m_skyNode.farCamera; oceanupdater.nearCamera = m_manager.m_skyNode.nearCamera; oceanupdater.oceanMaterialFar = m_oceanMaterialFar; oceanupdater.oceanMaterialNear = m_oceanMaterialNear; oceanupdater.m_manager = m_manager; } } m_drawOcean = m_manager.m_skyNode.trueAlt < fakeOceanAltitude; // if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && (m_manager.m_skyNode.trueAlt < fakeOceanAltitude)) { if (!MapView.MapIsEnabled && !m_core.stockOcean && !m_manager.m_skyNode.inScaledSpace && m_drawOcean) { foreach (Mesh mesh in m_screenGrids) { // Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15, m_manager.m_skyNode.farCamera); // Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15, m_manager.m_skyNode.nearCamera); Graphics.DrawMesh (mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialFar, 15, m_manager.m_skyNode.farCamera, 0, null, false, false); Graphics.DrawMesh (mesh, Vector3.zero, Quaternion.identity, m_oceanMaterialNear, 15, m_manager.m_skyNode.nearCamera, 0, null, false, false); } // Graphics.DrawMesh (fakeOceanMesh, Vector3.zero, Quaternion.identity, newMat, 15, // m_manager.m_skyNode.farCamera, 0, null, false, false); } if (!ocean && stockOceanExists) { PQS pqs = m_manager.parentCelestialBody.pqsController; // //// Debug.Log("PQS.childspheres count"+pqs.ChildSpheres.Length); // // // Debug.Log ("childspheres length"+pqs.ChildSpheres.Length.ToString()); if (pqs.ChildSpheres [0]) { // Debug.Log("pqs.ChildSpheres [0] found"); ocean = pqs.ChildSpheres [0]; emptyMaterial = new Material (ShaderTool.GetMatFromShader2 ("EmptyShader.shader")); // fakeOceanMaterial = new Material (ShaderTool.GetMatFromShader2 ("CompiledFakeOcean.shader")); // m_manager.m_skyNode.InitUniforms(fakeOceanMaterial); // m_manager.m_skyNode.InitPostprocessMaterial(fakeOceanMaterial); // Debug.Log ("fake ocean mat set"); ocean.surfaceMaterial = emptyMaterial; ocean.fallbackMaterial = emptyMaterial; // ocean.surfaceMaterial = fakeOceanMaterial; // ocean.fallbackMaterial = fakeOceanMaterial; ocean.useSharedMaterial=false; // oceanPC = new SimplePostProcessCube (20000, fakeOceanMaterial); // fakeOceanObject = oceanPC.GameObject; // fakeOceanObject.layer = 15; // fakeOceanMR = oceanPC.GameObject.GetComponent < MeshRenderer > (); // fakeOceanMR.material = fakeOceanMaterial; // oceanPC.GameObject.GetComponent < MeshFilter > ().mesh.Clear(); // oceanPC.GameObject.GetComponent < MeshFilter > ().mesh = isosphere.Create(10000); // // ///Thanks to rbray89 for this snippet that disables the stock ocean in a clean way // GameObject container = ocean.gameObject; // // FakeOceanPQS fakeOcean1 = new GameObject().AddComponent<FakeOceanPQS>(); // // fakeOcean1.CloneFrom(ocean); // Destroy(ocean); // // FakeOceanPQS fakeOcean = container.AddComponent<FakeOceanPQS>(); // fakeOcean.CloneFrom(fakeOcean1); // // Destroy(fakeOcean1); // // FieldInfo field = typeof(PQS).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First( // f => f.FieldType == typeof(PQS[])); // field.SetValue(pqs, new PQS[] {fakeOcean }); // // PQSMod_CelestialBodyTransform cbt = pqs.GetComponentsInChildren<PQSMod_CelestialBodyTransform>()[0]; // cbt.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[] { }; stockOceanExists = false; } else { stockOceanExists = false; Debug.Log ("[Scatterer] Stock ocean doesn't exist for " + m_manager.parentCelestialBody.name); } } if (ocean) { ocean.surfaceMaterial = emptyMaterial; ocean.fallbackMaterial = emptyMaterial; ocean.useSharedMaterial = false; // ocean.surfaceMaterial = fakeOceanMaterial; // ocean.fallbackMaterial = fakeOceanMaterial; // ocean.useSharedMaterial = false; // fakeOceanMaterial.SetVector ("_planetPos", m_manager.parentCelestialBody.transform.position); // fakeOceanMaterial.SetVector ("_cameraPos", m_manager.GetCore().farCamera.transform.position - m_manager.parentCelestialBody.transform.position); // fakeOceanMaterial.SetVector ("_Ocean_Color", new Color (m_oceanUpwellingColor.x, m_oceanUpwellingColor.y, m_oceanUpwellingColor.z) * 0.1f); // fakeOceanMaterial.SetFloat ("_Ocean_Sigma", GetMaxSlopeVariance ()); //// fakeOceanMaterial.SetMatrix ("_PlanetToWorld", m_manager.parentCelestialBody.transform.localToWorldMatrix); // // // // // //// fakeOceanMaterial.SetMatrix ("_PlanetToWorld", camToLocal.ToMatrix4x4()); // fakeOceanMaterial.SetMatrix ("_WorldToPlanet", m_manager.parentCelestialBody.transform.worldToLocalMatrix); // // //// fakeOceanMaterial.SetVector ("SUN_DIR", m_manager.GetSunNodeDirection ()); // m_manager.m_skyNode.SetUniforms(fakeOceanMaterial); // m_manager.m_skyNode.InitPostprocessMaterial(fakeOceanMaterial); // m_manager.m_skyNode.UpdatePostProcessMaterial(fakeOceanMaterial); // // // fakeOceanObject.transform.position= FlightGlobals.ActiveVessel.transform.position; } m_oceanMaterialNear.renderQueue = m_manager.GetCore ().oceanRenderQueue; m_oceanMaterialFar.renderQueue=m_manager.GetCore ().oceanRenderQueue; if (stockOceanExists) { //This causes problems later on // ocean.quadAllowBuild = false; // int deletedQuads=ocean.quads.Length; // // if (deletedQuads>0){ // // for (int i=0;i<ocean.quads.Length;i++) // { // if (ocean.quads[i]) // UnityEngine.Object.Destroy(ocean.quads[i]); // } // // ocean.quads = Array.FindAll(ocean.quads, PQisNotNull); //// deletedQuads-=ocean.quads.Length; // // Debug.Log("[Scatterer] Destroyed "+deletedQuads.ToString()+" stock ocean quads on " // +m_manager.parentCelestialBody.name); // // } // ocean.quads= new PQ[10]; // ocean.DeactivateSphere(); // ocean.DisableSphere(); // ocean.surfaceMaterial=new Material(ShaderTool.GetMatFromShader2("EmptyShader.shader")); // Debug.Log("ocean.subdivisionThreshold"+ ocean.subdivisionThreshold.ToString()); // Debug.Log("ocean.maxDetailDistance"+ ocean.maxDetailDistance.ToString()); } // //// ocean.quadAllowBuild=false; // Debug.Log("ocean.visRad"+ ocean.visRad); // Debug.Log("ocean.visibleRadius"+ ocean.visibleRadius.ToString()); // Debug.Log("ocean.visibleAltitude"+ ocean.visibleAltitude.ToString()); //// Debug.Log("ocean.useSharedMaterial"+ ocean.useSharedMaterial.ToString()); //// Debug.Log("ocean.surfaceMaterial"+ ocean.surfaceMaterial.ToString()); // Debug.Log("ocean.subdivisionThresholds"+ ocean.subdivisionThresholds.ToString()); // Debug.Log("ocean.subdivisionThreshold"+ ocean.subdivisionThreshold.ToString()); //// Debug.Log("ocean.radiusMi"+ ocean.radiusMin.ToString()); //// Debug.Log("ocean.radiusMax"+ ocean.radiusMax.ToString()); //// Debug.Log("ocean.quadAllowBuild"+ ocean.quadAllowBuild.ToString()); // Debug.Log("ocean.maxDetailDistance"+ ocean.maxDetailDistance.ToString()); // Debug.Log("ocean.detailAltitudeMax"+ ocean.detailAltitudeMax.ToString()); //// } // ocean.isDisabled = true; // ocean.DisableSphere (); // ocean.isDisabled = !m_core.stockOcean; // // if (!m_core.stockOcean) // { // ocean.DisableSphere (); // } // else // { // ocean.EnableSphere (); // } // for(int i = 0; i < numGrids; i++) // { // waterMeshRenderersNear[i].enabled=!m_core.stockOcean && !MapView.MapIsEnabled; // waterMeshRenderersFar[i].enabled=!m_core.stockOcean && !MapView.MapIsEnabled ; // } }