Beispiel #1
0
        public virtual void Init(ProlandManager manager)
        {
            m_manager = manager;
            loadFromConfigNode();

            InitOceanMaterial();

            //Worth moving to projected Grid Class?
            CreateProjectedGrid();

            oceanCameraProjectionMatModifier           = waterGameObjects[0].AddComponent <OceanCameraUpdateHook>();
            oceanCameraProjectionMatModifier.oceanNode = this;

            InitUnderwaterMaterial();

            underwaterProjector = new AtmosphereProjector(underwaterMaterial, m_manager.parentLocalTransform, (float)m_manager.m_radius);
            underwaterProjector.setActivated(false);

            //move this to separate class and make it work on every camera
            //refraction command buffer
            oceanRefractionCommandBuffer      = new CommandBuffer();
            oceanRefractionCommandBuffer.name = "ScattererOceanGrabScreen";
            oceanRefractionCommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, Scatterer.Instance.bufferManager.refractionTexture);
            Camera farCam;

            farCam = Scatterer.Instance.ReturnProperCamera(true, true);
            if (!(farCam is null))
            {
                //Ok, dual camera mode, register this far camera.
                farCam.AddCommandBuffer(CameraEvent.AfterForwardOpaque, oceanRefractionCommandBuffer);
            }
            //this will register right regardless
            Scatterer.Instance.ReturnProperCamera(false, false).AddCommandBuffer(CameraEvent.AfterForwardOpaque, oceanRefractionCommandBuffer);

            //dimming
            //TODO: maybe this can be changed, instead of complicated hooks on the Camera, add it to the light, like causticsShadowMaskModulate?
            if ((Scatterer.Instance.mainSettings.underwaterLightDimming || Scatterer.Instance.mainSettings.oceanCaustics) && (HighLogic.LoadedScene != GameScenes.MAINMENU))
            {
                underwaterDimmingHook           = (UnderwaterDimmingHook)Scatterer.Instance.scaledSpaceCamera.gameObject.AddComponent(typeof(UnderwaterDimmingHook));
                underwaterDimmingHook.oceanNode = this;
            }

            if (Scatterer.Instance.mainSettings.oceanCaustics && (HighLogic.LoadedScene == GameScenes.FLIGHT))
            {
                causticsShadowMaskModulator = (CausticsShadowMaskModulate)Scatterer.Instance.sunLight.AddComponent(typeof(CausticsShadowMaskModulate));
                if (!causticsShadowMaskModulator.Init(causticsTexturePath, causticsLayer1Scale, causticsLayer1Speed, causticsLayer2Scale, causticsLayer2Speed,
                                                      causticsMultiply, causticsMinBrightness, (float)manager.GetRadius(), causticsBlurDepth))
                {
                    UnityEngine.Object.DestroyImmediate(causticsShadowMaskModulator);
                    causticsShadowMaskModulator = null;
                }
            }
        }
Beispiel #2
0
        public virtual void Init(ProlandManager manager)
        {
            m_manager = manager;
            loadFromConfigNode();

            InitOceanMaterial();

            //Worth moving to projected Grid Class?
            CreateProjectedGrid();

            oceanCameraProjectionMatModifier           = waterGameObjects[0].AddComponent <OceanCameraUpdateHook>();
            oceanCameraProjectionMatModifier.oceanNode = this;

            waterGameObjects[0].AddComponent <ScreenCopierNotifier>();

            InitUnderwaterMaterial();

            underwaterProjector = new AtmosphereProjector(underwaterMaterial, m_manager.parentLocalTransform, (float)m_manager.m_radius);
            underwaterProjector.setActivated(false);

            //dimming
            //TODO: maybe this can be changed, instead of complicated hooks on the Camera, add it to the light, like causticsShadowMaskModulate?
            if ((Scatterer.Instance.mainSettings.underwaterLightDimming || Scatterer.Instance.mainSettings.oceanCaustics) && (HighLogic.LoadedScene != GameScenes.MAINMENU))
            {
                underwaterDimmingHook           = (UnderwaterDimmingHook)Scatterer.Instance.scaledSpaceCamera.gameObject.AddComponent(typeof(UnderwaterDimmingHook));
                underwaterDimmingHook.oceanNode = this;
            }

            if (Scatterer.Instance.mainSettings.oceanCaustics && (HighLogic.LoadedScene == GameScenes.FLIGHT))
            {
                //why doesn't this work with IVA camera? do they have a separate light?
                causticsShadowMaskModulator = (CausticsShadowMaskModulate)Scatterer.Instance.sunLight.gameObject.AddComponent(typeof(CausticsShadowMaskModulate));
                if (!causticsShadowMaskModulator.Init(causticsTexturePath, causticsLayer1Scale, causticsLayer1Speed, causticsLayer2Scale, causticsLayer2Speed,
                                                      causticsMultiply, causticsMinBrightness, (float)manager.GetRadius(), causticsBlurDepth))
                {
                    UnityEngine.Object.DestroyImmediate(causticsShadowMaskModulator);
                    causticsShadowMaskModulator = null;
                }
            }
        }
