示例#1
0
        void CreateProjectedGrid()
        {
            //Create the projected grid. The resolution is the size in pixels
            //of each square in the grid. If the squares are small the size of
            //the mesh will exceed the max verts for a mesh in Unity. In this case
            //split the mesh up into smaller meshes.
            m_resolution = Mathf.Max(1, m_resolution);
            //The number of squares in the grid on the x and y axis
            int NX = Screen.width / m_resolution;
            int NY = Screen.height / m_resolution;

            numGrids = 1;
            //			const int MAX_VERTS = 65000;
            //The number of meshes need to make a grid of this resolution
            if (NX * NY > MAX_VERTS)
            {
                numGrids += (NX * NY) / MAX_VERTS;
            }
            m_screenGrids      = new Mesh[numGrids];
            waterGameObjects   = new GameObject[numGrids];
            waterMeshRenderers = new MeshRenderer[numGrids];
            waterMeshFilters   = new MeshFilter[numGrids];
            //Make the meshes. The end product will be a grid of verts that cover
            //the screen on the x and y axis with the z depth at 0. This grid is then
            //projected as the ocean by the shader
            for (int i = 0; i < numGrids; i++)
            {
                NY = Screen.height / numGrids / m_resolution;
                m_screenGrids [i]        = MeshFactory.MakePlane(NX, NY, MeshFactory.PLANE.XY, false, true, (float)i / (float)numGrids, 1.0f / (float)numGrids);
                m_screenGrids [i].bounds = new Bounds(Vector3.zero, new Vector3(1e8f, 1e8f, 1e8f));
                waterGameObjects [i]     = new GameObject();
                waterGameObjects [i].transform.parent = m_manager.parentCelestialBody.transform;
                //might be redundant
                waterMeshFilters [i] = waterGameObjects [i].AddComponent <MeshFilter> ();
                waterMeshFilters [i].mesh.Clear();
                waterMeshFilters [i].mesh                = m_screenGrids [i];
                waterGameObjects [i].layer               = 15;
                waterMeshRenderers [i]                   = waterGameObjects [i].AddComponent <MeshRenderer> ();
                waterMeshRenderers [i].sharedMaterial    = m_oceanMaterial;
                waterMeshRenderers [i].material          = m_oceanMaterial;
                waterMeshRenderers [i].receiveShadows    = false;
                waterMeshRenderers [i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                waterMeshRenderers [i].enabled           = true;
            }
        }
示例#2
0
        // Just a dummy gameObject so the reflectionProbeChecker can capture the reflection Camera
        public void addReflectionProbeFixer()
        {
            ReflectionProbeCheckerGO = new GameObject("Scatterer ReflectionProbeCheckerGO");
            //ReflectionProbeCheckerGO.transform.parent = nearCamera.transform; //VesselViewer doesn't like this for some reason
            ReflectionProbeCheckerGO.layer = 15;

            reflectionProbeChecker = ReflectionProbeCheckerGO.AddComponent <ReflectionProbeChecker> ();

            MeshFilter _mf = ReflectionProbeCheckerGO.AddComponent <MeshFilter> ();

            _mf.mesh.Clear();
            _mf.mesh        = MeshFactory.MakePlane(2, 2, MeshFactory.PLANE.XY, false, false);
            _mf.mesh.bounds = new Bounds(Vector4.zero, new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity));

            MeshRenderer _mr = ReflectionProbeCheckerGO.AddComponent <MeshRenderer> ();

            _mr.sharedMaterial    = new Material(ShaderReplacer.Instance.LoadedShaders[("Scatterer/invisible")]);
            _mr.material          = new Material(ShaderReplacer.Instance.LoadedShaders[("Scatterer/invisible")]);
            _mr.receiveShadows    = false;
            _mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            _mr.enabled           = true;
        }
