Beispiel #1
0
        public void OnWillRenderObject()
        {
            if (!base.enabled || !base.GetComponent <Renderer>() || !base.GetComponent <Renderer>().sharedMaterial || !base.GetComponent <Renderer>().enabled)
            {
                return;
            }
            Camera current = Camera.current;

            if (!current)
            {
                return;
            }
            if (Water.s_InsideWater)
            {
                return;
            }
            Water.s_InsideWater         = true;
            this.m_HardwareWaterSupport = this.FindHardwareWaterSupport();
            Water.WaterMode waterMode = this.GetWaterMode();
            Camera          camera;
            Camera          camera2;

            this.CreateWaterObjects(current, out camera, out camera2);
            Vector3 position        = base.transform.position;
            Vector3 up              = base.transform.up;
            int     pixelLightCount = QualitySettings.pixelLightCount;

            if (this.disablePixelLights)
            {
                QualitySettings.pixelLightCount = 0;
            }
            this.UpdateCameraModes(current, camera);
            this.UpdateCameraModes(current, camera2);
            if (waterMode >= Water.WaterMode.Reflective)
            {
                float     w     = -Vector3.Dot(up, position) - this.clipPlaneOffset;
                Vector4   plane = new Vector4(up.x, up.y, up.z, w);
                Matrix4x4 zero  = Matrix4x4.zero;
                Water.CalculateReflectionMatrix(ref zero, plane);
                Vector3 position2 = current.transform.position;
                Vector3 position3 = zero.MultiplyPoint(position2);
                camera.worldToCameraMatrix = current.worldToCameraMatrix * zero;
                Vector4 clipPlane = this.CameraSpacePlane(camera, position, up, 1f);
                camera.projectionMatrix   = current.CalculateObliqueMatrix(clipPlane);
                camera.cullingMask        = (-17 & this.reflectLayers.value);
                camera.targetTexture      = this.m_ReflectionTexture;
                GL.invertCulling          = true;
                camera.transform.position = position3;
                Vector3 eulerAngles = current.transform.eulerAngles;
                camera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z);
                camera.Render();
                camera.transform.position = position2;
                GL.invertCulling          = false;
                base.GetComponent <Renderer>().sharedMaterial.SetTexture("_ReflectionTex", this.m_ReflectionTexture);
            }
            if (waterMode >= Water.WaterMode.Refractive)
            {
                camera2.worldToCameraMatrix = current.worldToCameraMatrix;
                Vector4 clipPlane2 = this.CameraSpacePlane(camera2, position, up, -1f);
                camera2.projectionMatrix   = current.CalculateObliqueMatrix(clipPlane2);
                camera2.cullingMask        = (-17 & this.refractLayers.value);
                camera2.targetTexture      = this.m_RefractionTexture;
                camera2.transform.position = current.transform.position;
                camera2.transform.rotation = current.transform.rotation;
                camera2.Render();
                base.GetComponent <Renderer>().sharedMaterial.SetTexture("_RefractionTex", this.m_RefractionTexture);
            }
            if (this.disablePixelLights)
            {
                QualitySettings.pixelLightCount = pixelLightCount;
            }
            switch (waterMode)
            {
            case Water.WaterMode.Simple:
                Shader.EnableKeyword("WATER_SIMPLE");
                Shader.DisableKeyword("WATER_REFLECTIVE");
                Shader.DisableKeyword("WATER_REFRACTIVE");
                break;

            case Water.WaterMode.Reflective:
                Shader.DisableKeyword("WATER_SIMPLE");
                Shader.EnableKeyword("WATER_REFLECTIVE");
                Shader.DisableKeyword("WATER_REFRACTIVE");
                break;

            case Water.WaterMode.Refractive:
                Shader.DisableKeyword("WATER_SIMPLE");
                Shader.DisableKeyword("WATER_REFLECTIVE");
                Shader.EnableKeyword("WATER_REFRACTIVE");
                break;
            }
            Water.s_InsideWater = false;
        }
