示例#1
0
        //Initialization
        public void Start()
        {
            m_radius = m_manager.GetRadius();

            Rt = (Rt / Rg) * m_radius;
            RL = (RL / Rg) * m_radius;
            Rg = m_radius;

            m_mesh = MeshFactory.MakePlane(2, 2, MeshFactory.PLANE.XY, false, false);
            m_mesh.bounds = new Bounds(parentCelestialBody.transform.position, new Vector3(1e8f, 1e8f, 1e8f));

            //Inscatter is responsible for the change in the sky color as the sun moves
            //The raw file is a 4D array of 32 bit floats with a range of 0 to 1.589844
            //As there is not such thing as a 4D texture the data is packed into a 3D texture
            //and the shader manually performs the sample for the 4th dimension
            m_inscatter = new RenderTexture(RES_MU_S * RES_NU, RES_MU * RES_R, 0, RenderTextureFormat.ARGBHalf);
            m_inscatter.wrapMode = TextureWrapMode.Clamp;
            m_inscatter.filterMode = FilterMode.Bilinear;

            //Transmittance is responsible for the change in the sun color as it moves
            //The raw file is a 2D array of 32 bit floats with a range of 0 to 1
            m_transmit = new RenderTexture(TRANSMITTANCE_W, TRANSMITTANCE_H, 0, RenderTextureFormat.ARGBHalf);
            m_transmit.wrapMode = TextureWrapMode.Clamp;
            m_transmit.filterMode = FilterMode.Bilinear;

            //Irradiance is responsible for the change in the sky color as the sun moves
            //The raw file is a 2D array of 32 bit floats with a range of 0 to 1
            m_irradiance = new RenderTexture(SKY_W, SKY_H, 0, RenderTextureFormat.ARGBHalf);
            m_irradiance.wrapMode = TextureWrapMode.Clamp;
            m_irradiance.filterMode = FilterMode.Bilinear;

            initiateOrRestart();
            m_skyMaterialScaled = new Material(ShaderTool.GetMatFromShader2("CompiledSkyScaled.shader"));
            m_skyMaterialScaled.renderQueue = 2004;

            m_skyExtinction = new Material(ShaderTool.GetMatFromShader2("CompiledSkyExtinction.shader"));
            m_skyExtinction.renderQueue = 2002;

            sunGlare = new Texture2D(512, 512);
            black = new Texture2D(512, 512);

            //			string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            //			UriBuilder uri = new UriBuilder(codeBase);
            //			path = Uri.UnescapeDataString(uri.Path);
            //			path=Path.GetDirectoryName (path);
            path = m_manager.GetCore().path;

            sunGlare.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", path + "/config/" + parentCelestialBody.name + m_filePath, "sunglare.png")));

            black.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", path + "/config/" + parentCelestialBody.name + m_filePath, "black.png")));

            sunGlare.wrapMode = TextureWrapMode.Clamp;
            m_skyMaterialScaled.SetTexture("_Sun_Glare", sunGlare);

            InitUniforms(m_skyMaterialScaled);
            InitUniforms(m_skyExtinction);

            m_atmosphereMaterial = ShaderTool.GetMatFromShader2("CompiledAtmosphericScatter.shader");

            CurrentPQS = parentCelestialBody.pqsController;
            testPQS = parentCelestialBody.pqsController;

            for (int j = 0; j < 10; j++) {
                debugSettings[j] = true;
            }

            for (int j = 0; j < 10; j++) {
                additionalScales[j] = 1f;
            }

            skyObject = new GameObject();
            skyMF = skyObject.AddComponent < MeshFilter > ();
            Mesh idmesh = skyMF.mesh;
            idmesh.Clear();
            idmesh = m_mesh;
            //
            skyObject.layer = layer;
            //			celestialTransform = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == parentCelestialBody.name);
            celestialTransform = ParentPlanetTransform;
            //			skyObject.transform.parent = parentCelestialBody.transform;
            skyObject.transform.parent = celestialTransform;

            skyMR = skyObject.AddComponent < MeshRenderer > ();
            skyMR.sharedMaterial = m_skyMaterialScaled;
            skyMR.material = m_skyMaterialScaled;
            skyMR.castShadows = false;
            skyMR.receiveShadows = false;

            ///same for skyextinct
            skyExtinctObject = new GameObject();
            skyExtinctMF = skyExtinctObject.AddComponent < MeshFilter > ();
            idmesh = skyExtinctMF.mesh;
            idmesh.Clear();
            idmesh = m_mesh;
            //
            skyExtinctObject.layer = layer;
            skyExtinctObject.transform.parent = celestialTransform;

            skyExtinctMR = skyExtinctObject.AddComponent < MeshRenderer > ();
            skyExtinctMR.sharedMaterial = m_skyExtinction;
            skyExtinctMR.material = m_skyExtinction;
            skyExtinctMR.castShadows = false;
            skyExtinctMR.receiveShadows = false;

            hp = new SimplePostProcessCube(10000, m_atmosphereMaterial);
            atmosphereMesh = hp.GameObject;
            atmosphereMesh.layer = 15;
            atmosphereMeshrenderer = hp.GameObject.GetComponent < MeshRenderer > ();
            atmosphereMeshrenderer.material = m_atmosphereMaterial;

            celestialBodies = (CelestialBody[]) CelestialBody.FindObjectsOfType(typeof(CelestialBody));
        }