示例#3
0
        public void start()
        {
            LoadConfigNode();

            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.wrapMode = TextureWrapMode.Clamp;
            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.wrapMode = TextureWrapMode.Clamp;
            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.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);

            if (!(HighLogic.LoadedScene == GameScenes.TRACKSTATION))
            {
                sunglareMaterial.SetTexture("_customDepthTexture", Scatterer.Instance.bufferManager.depthTexture);
            }
            else
            {
                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));

            sunflareGameObject = new GameObject();
            MeshFilter sunflareGameObjectMeshFilter;

            if (sunflareGameObject.GetComponent <MeshFilter> ())
            {
                sunflareGameObjectMeshFilter = sunflareGameObject.GetComponent <MeshFilter> ();
            }
            else
            {
                sunflareGameObjectMeshFilter = sunflareGameObject.AddComponent <MeshFilter>();
            }

            sunflareGameObjectMeshFilter.mesh.Clear();
            sunflareGameObjectMeshFilter.mesh = screenMesh;

            MeshRenderer sunflareGameObjectMeshRenderer;

            if (sunflareGameObject.GetComponent <MeshRenderer> ())
            {
                sunflareGameObjectMeshRenderer = sunflareGameObject.GetComponent <MeshRenderer> ();
            }
            else
            {
                sunflareGameObjectMeshRenderer = sunflareGameObject.AddComponent <MeshRenderer>();
            }

            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 < ghost1SettingsList1.Count; i++)
            {
                ghost1Settings1.SetRow(i, ghost1SettingsList1[i]);
            }
            Matrix4x4 ghost1Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost1SettingsList2.Count; i++)
            {
                ghost1Settings2.SetRow(i, ghost1SettingsList2[i]);
            }

            //ghost 2
            Matrix4x4 ghost2Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost2SettingsList1.Count; i++)
            {
                ghost2Settings1.SetRow(i, ghost2SettingsList1[i]);
            }
            Matrix4x4 ghost2Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost2SettingsList2.Count; i++)
            {
                ghost2Settings2.SetRow(i, ghost2SettingsList2[i]);
            }

            //ghost 3
            Matrix4x4 ghost3Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost3SettingsList1.Count; i++)
            {
                ghost3Settings1.SetRow(i, ghost3SettingsList1[i]);
            }
            Matrix4x4 ghost3Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost3SettingsList2.Count; i++)
            {
                ghost3Settings2.SetRow(i, ghost3SettingsList2[i]);
            }

            extinctionTexture = new RenderTexture(4, 4, 0, RenderTextureFormat.ARGB32);
            extinctionTexture.antiAliasing = 1;
            extinctionTexture.filterMode   = FilterMode.Point;
            extinctionTexture.Create();

            sunglareMaterial.SetVector("flareSettings", flareSettings);
            sunglareMaterial.SetVector("spikesSettings", spikesSettings);

            sunglareMaterial.SetMatrix("ghost1Settings1", ghost1Settings1);
            sunglareMaterial.SetMatrix("ghost1Settings2", ghost1Settings2);

            sunglareMaterial.SetMatrix("ghost2Settings1", ghost2Settings1);
            sunglareMaterial.SetMatrix("ghost2Settings2", ghost2Settings2);

            sunglareMaterial.SetMatrix("ghost3Settings1", ghost3Settings1);
            sunglareMaterial.SetMatrix("ghost3Settings2", ghost3Settings2);

            sunglareMaterial.SetTexture("extinctionTexture", extinctionTexture);

            sunglareMaterial.SetVector("flareColor", flareColor);

            scaledCameraHook       = (SunflareCameraHook)Scatterer.Instance.scaledSpaceCamera.gameObject.AddComponent(typeof(SunflareCameraHook));
            scaledCameraHook.flare = this;
            scaledCameraHook.useDbufferOnCamera = 0f;

            if (!(HighLogic.LoadedScene == GameScenes.TRACKSTATION))
            {
                nearCameraHook       = (SunflareCameraHook)Scatterer.Instance.nearCamera.gameObject.AddComponent(typeof(SunflareCameraHook));
                nearCameraHook.flare = this;
                nearCameraHook.useDbufferOnCamera = 1f;
            }

            Utils.LogDebug("Added custom sun flare for " + sourceName);
        }