Beispiel #2
0
    public void OnWillRenderObject()
    {
        if (!base.get_enabled() || !base.get_renderer() || !base.get_renderer().get_sharedMaterial() || !base.get_renderer().get_enabled())
        {
            return;
        }
        Camera current = Camera.get_current();

        if (!current)
        {
            return;
        }
        if (Water.s_InsideWater)
        {
            return;
        }
        Water.s_InsideWater         = true;
        this.m_HardwareWaterSupport = this.FindHardwareWaterSupport();
        Water.WaterMode waterMode = this.GetWaterMode();
        Camera          camera;
        Camera          camera2;

        this.CreateWaterObjects(current, out camera, out camera2);
        Vector3 position        = base.get_transform().get_position();
        Vector3 up              = base.get_transform().get_up();
        int     pixelLightCount = QualitySettings.get_pixelLightCount();

        if (this.m_DisablePixelLights)
        {
            QualitySettings.set_pixelLightCount(0);
        }
        this.UpdateCameraModes(current, camera);
        this.UpdateCameraModes(current, camera2);
        if (waterMode >= Water.WaterMode.Reflective)
        {
            float     num   = -Vector3.Dot(up, position) - this.m_ClipPlaneOffset;
            Vector4   plane = new Vector4(up.x, up.y, up.z, num);
            Matrix4x4 zero  = Matrix4x4.get_zero();
            Water.CalculateReflectionMatrix(ref zero, plane);
            Vector3 position2 = current.get_transform().get_position();
            Vector3 position3 = zero.MultiplyPoint(position2);
            camera.set_worldToCameraMatrix(current.get_worldToCameraMatrix() * zero);
            Vector4   clipPlane        = this.CameraSpacePlane(camera, position, up, 1f);
            Matrix4x4 projectionMatrix = current.get_projectionMatrix();
            Water.CalculateObliqueMatrix(ref projectionMatrix, clipPlane);
            camera.set_projectionMatrix(projectionMatrix);
            camera.set_cullingMask(-17 & this.m_ReflectLayers.get_value());
            camera.set_targetTexture(this.m_ReflectionTexture);
            GL.SetRevertBackfacing(true);
            camera.get_transform().set_position(position3);
            Vector3 eulerAngles = current.get_transform().get_eulerAngles();
            camera.get_transform().set_eulerAngles(new Vector3(0f, eulerAngles.y, eulerAngles.z));
            camera.Render();
            camera.get_transform().set_position(position2);
            GL.SetRevertBackfacing(false);
            base.get_renderer().get_sharedMaterial().SetTexture("_ReflectionTex", this.m_ReflectionTexture);
        }
        if (waterMode >= Water.WaterMode.Refractive)
        {
            camera2.set_worldToCameraMatrix(current.get_worldToCameraMatrix());
            Vector4   clipPlane2        = this.CameraSpacePlane(camera2, position, up, -1f);
            Matrix4x4 projectionMatrix2 = current.get_projectionMatrix();
            Water.CalculateObliqueMatrix(ref projectionMatrix2, clipPlane2);
            camera2.set_projectionMatrix(projectionMatrix2);
            camera2.set_cullingMask(-17 & this.m_RefractLayers.get_value());
            camera2.set_targetTexture(this.m_RefractionTexture);
            camera2.get_transform().set_position(current.get_transform().get_position());
            camera2.get_transform().set_rotation(current.get_transform().get_rotation());
            camera2.Render();
            base.get_renderer().get_sharedMaterial().SetTexture("_RefractionTex", this.m_RefractionTexture);
        }
        if (this.m_DisablePixelLights)
        {
            QualitySettings.set_pixelLightCount(pixelLightCount);
        }
        switch (waterMode)
        {
        case Water.WaterMode.Simple:
            Shader.EnableKeyword("WATER_SIMPLE");
            Shader.DisableKeyword("WATER_REFLECTIVE");
            Shader.DisableKeyword("WATER_REFRACTIVE");
            break;

        case Water.WaterMode.Reflective:
            Shader.DisableKeyword("WATER_SIMPLE");
            Shader.EnableKeyword("WATER_REFLECTIVE");
            Shader.DisableKeyword("WATER_REFRACTIVE");
            break;

        case Water.WaterMode.Refractive:
            Shader.DisableKeyword("WATER_SIMPLE");
            Shader.DisableKeyword("WATER_REFLECTIVE");
            Shader.EnableKeyword("WATER_REFRACTIVE");
            break;
        }
        Water.s_InsideWater = false;
    }
