void Awake()
        {
            if (!DaggerfallUnity.Settings.Nystul_RealtimeReflections)
                return;

            reflectionPlaneBottom = new GameObject("ReflectionPlaneBottom");
            reflectionPlaneBottom.layer = LayerMask.NameToLayer("Water");
            MeshFilter meshFilter = (MeshFilter)reflectionPlaneBottom.AddComponent(typeof(MeshFilter));
            meshFilter.mesh = CreateMesh(100000.0f, 100000.0f); // create quad with normal facing into negative y-direction (so it is not visible but it will trigger OnWillRenderObject() in MirrorReflection.cs) - should be big enough to be "visible" even when looking parallel to the x/z-plane
            MeshRenderer renderer = reflectionPlaneBottom.AddComponent(typeof(MeshRenderer)) as MeshRenderer;

            renderer.material.shader = Shader.Find("Standard");
            Texture2D tex = new Texture2D(1, 1);
            tex.SetPixel(0, 0, Color.green);
            tex.Apply();
            renderer.material.mainTexture = tex;
            renderer.material.color = Color.green;
            renderer.enabled = true; // if this is set to false OnWillRenderObject() in MirrorReflection.cs will not work (workaround would be to change OnWillRenderObject() to Update()

            mirrorRefl = reflectionPlaneBottom.AddComponent<MirrorReflection>();
            mirrorRefl.m_TextureSize = 512;

            reflectionPlaneBottom.transform.SetParent(this.transform);

            InjectReflectiveMaterialProperty scriptInjectReflectiveMaterialProperty = reflectionPlaneBottom.AddComponent<InjectReflectiveMaterialProperty>(); // the inject script is parented to this plane so that the OnWillRenderObject() method of the inject script will work - this is important since update() function resulted in slightly delayed update which could be seen when ground level height changed
            scriptInjectReflectiveMaterialProperty.iniPathConfigInjectionTextures = this.iniPathConfigInjectionTextures;

            reflectionPlaneSeaLevel = new GameObject("ReflectionPlaneSeaLevel");
            reflectionPlaneSeaLevel.layer = LayerMask.NameToLayer("Water");
            MeshFilter meshFilterSeaLevel = (MeshFilter)reflectionPlaneSeaLevel.AddComponent(typeof(MeshFilter));
            meshFilterSeaLevel.mesh = CreateMesh(1000000.0f, 1000000.0f); // create quad facing into negative y-direction (so it is not visible but it will trigger OnWillRenderObject() in MirrorReflection.cs) - should be big enough to be "visible" even when looking parallel to the x/z-plane
            MeshRenderer rendererSeaLevel = reflectionPlaneSeaLevel.AddComponent(typeof(MeshRenderer)) as MeshRenderer;

            rendererSeaLevel.material.shader = Shader.Find("Standard");
            Texture2D texSeaLevel = new Texture2D(1, 1);
            texSeaLevel.SetPixel(0, 0, Color.green);
            texSeaLevel.Apply();
            rendererSeaLevel.material.mainTexture = texSeaLevel;
            rendererSeaLevel.material.color = Color.green;
            rendererSeaLevel.enabled = true; // if this is set to false OnWillRenderObject() in MirrorReflection.cs will not work (workaround would be to change OnWillRenderObject() to Update()

            mirrorReflSeaLevel = reflectionPlaneSeaLevel.AddComponent<MirrorReflection>();
            mirrorReflSeaLevel.m_TextureSize = 512;

            reflectionPlaneSeaLevel.transform.SetParent(this.transform);

            LayerMask layerIndexWorldTerrain = LayerMask.NameToLayer("WorldTerrain");
            if (layerIndexWorldTerrain != -1)
            {
                mirrorRefl.m_ReflectLayers.value = (1 << LayerMask.NameToLayer("Default")) + (1 << LayerMask.NameToLayer("WorldTerrain"));
                mirrorReflSeaLevel.m_ReflectLayers = (1 << LayerMask.NameToLayer("Default")) + (1 << LayerMask.NameToLayer("WorldTerrain"));
            }
            else
            {
                mirrorRefl.m_ReflectLayers.value = 1 << LayerMask.NameToLayer("Default");
                mirrorReflSeaLevel.m_ReflectLayers = 1 << LayerMask.NameToLayer("Default");
            }

            PlayerEnterExit.OnTransitionInterior += OnTransitionToInterior;
            PlayerEnterExit.OnTransitionExterior += OnTransitionToExterior;
            PlayerEnterExit.OnTransitionDungeonInterior += OnTransitionToInterior;
            PlayerEnterExit.OnTransitionDungeonExterior += OnTransitionToExterior;
        }