示例#4
0
        // Use this for initialization
        public virtual void Start()
        {
//			m_cameraToWorldMatrix = Matrix4x4d.Identity ();
//
            //using different materials for both the far and near cameras because they have different projection matrixes
            //the projection matrix in the shader has to match that of the camera or the projection will be wrong and the ocean will
            //appear to "shift around"

            if (Core.Instance.oceanPixelLights)
            {
                m_oceanMaterial = new Material(ShaderReplacer.Instance.LoadedShaders[("Scatterer/OceanWhiteCapsPixelLights")]);
            }
            else
            {
                m_oceanMaterial = new Material(ShaderReplacer.Instance.LoadedShaders[("Scatterer/OceanWhiteCaps")]);
            }

            if (Core.Instance.oceanSkyReflections)
            {
                m_oceanMaterial.EnableKeyword("SKY_REFLECTIONS_ON");
                m_oceanMaterial.DisableKeyword("SKY_REFLECTIONS_OFF");
            }
            else
            {
                m_oceanMaterial.EnableKeyword("SKY_REFLECTIONS_OFF");
                m_oceanMaterial.DisableKeyword("SKY_REFLECTIONS_ON");
            }

            if (Core.Instance.usePlanetShine)
            {
                m_oceanMaterial.EnableKeyword("PLANETSHINE_ON");
                m_oceanMaterial.DisableKeyword("PLANETSHINE_OFF");
            }
            else
            {
                m_oceanMaterial.DisableKeyword("PLANETSHINE_ON");
                m_oceanMaterial.EnableKeyword("PLANETSHINE_OFF");
            }

            if (Core.Instance.oceanRefraction)
            {
                m_oceanMaterial.EnableKeyword("REFRACTION_ON");
                m_oceanMaterial.DisableKeyword("REFRACTION_OFF");
            }
            else
            {
                m_oceanMaterial.EnableKeyword("REFRACTION_OFF");
                m_oceanMaterial.DisableKeyword("REFRACTION_ON");
            }


//			m_manager.GetSkyNode ().InitUniforms (m_oceanMaterialNear);


            m_manager.GetSkyNode().InitUniforms(m_oceanMaterial);

            m_oceanMaterial.SetTexture(ShaderProperties._customDepthTexture_PROPERTY, Core.Instance.customDepthBufferTexture);

            m_oceanMaterial.SetTexture("_BackgroundTexture", Core.Instance.refractionTexture);

            m_oceanMaterial.renderQueue = 2050;

            m_oldlocalToOcean = Matrix4x4d.Identity();
//			m_oldworldToOcean = Matrix4x4d.Identity ();
            m_offset = Vector3d2.Zero();

            //Create the projected grid. The resolution is the size in pixels
            //of each square in the grid. If the squares are small the size of
            //the mesh will exceed the max verts for a mesh in Unity. In this case
            //split the mesh up into smaller meshes.

            m_resolution = Mathf.Max(1, m_resolution);
            //The number of squares in the grid on the x and y axis
            int NX = Screen.width / m_resolution;
            int NY = Screen.height / m_resolution;

            numGrids = 1;

            //			const int MAX_VERTS = 65000;
            //The number of meshes need to make a grid of this resolution
            if (NX * NY > MAX_VERTS)
            {
                numGrids += (NX * NY) / MAX_VERTS;
            }

            m_screenGrids = new Mesh[numGrids];

            waterGameObjects   = new GameObject[numGrids];
            waterMeshRenderers = new MeshRenderer[numGrids];
            waterMeshFilters   = new MeshFilter[numGrids];

            //Make the meshes. The end product will be a grid of verts that cover
            //the screen on the x and y axis with the z depth at 0. This grid is then
            //projected as the ocean by the shader
            for (int i = 0; i < numGrids; i++)
            {
                NY = Screen.height / numGrids / m_resolution;

                m_screenGrids [i]        = MakePlane(NX, NY, (float)i / (float)numGrids, 1.0f / (float)numGrids);
                m_screenGrids [i].bounds = new Bounds(Vector3.zero, new Vector3(1e8f, 1e8f, 1e8f));


                waterGameObjects[i] = new GameObject();
                waterGameObjects[i].transform.parent = m_manager.parentCelestialBody.transform;               //might be redundant
                waterMeshFilters[i] = waterGameObjects[i].AddComponent <MeshFilter>();
                waterMeshFilters[i].mesh.Clear();
                waterMeshFilters[i].mesh = m_screenGrids[i];

                //waterGameObjects[i].layer = 15;
                waterGameObjects[i].layer = 23;
                waterMeshRenderers[i]     = waterGameObjects[i].AddComponent <MeshRenderer>();


                waterMeshRenderers[i].sharedMaterial = m_oceanMaterial;
                waterMeshRenderers[i].material       = m_oceanMaterial;


                waterMeshRenderers[i].receiveShadows    = false;
                waterMeshRenderers[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;


//				CommandBufferModifiedProjectionMatrix tmp = waterGameObjects[i].AddComponent<CommandBufferModifiedProjectionMatrix>();
//				tmp.Core.Instance=Core.Instance;

                waterMeshRenderers[i].enabled = true;
            }

            cbProjectionMat           = waterGameObjects[0].AddComponent <CommandBufferModifiedProjectionMatrix>();
            cbProjectionMat.oceanNode = this;

            underwaterGameObject = new GameObject();

            if (underwaterGameObject.GetComponent <MeshFilter> ())
            {
                underwaterMeshFilter = underwaterGameObject.GetComponent <MeshFilter> ();
            }
            else
            {
                underwaterMeshFilter = underwaterGameObject.AddComponent <MeshFilter>();
            }

            underwaterMeshFilter.mesh.Clear();
            underwaterMeshFilter.mesh        = MeshFactory.MakePlaneWithFrustumIndexes();
            underwaterMeshFilter.mesh.bounds = new Bounds(Vector3.zero, new Vector3(1e8f, 1e8f, 1e8f));

            if (underwaterGameObject.GetComponent <MeshRenderer> ())
            {
                underwaterMeshrenderer = underwaterGameObject.GetComponent <MeshRenderer> ();
            }
            else
            {
                underwaterMeshrenderer = underwaterGameObject.AddComponent <MeshRenderer>();
            }

            underwaterPostProcessingMaterial = new Material(ShaderReplacer.Instance.LoadedShaders[("Scatterer/UnderwaterScatter")]);
            underwaterPostProcessingMaterial.SetOverrideTag("IgnoreProjector", "True");
            m_manager.GetSkyNode().InitPostprocessMaterial(underwaterPostProcessingMaterial);
            underwaterPostProcessingMaterial.renderQueue = 2049;

            if (Core.Instance.oceanRefraction && (HighLogic.LoadedScene != GameScenes.TRACKSTATION))
            {
                Core.Instance.refractionCam.underwaterPostProcessing = underwaterMeshrenderer;
            }
            underwaterMeshrenderer.sharedMaterial = underwaterPostProcessingMaterial;
            underwaterMeshrenderer.material       = underwaterPostProcessingMaterial;

            underwaterMeshrenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            underwaterMeshrenderer.receiveShadows    = false;
            underwaterMeshrenderer.enabled           = false;

            //underwaterGameObject.layer = 15;
            underwaterGameObject.layer = 23;
        }
示例#5
0
        public void start()
        {
            sunglareMaterial = new Material(ShaderTool.GetMatFromShader2("CompiledSunGlare.shader"));

            //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}", inCore.path + "/sunflare", "sunSpikes.png")));
            sunSpikes.wrapMode = TextureWrapMode.Clamp;
            sunFlare.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "sunFlare.png")));
            sunFlare.wrapMode = TextureWrapMode.Clamp;
            sunGhost1.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "Ghost1.png")));
            sunGhost1.wrapMode = TextureWrapMode.Clamp;
            sunGhost2.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "Ghost2.png")));
            sunGhost2.wrapMode = TextureWrapMode.Clamp;
            sunGhost3.LoadImage(System.IO.File.ReadAllBytes(String.Format("{0}/{1}", inCore.path + "/sunflare", "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("_customDepthTexture", inCore.customDepthBufferTexture);

            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));

            Sun.Instance.sunFlare.enabled = false;


            loadConfigNode();

            //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 < ghost1SettingsList1.Count; i++)
            {
                ghost1Settings1.SetRow(i, ghost1SettingsList1[i]);
            }
            Matrix4x4 ghost1Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost1SettingsList2.Count; i++)
            {
                ghost1Settings2.SetRow(i, ghost1SettingsList2[i]);
            }

            //ghost 2
            Matrix4x4 ghost2Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost2SettingsList1.Count; i++)
            {
                ghost2Settings1.SetRow(i, ghost2SettingsList1[i]);
            }
            Matrix4x4 ghost2Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost2SettingsList2.Count; i++)
            {
                ghost2Settings2.SetRow(i, ghost2SettingsList2[i]);
            }

            //ghost 3
            Matrix4x4 ghost3Settings1 = Matrix4x4.zero;

            for (int i = 0; i < ghost3SettingsList1.Count; i++)
            {
                ghost3Settings1.SetRow(i, ghost3SettingsList1[i]);
            }
            Matrix4x4 ghost3Settings2 = Matrix4x4.zero;

            for (int i = 0; i < ghost3SettingsList2.Count; i++)
            {
                ghost3Settings2.SetRow(i, ghost3SettingsList2[i]);
            }


            sunglareMaterial.SetVector("flareSettings", flareSettings);
            sunglareMaterial.SetVector("spikesSettings", spikesSettings);

            sunglareMaterial.SetMatrix("ghost1Settings1", ghost1Settings1);
            sunglareMaterial.SetMatrix("ghost1Settings2", ghost1Settings2);

            sunglareMaterial.SetMatrix("ghost2Settings1", ghost2Settings1);
            sunglareMaterial.SetMatrix("ghost2Settings2", ghost2Settings2);

            sunglareMaterial.SetMatrix("ghost3Settings1", ghost3Settings1);
            sunglareMaterial.SetMatrix("ghost3Settings2", ghost3Settings2);

            Debug.Log("[Scatterer] added custom sun flare");
        }