Beispiel #3
0
        // Use this for initialization
        public virtual void Init()
        {
            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");
            }

            if (Core.Instance.shadowsOnOcean && (QualitySettings.shadows != ShadowQuality.Disable))
            {
                if (QualitySettings.shadows == ShadowQuality.HardOnly)
                {
                    m_oceanMaterial.EnableKeyword("OCEAN_SHADOWS_HARD");
                    m_oceanMaterial.DisableKeyword("OCEAN_SHADOWS_SOFT");
                }
                else
                {
                    m_oceanMaterial.EnableKeyword("OCEAN_SHADOWS_SOFT");
                    m_oceanMaterial.DisableKeyword("OCEAN_SHADOWS_HARD");
                }
                m_oceanMaterial.DisableKeyword("OCEAN_SHADOWS_OFF");
            }
            else
            {
                m_oceanMaterial.EnableKeyword("OCEAN_SHADOWS_OFF");
                m_oceanMaterial.DisableKeyword("OCEAN_SHADOWS_HARD");
                m_oceanMaterial.DisableKeyword("OCEAN_SHADOWS_SOFT");
            }

            m_oceanMaterial.SetOverrideTag("IgnoreProjector", "True");

            m_manager.GetSkyNode().InitUniforms(m_oceanMaterial);

            m_oceanMaterial.SetTexture(ShaderProperties._customDepthTexture_PROPERTY, Core.Instance.bufferRenderingManager.depthTexture);

            //if (Core.Instance.oceanRefraction)
            m_oceanMaterial.SetTexture("_BackgroundTexture", Core.Instance.bufferRenderingManager.refractionTexture);
            m_oceanMaterial.renderQueue = 2501;

            m_oldlocalToOcean = 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;
                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;
            }

            oceanCameraProjectionMatModifier           = waterGameObjects[0].AddComponent <OceanCameraUpdateHook>();
            oceanCameraProjectionMatModifier.oceanNode = this;

            underwaterMaterial = new Material(ShaderReplacer.Instance.LoadedShaders[("Scatterer/UnderwaterScatterProjector")]);
            m_manager.GetSkyNode().InitPostprocessMaterial(underwaterMaterial);
            m_manager.GetSkyNode().InitPostprocessMaterial(m_oceanMaterial);

            underwaterMaterial.renderQueue = 2502;           //draw over fairings which is 2450 and over ocean which is 2501

            underwaterProjector = new AtmosphereProjector(underwaterMaterial, m_manager.parentLocalTransform, (float)m_manager.m_radius);
            underwaterProjector.setActivated(false);

            initUniforms();

            //move this to separate class and make it work on every camera

            //refraction command buffer
            oceanRefractionCommandBuffer      = new CommandBuffer();
            oceanRefractionCommandBuffer.name = "ScattererOceanGrabScreen";

            // copy screen
            oceanRefractionCommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, Core.Instance.bufferRenderingManager.refractionTexture);

            Core.Instance.farCamera.AddCommandBuffer(CameraEvent.AfterForwardOpaque, oceanRefractionCommandBuffer);
            Core.Instance.nearCamera.AddCommandBuffer(CameraEvent.AfterForwardOpaque, oceanRefractionCommandBuffer);

            //dimming
            if (Core.Instance.underwaterLightDimming && (HighLogic.LoadedScene != GameScenes.MAINMENU))
            {
                underwaterDimmingHook           = (UnderwaterDimmingHook)Core.Instance.scaledSpaceCamera.gameObject.AddComponent(typeof(UnderwaterDimmingHook));
                underwaterDimmingHook.oceanNode = this;
            }
        }