Beispiel #2
0
        void Awake()
        {
            if (!DaggerfallUnity.Settings.Nystul_RealtimeReflections)
            {
                return;
            }

            reflectionPlaneBottom       = new GameObject("ReflectionPlaneBottom");
            reflectionPlaneBottom.layer = LayerMask.NameToLayer("Water");
            MeshFilter meshFilter = (MeshFilter)reflectionPlaneBottom.AddComponent(typeof(MeshFilter));

            meshFilter.mesh = CreateMesh(100000.0f, 100000.0f); // create quad with normal facing into negative y-direction (so it is not visible but it will trigger OnWillRenderObject() in MirrorReflection.cs) - should be big enough to be "visible" even when looking parallel to the x/z-plane
            MeshRenderer renderer = reflectionPlaneBottom.AddComponent(typeof(MeshRenderer)) as MeshRenderer;

            renderer.material.shader = Shader.Find("Standard");
            Texture2D tex = new Texture2D(1, 1);

            tex.SetPixel(0, 0, Color.green);
            tex.Apply();
            renderer.material.mainTexture = tex;
            renderer.material.color       = Color.green;
            renderer.enabled = true; // if this is set to false OnWillRenderObject() in MirrorReflection.cs will not work (workaround would be to change OnWillRenderObject() to Update()

            mirrorRefl = reflectionPlaneBottom.AddComponent <MirrorReflection>();
            mirrorRefl.m_TextureSize = 512;

            reflectionPlaneBottom.transform.SetParent(this.transform);

            InjectReflectiveMaterialProperty scriptInjectReflectiveMaterialProperty = reflectionPlaneBottom.AddComponent <InjectReflectiveMaterialProperty>(); // the inject script is parented to this plane so that the OnWillRenderObject() method of the inject script will work - this is important since update() function resulted in slightly delayed update which could be seen when ground level height changed

            scriptInjectReflectiveMaterialProperty.iniPathConfigInjectionTextures = this.iniPathConfigInjectionTextures;

            reflectionPlaneSeaLevel       = new GameObject("ReflectionPlaneSeaLevel");
            reflectionPlaneSeaLevel.layer = LayerMask.NameToLayer("Water");
            MeshFilter meshFilterSeaLevel = (MeshFilter)reflectionPlaneSeaLevel.AddComponent(typeof(MeshFilter));

            meshFilterSeaLevel.mesh = CreateMesh(1000000.0f, 1000000.0f); // create quad facing into negative y-direction (so it is not visible but it will trigger OnWillRenderObject() in MirrorReflection.cs) - should be big enough to be "visible" even when looking parallel to the x/z-plane
            MeshRenderer rendererSeaLevel = reflectionPlaneSeaLevel.AddComponent(typeof(MeshRenderer)) as MeshRenderer;


            rendererSeaLevel.material.shader = Shader.Find("Standard");
            Texture2D texSeaLevel = new Texture2D(1, 1);

            texSeaLevel.SetPixel(0, 0, Color.green);
            texSeaLevel.Apply();
            rendererSeaLevel.material.mainTexture = texSeaLevel;
            rendererSeaLevel.material.color       = Color.green;
            rendererSeaLevel.enabled = true; // if this is set to false OnWillRenderObject() in MirrorReflection.cs will not work (workaround would be to change OnWillRenderObject() to Update()

            mirrorReflSeaLevel = reflectionPlaneSeaLevel.AddComponent <MirrorReflection>();
            mirrorReflSeaLevel.m_TextureSize = 512;

            reflectionPlaneSeaLevel.transform.SetParent(this.transform);

            LayerMask layerIndexWorldTerrain = LayerMask.NameToLayer("WorldTerrain");

            if (layerIndexWorldTerrain != -1)
            {
                mirrorRefl.m_ReflectLayers.value   = (1 << LayerMask.NameToLayer("Default")) + (1 << LayerMask.NameToLayer("WorldTerrain"));
                mirrorReflSeaLevel.m_ReflectLayers = (1 << LayerMask.NameToLayer("Default")) + (1 << LayerMask.NameToLayer("WorldTerrain"));
            }
            else
            {
                mirrorRefl.m_ReflectLayers.value   = 1 << LayerMask.NameToLayer("Default");
                mirrorReflSeaLevel.m_ReflectLayers = 1 << LayerMask.NameToLayer("Default");
            }

            useDeferredReflections = (GameManager.Instance.MainCamera.renderingPath == RenderingPath.DeferredShading);

            if (useDeferredReflections)
            {
                componentDefferedPlanarReflections = GameManager.Instance.MainCameraObject.AddComponent <ReflectionsMod.DeferredPlanarReflections>();
            }

            playerInside = GameManager.Instance.IsPlayerInside;

            PlayerEnterExit.OnTransitionInterior        += OnTransitionToInterior;
            PlayerEnterExit.OnTransitionExterior        += OnTransitionToExterior;
            PlayerEnterExit.OnTransitionDungeonInterior += OnTransitionToInterior;
            PlayerEnterExit.OnTransitionDungeonExterior += OnTransitionToExterior;
        }