示例#2
0
        //Initialization
        public void Start()
        {
            m_radius=m_manager.GetRadius();

            Rt = (Rt / Rg) * m_radius;
            RL = (RL / Rg) * m_radius;
            Rg = m_radius;

            //			old mesh, causes artifacts with aniso in dx9
            //			m_mesh = MeshFactory.MakePlane(2, 2, MeshFactory.PLANE.XY, false,false);
            //			m_mesh.bounds = new Bounds(parentCelestialBody.transform.position, new Vector3(1e8f,1e8f, 1e8f));

            m_mesh = isoSphere.Create ();
            m_mesh.bounds = new Bounds(parentCelestialBody.transform.position, new Vector3(1e8f,1e8f, 1e8f));

            //The sky map is used to create a reflection of the sky for objects that need it (like the ocean)
            //			m_skyMap = new RenderTexture(512, 512, 0, RenderTextureFormat.ARGBHalf);
            //			m_skyMap.filterMode = FilterMode.Trilinear;
            //			m_skyMap.wrapMode = TextureWrapMode.Clamp;
            //			m_skyMap.anisoLevel = 9;
            //			m_skyMap.useMipMap = true;
            //			//m_skyMap.mipMapBias = -0.5f;
            //			m_skyMap.Create();

            //Inscatter is responsible for the change in the sky color as the sun moves
            //The raw file is a 4D array of 32 bit floats with a range of 0 to 1.589844
            //As there is not such thing as a 4D texture the data is packed into a 3D texture
            //and the shader manually performs the sample for the 4th dimension
            m_inscatter = new RenderTexture(RES_MU_S * RES_NU, RES_MU * RES_R, 0, RenderTextureFormat.ARGBHalf);
            m_inscatter.wrapMode = TextureWrapMode.Clamp;
            m_inscatter.filterMode = FilterMode.Bilinear;

            //Transmittance is responsible for the change in the sun color as it moves
            //The raw file is a 2D array of 32 bit floats with a range of 0 to 1
            m_transmit = new RenderTexture(TRANSMITTANCE_W, TRANSMITTANCE_H, 0, RenderTextureFormat.ARGBHalf);
            m_transmit.wrapMode = TextureWrapMode.Clamp;
            m_transmit.filterMode = FilterMode.Bilinear;

            //Irradiance is responsible for the change in the sky color as the sun moves
            //The raw file is a 2D array of 32 bit floats with a range of 0 to 1
            m_irradiance = new RenderTexture(SKY_W, SKY_H, 0, RenderTextureFormat.ARGBHalf);
            m_irradiance.wrapMode = TextureWrapMode.Clamp;
            m_irradiance.filterMode = FilterMode.Bilinear;

            initiateOrRestart ();
            m_skyMaterialScaled=new Material(ShaderTool.GetMatFromShader2("CompiledSkyScaled.shader"));
            m_skyMaterialScaled.renderQueue = 2003;

            sunGlare = new Texture2D (512, 512);
            black = new Texture2D (512, 512);

            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            path = Uri.UnescapeDataString(uri.Path);
            path=Path.GetDirectoryName (path);

            sunGlare.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", path + m_filePath, "sunglare.png")));
            black.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", path + m_filePath, "black.png")));

            sunGlare.wrapMode = TextureWrapMode.Clamp;
            m_skyMaterialScaled.SetTexture("_Sun_Glare", sunGlare);

            InitUniforms(m_skyMaterialScaled);
            //			InitUniforms(m_skyMapMaterial);

            m_atmosphereMaterial = ShaderTool.GetMatFromShader2 ("CompiledAtmosphericScatter.shader");

            if (forceOFFaniso) {
                QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable;
            }

            else
            {
                QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;
            }

            CurrentPQS = parentCelestialBody.pqsController;
            testPQS = parentCelestialBody.pqsController;

            for (int j=0; j<10; j++)
            {
                debugSettings[j]=true;
            }

            for (int j=0; j<10; j++)
            {
                additionalScales[j]=1f;
            }

            tester = new GameObject ();
            MF = tester.AddComponent<MeshFilter>();
            Mesh idmesh = MF.mesh;
            idmesh.Clear ();
            idmesh = m_mesh;
            //
            tester.layer = layer;
            celestialTransform = ScaledSpace.Instance.scaledSpaceTransforms.Single(t => t.name == parentCelestialBody.name);
            //			tester.transform.parent = parentCelestialBody.transform;
            tester.transform.parent = celestialTransform;

            MR = tester.AddComponent<MeshRenderer>();
            MR.sharedMaterial = m_skyMaterialScaled;
            MR.material =m_skyMaterialScaled;
            MR.castShadows = false;
            MR.receiveShadows = false;

            //			tester.transform.localPosition = Vector3.zero;
            //			tester.transform.localRotation = Quaternion.identity;
            //			tester.transform.localScale = Vector3.one;

            //			MR.enabled = true;

            //			pSystemBodies = (PSystemBody[])UnityEngine.Object.FindObjectsOfType(typeof(PSystemBody));
            //			print ("NUMBER FOUND");
            //			print (pSystemBodies.Length);
            //
            //			kerbinPsystemBody=ScaledSpace.Instance.transform.FindChild("Kerbin").gameObject.GetComponentInChildren<ScaledSpaceFader>();
            //
            //			if (kerbinPsystemBody == null) {
            //				print ("NULL");
            //			}
            //				else{
            //					print ("NOT NULL");
            //				print("fadeStart");
            //
            //				print(kerbinPsystemBody.fadeStart);
            //
            //				print("fadeEnd");
            //
            //				print(kerbinPsystemBody.fadeEnd);
            //
            //
            //			}

            hp = new SimplePostProcessCube (1000, m_atmosphereMaterial);
            atmosphereMesh = hp.GameObject;
            atmosphereMesh.layer = 15;
            atmosphereMeshrenderer = hp.GameObject.GetComponent<MeshRenderer>();
            atmosphereMeshrenderer.material = m_atmosphereMaterial;

            celestialBodies = (CelestialBody[])CelestialBody.FindObjectsOfType(typeof(CelestialBody));
        }