Beispiel #3
0
 private void CreateWaterObjects(Camera currentCamera, out Camera reflectionCamera, out Camera refractionCamera)
 {
     Water.WaterMode waterMode = this.GetWaterMode();
     reflectionCamera = null;
     refractionCamera = null;
     if (waterMode >= Water.WaterMode.Reflective)
     {
         if (!this.m_ReflectionTexture || this.m_OldReflectionTextureSize != this.textureSize)
         {
             if (this.m_ReflectionTexture)
             {
                 UnityEngine.Object.DestroyImmediate(this.m_ReflectionTexture);
             }
             this.m_ReflectionTexture              = new RenderTexture(this.textureSize, this.textureSize, 16);
             this.m_ReflectionTexture.name         = "__WaterReflection" + base.GetInstanceID();
             this.m_ReflectionTexture.isPowerOfTwo = true;
             this.m_ReflectionTexture.hideFlags    = HideFlags.DontSave;
             this.m_OldReflectionTextureSize       = this.textureSize;
         }
         this.m_ReflectionCameras.TryGetValue(currentCamera, out reflectionCamera);
         if (!reflectionCamera)
         {
             GameObject gameObject = new GameObject(string.Concat(new object[]
             {
                 "Water Refl Camera id",
                 base.GetInstanceID(),
                 " for ",
                 currentCamera.GetInstanceID()
             }), new Type[]
             {
                 typeof(Camera),
                 typeof(Skybox)
             });
             reflectionCamera                    = gameObject.GetComponent <Camera>();
             reflectionCamera.enabled            = false;
             reflectionCamera.transform.position = base.transform.position;
             reflectionCamera.transform.rotation = base.transform.rotation;
             reflectionCamera.gameObject.AddComponent <FlareLayer>();
             gameObject.hideFlags = HideFlags.HideAndDontSave;
             this.m_ReflectionCameras[currentCamera] = reflectionCamera;
         }
     }
     if (waterMode >= Water.WaterMode.Refractive)
     {
         if (!this.m_RefractionTexture || this.m_OldRefractionTextureSize != this.textureSize)
         {
             if (this.m_RefractionTexture)
             {
                 UnityEngine.Object.DestroyImmediate(this.m_RefractionTexture);
             }
             this.m_RefractionTexture              = new RenderTexture(this.textureSize, this.textureSize, 16);
             this.m_RefractionTexture.name         = "__WaterRefraction" + base.GetInstanceID();
             this.m_RefractionTexture.isPowerOfTwo = true;
             this.m_RefractionTexture.hideFlags    = HideFlags.DontSave;
             this.m_OldRefractionTextureSize       = this.textureSize;
         }
         this.m_RefractionCameras.TryGetValue(currentCamera, out refractionCamera);
         if (!refractionCamera)
         {
             GameObject gameObject2 = new GameObject(string.Concat(new object[]
             {
                 "Water Refr Camera id",
                 base.GetInstanceID(),
                 " for ",
                 currentCamera.GetInstanceID()
             }), new Type[]
             {
                 typeof(Camera),
                 typeof(Skybox)
             });
             refractionCamera                    = gameObject2.GetComponent <Camera>();
             refractionCamera.enabled            = false;
             refractionCamera.transform.position = base.transform.position;
             refractionCamera.transform.rotation = base.transform.rotation;
             refractionCamera.gameObject.AddComponent <FlareLayer>();
             gameObject2.hideFlags = HideFlags.HideAndDontSave;
             this.m_RefractionCameras[currentCamera] = refractionCamera;
         }
     }
 }
Beispiel #4
0
 private void CreateWaterObjects(Camera currentCamera, out Camera reflectionCamera, out Camera refractionCamera)
 {
     Water.WaterMode waterMode = this.GetWaterMode();
     reflectionCamera = null;
     refractionCamera = null;
     if (waterMode >= Water.WaterMode.Reflective)
     {
         if (!this.m_ReflectionTexture || this.m_OldReflectionTextureSize != this.m_TextureSize)
         {
             if (this.m_ReflectionTexture)
             {
                 Object.DestroyImmediate(this.m_ReflectionTexture);
             }
             this.m_ReflectionTexture = new RenderTexture(this.m_TextureSize, this.m_TextureSize, 16);
             this.m_ReflectionTexture.set_name("__WaterReflection" + base.GetInstanceID());
             this.m_ReflectionTexture.set_isPowerOfTwo(true);
             this.m_ReflectionTexture.set_hideFlags(4);
             this.m_OldReflectionTextureSize = this.m_TextureSize;
         }
         reflectionCamera = (this.m_ReflectionCameras.get_Item(currentCamera) as Camera);
         if (!reflectionCamera)
         {
             GameObject gameObject = new GameObject(string.Concat(new object[]
             {
                 "Water Refl Camera id",
                 base.GetInstanceID(),
                 " for ",
                 currentCamera.GetInstanceID()
             }), new Type[]
             {
                 typeof(Camera),
                 typeof(Skybox)
             });
             reflectionCamera = gameObject.get_camera();
             reflectionCamera.set_enabled(false);
             reflectionCamera.get_transform().set_position(base.get_transform().get_position());
             reflectionCamera.get_transform().set_rotation(base.get_transform().get_rotation());
             reflectionCamera.get_gameObject().AddComponent("FlareLayer");
             gameObject.set_hideFlags(13);
             this.m_ReflectionCameras.set_Item(currentCamera, reflectionCamera);
         }
     }
     if (waterMode >= Water.WaterMode.Refractive)
     {
         if (!this.m_RefractionTexture || this.m_OldRefractionTextureSize != this.m_TextureSize)
         {
             if (this.m_RefractionTexture)
             {
                 Object.DestroyImmediate(this.m_RefractionTexture);
             }
             this.m_RefractionTexture = new RenderTexture(this.m_TextureSize, this.m_TextureSize, 16);
             this.m_RefractionTexture.set_name("__WaterRefraction" + base.GetInstanceID());
             this.m_RefractionTexture.set_isPowerOfTwo(true);
             this.m_RefractionTexture.set_hideFlags(4);
             this.m_OldRefractionTextureSize = this.m_TextureSize;
         }
         refractionCamera = (this.m_RefractionCameras.get_Item(currentCamera) as Camera);
         if (!refractionCamera)
         {
             GameObject gameObject2 = new GameObject(string.Concat(new object[]
             {
                 "Water Refr Camera id",
                 base.GetInstanceID(),
                 " for ",
                 currentCamera.GetInstanceID()
             }), new Type[]
             {
                 typeof(Camera),
                 typeof(Skybox)
             });
             refractionCamera = gameObject2.get_camera();
             refractionCamera.set_enabled(false);
             refractionCamera.get_transform().set_position(base.get_transform().get_position());
             refractionCamera.get_transform().set_rotation(base.get_transform().get_rotation());
             refractionCamera.get_gameObject().AddComponent("FlareLayer");
             gameObject2.set_hideFlags(13);
             this.m_RefractionCameras.set_Item(currentCamera, refractionCamera);
         }
     }
 }