示例#1
0
        private void OnWillRenderObject()
        {
            if (isRending || data == null)
            {
                return;
            }

            var camera = Camera.current;

            if (camera == null)
            {
                return;
            }

            OceanCameraTask oceanCamera;

            if (RenderHelper.TryGetOceanCamera(camera, out oceanCamera))
            {
                isRending          = true;
                requestCamera      = camera;
                requestOceanCamera = oceanCamera;
                oceanCamera.AddWillRenderOcean(this);
                oceanCamera.AddUnderOceanMarkDrawer(this);
            }
        }
示例#2
0
 public void OnPreReflectionRender(OceanCameraTask oceanCamera)
 {
     if (IsHasUnderOceanEffect)
     {
         underOceanEffectDisposer = new UnderOceanModeOptions.DisableUnderOceanEffectScope();
     }
 }
示例#3
0
        public override PreparedContent OnPreOceanRender(OceanCameraTask oceanCamera, OceanVolume ocean)
        {
            Matrix4x4 worldToLightMatrix;

            if (materialData.ModeObject.Mode.Cookie > 0 && oceanCamera.Data.SunLight != null)
            {
                var sunLightTransform = oceanCamera.Data.SunLight.transform;
                worldToLightMatrix = Matrix4x4.TRS(sunLightTransform.position, sunLightTransform.rotation, materialData.Data.Cookie.Scale).inverse;
            }
            else
            {
                worldToLightMatrix = Matrix4x4.identity;
            }
            Shader.SetGlobalMatrix(UnderCookieOptions.WorldToCookieMatrixShaderID, worldToLightMatrix);


            UnderOceanModeOptions.UpdateKeywords(materialData.ModeObject.Mode);
            if (!UnderMaterialOptions.UpdateShaderFields(materialData.Data))
            {
                if (materialData.Data.Cookie.Texture != null)
                {
                    Shader.SetGlobalTexture(UnderCookieOptions.TextureShaderFieldID, materialData.Data.Cookie.Texture.GetCurrentTexture());
                }
            }

            if (ProjectSettings.Current.RenderQueue == OceanRenderQueue.Transparent)
            {
                UnderOceanModeOptions.DisableUnderOceanFogEffect();
            }

            Shader.SetGlobalVector(UnderMaterialOptions.UnderOceanPositionShaderID, new Vector4(0, ocean.Height, 0, 0));

            return(PreparedContent.UnderOceanMarkTexture);
        }
示例#4
0
 public void SetValueToShader(OceanCameraTask oceanCamera, CameraTaskRippleData rippleData)
 {
     ClearFinalRipples();
     RippleFilter.Filter(oceanCamera, rippleData, observers, FinalRipples);
     SetValue(FinalRipples, FinalRippleOptions);
     RippleOptions.Accessor.SetGlobalValues(FinalRippleOptions);
 }
示例#5
0
            internal void InternalRenderColorAndDepth(Camera camera, OceanCameraTask oceanCamera, DepthEffecttProjectSettings setting, PreparedContent renderContents)
            {
                var textureSize        = RenderHelper.GetTextureSize(camera, setting.TextureScale);
                var colorRenderTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y);
                var depthRenderTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y, 24, RenderTextureFormat.Depth);

                renderCamera.clearFlags    = CameraClearFlags.Skybox;
                renderCamera.renderingPath = setting.CameraRenderingPath;
                RenderHelper.CopyCameraOptions(camera, renderCamera);
                RenderHelper.SetLayerWithoutWater(renderCamera, setting.CullingMask & camera.cullingMask);
                RenderHelper.CopySkyBox(oceanCamera, skybox);
                renderCamera.transform.position = camera.transform.position;
                renderCamera.transform.rotation = camera.transform.rotation;

                using (new RenderHelper.PointLightsScope(setting.EnablePointLights))
                {
                    oceanCamera.TaskController.OnPreRefractionRender(oceanCamera);
                    renderCamera.SetTargetBuffers(colorRenderTexture.colorBuffer, depthRenderTexture.depthBuffer);
                    renderCamera.Render();
                    renderCamera.targetTexture = null;
                    oceanCamera.TaskController.OnPostRefractionRender(oceanCamera);
                }

                RefractionTexture      = colorRenderTexture;
                RefractionDepthTexture = depthRenderTexture;
            }
示例#6
0
        public static bool TryGetOceanCamera(Camera camera, out OceanCameraTask oceanCamera)
        {
            oceanCamera = camera.GetComponent <OceanCameraTask>();
            if (oceanCamera == null)
            {
                oceanCamera = camera.gameObject.AddComponent <OceanCameraTask>();
            }
            return(true);

            //oceanCamera = camera.GetComponent<OceanCameraTask>();
            //if (oceanCamera != null)
            //{
            //    return true;
            //}
            //else
            //{
            //    if ((camera.hideFlags & HideFlags.HideAndDontSave) == 0)
            //    {
            //        oceanCamera = camera.gameObject.AddComponent<OceanCameraTask>();
            //        return true;
            //    }

            //    return false;
            //}
        }
示例#7
0
 public void OnPostReflectionRender(OceanCameraTask oceanCamera)
 {
     if (underOceanEffectDisposer != null)
     {
         underOceanEffectDisposer.Dispose();
         underOceanEffectDisposer = null;
     }
 }
示例#8
0
 public DepthTextureMode RenderDepthOnlyWhenOpaque(Camera camera, OceanCameraTask data, DepthEffecttProjectSettings setting, PreparedContent renderContents)
 {
     RemoveCommandBufferColor(camera);
     OceanIsOpaque();
     InternalRenderDepthOnly(camera, data, setting, renderContents);
     SetValuesToShader();
     return(DepthTextureMode.None);
 }
示例#9
0
 private void OnRenderObject()
 {
     if (Camera.current == requestCamera)
     {
         isRending          = false;
         requestCamera      = null;
         requestOceanCamera = null;
     }
 }
示例#10
0
 protected virtual void CollectOceanInfos(OceanCameraTask oceanCamera)
 {
     for (int i = 0; i < oceanCamera.WillRenderOceans.Count; i++)
     {
         var ocean   = oceanCamera.WillRenderOceans[i];
         var current = ocean.GetRenderContents(oceanCamera);
         PreparedContents |= current;
     }
 }
示例#11
0
            public DepthTextureMode Render(Camera camera, OceanCameraTask oceanCamera, ICameraTaskData data)
            {
                var quality = oceanCamera.projectSetting.Reflection;

                if ((data.PreparedContents & PreparedContent.ReflectionTexture) != 0)
                {
                    InternalRender(camera, oceanCamera, quality, data);
                }
                return(DepthTextureMode.None);
            }
示例#12
0
            internal void InternalRender(Camera camera, OceanCameraTask oceanCamera, ReflectionProjectSetting setting, ICameraTaskData data)
            {
                if (camera.orthographic)
                {
                    return;
                }

                var textureSize             = RenderHelper.GetTextureSize(camera, setting.TextureScale);
                var reflectionRenderTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y);

                renderCamera.renderingPath = setting.RenderingPath;
                RenderHelper.CopyCameraOptions(camera, renderCamera);
                RenderHelper.SetLayerWithoutWater(renderCamera, setting.CullingMask);
                RenderHelper.CopySkyBox(oceanCamera, skybox);

                {
                    Vector3 pos    = new Vector3(0, data.Height, 0);
                    Vector3 normal = data.Normal;

                    // Reflect camera around reflection plane
                    float   d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
                    Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

                    Matrix4x4 reflection = Matrix4x4.zero;
                    CalculateReflectionMatrix(ref reflection, reflectionPlane);
                    renderCamera.transform.position  = reflection.MultiplyPoint(camera.transform.position);
                    renderCamera.worldToCameraMatrix = camera.worldToCameraMatrix * reflection;

                    // Setup oblique projection matrix so that near plane is our reflection
                    // plane. This way we clip everything below/above it for free.
                    Vector4 clipPlane = CameraSpacePlane(renderCamera, pos, normal, 1.0f);
                    renderCamera.projectionMatrix = camera.CalculateObliqueMatrix(clipPlane);

                    //// Set custom culling matrix from the current camera
                    renderCamera.cullingMatrix = camera.projectionMatrix * camera.worldToCameraMatrix;

                    Vector3 euler = camera.transform.eulerAngles;
                    renderCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
                }

                using (new RenderHelper.InvertCullingScope())
                {
                    using (new RenderHelper.PointLightsScope(setting.EnablePointLights))
                    {
                        oceanCamera.TaskController.OnPreReflectionRender(oceanCamera);
                        renderCamera.targetTexture = reflectionRenderTexture;
                        renderCamera.Render();
                        renderCamera.targetTexture = null;
                        oceanCamera.TaskController.OnPostReflectionRender(oceanCamera);
                    }
                }

                ReflectionTexture = reflectionRenderTexture;
                SetValuesToShader();
            }
示例#13
0
        public static bool TryGet(OceanCameraTask oceanCamera, out OceanVolume result)
        {
            if (activated.Count != 0)
            {
                result = activated[0];
                return(true);
            }

            result = default;
            return(false);
        }
示例#14
0
        protected virtual void CollectUnderOceanInfos(OceanCameraTask oceanCamera, OceanVolume ocean)
        {
            if (oceanCamera.EnableUnderOceanEffect)
            {
                if (ocean.EnableUnderOcean && ocean.UnderOceanData != null)
                {
                    PreparedContents     |= ocean.UnderOceanData.OnPreOceanRender(oceanCamera, ocean);
                    IsHasUnderOceanEffect = true;
                    return;
                }
            }

            UnderOceanModeOptions.DisableUnderOceanEffectAll();
        }
示例#15
0
 public void SetValueToShader(OceanCameraTask oceanCamera, FoamCameraData data, PreparedContent preparedContent)
 {
     if (ProjectSettings.Current.Foam.EnabledFoamShpereCulling)
     {
         if ((preparedContent & PreparedContent.Foam16) != 0)
         {
             SetValueToShader(oceanCamera, data, 16, 4);
         }
         else if ((preparedContent & PreparedContent.Foam8) != 0)
         {
             SetValueToShader(oceanCamera, data, 8, 2);
         }
     }
 }
示例#16
0
 public static void CopySkyBox(OceanCameraTask source, Skybox skybox)
 {
     if (source.ThisCamera.clearFlags == CameraClearFlags.Skybox)
     {
         Skybox sourceSkyBox = source.Skybox;
         if (sourceSkyBox != null && sourceSkyBox.material != null)
         {
             skybox.enabled  = true;
             skybox.material = sourceSkyBox.material;
             return;
         }
     }
     skybox.enabled = false;
 }
示例#17
0
 internal void AddCommandBufferColor(Camera camera, OceanCameraTask data)
 {
     if (!isAddCameraColor)
     {
         if (colorCommandBuffer == null)
         {
             colorCommandBuffer      = new CommandBuffer();
             colorCommandBuffer.name = "Refraction ocean color";
             int screenCopy = Shader.PropertyToID("ScreenCopy");
             colorCommandBuffer.GetTemporaryRT(screenCopy, -1, -1, 0, FilterMode.Bilinear);
             colorCommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, screenCopy);
             colorCommandBuffer.SetGlobalTexture(RefractionTextureShaderID, screenCopy);
         }
         isAddCameraColor = true;
         camera.AddCommandBuffer(colorCameraEvent, colorCommandBuffer);
     }
 }
示例#18
0
        public virtual void OnPreOceanRender(OceanCameraTask oceanCamera)
        {
            SunLight = GetSunlight();
            CollectOceanInfos(oceanCamera);

            OceanVolume ocean;

            if (OceanVolume.TryGet(oceanCamera, out ocean))
            {
                Height = ocean.Height;
                Normal = ocean.Normal;
                CollectUnderOceanInfos(oceanCamera, ocean);
            }
            else
            {
                Height = 0;
                Normal = Vector3.up;
                UnderOceanModeOptions.DisableUnderOceanEffectAll();
            }

            Shader.SetGlobalFloat(OceanShaderOptions.TimeShaderID, OceanTime);

            if ((PreparedContents & PreparedContent.SunLight) != 0 && SunLight != null)
            {
                Vector4 pos = SunLight.transform.eulerAngles;
                pos.w = Vector3.Dot(new Vector3(0, -1, 0), SunLight.transform.forward);
                Shader.SetGlobalVector(OceanShaderOptions.SunLightShaderID, pos);
                Shader.SetGlobalColor(OceanShaderOptions.SunLightColorShaderID, SunLight.color);
            }

            if ((PreparedContents & PreparedContent.Ripple) != 0)
            {
                RippleSystem.Current.SetValueToShader(oceanCamera, new CameraTaskRippleData()
                {
                    OceanHeight = Height
                });
            }

            FoamShpereSystem.Current.SetValueToShader(oceanCamera, FoamData, PreparedContents);
            FoamAreaSystem.Current.SetValueToShader(oceanCamera, PreparedContents);
        }
示例#19
0
        private void OnWillRenderObject()
        {
            var camera = Camera.current;

            if (camera == null)
            {
                return;
            }

            OceanCameraTask oceanCamera = camera.GetComponent <OceanCameraTask>();

            if (oceanCamera != null)
            {
                if (markMaterial == null)
                {
                    Debug.LogError(new ArgumentNullException(nameof(markMaterial)), this);
                    return;
                }

                UpdateMarkPosition(camera.transform);
                oceanCamera.AddUnderOceanMarkDrawer(this);
            }
        }
示例#20
0
            public DepthTextureMode Render(Camera camera, OceanCameraTask oceanCamera, PreparedContent renderContents)
            {
                try
                {
                    if (((renderContents & PreparedContent.UnderOceanMarkTexture) == 0) || (underOceanMarkDrawers.Count == 0 && underOceanMarkObservers.Count == 0))
                    {
                        Shader.SetGlobalTexture(UnderOceanMarkTextureShaderID, BlackTexture.Value);
                        Shader.SetGlobalTexture(UnderOceanMarkDepthTextureShaderID, BlackTexture.Value);
                        return(DepthTextureMode.None);
                    }

                    CameraTaskEvent eventValue = new CameraTaskEvent(renderCamera, oceanCamera, oceanCamera.projectSetting.MarkLayer);
                    NotifyObservers(underOceanMarkDrawers, eventValue);
                    NotifyObservers(underOceanMarkObservers, eventValue);

                    var textureSize = RenderHelper.GetTextureSize(camera, oceanCamera.projectSetting.UnderOceanMark.TextureScale);
                    UnderOceanMarkTexture      = RenderTexture.GetTemporary(textureSize.x, textureSize.y);
                    UnderOceanMarkDepthTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y, 24, RenderTextureFormat.Depth);

                    RenderHelper.CopyCameraOptions(camera, renderCamera);
                    renderCamera.cullingMask = oceanCamera.projectSetting.MarkCullingMask;

                    renderCamera.transform.position = camera.transform.position;
                    renderCamera.transform.rotation = camera.transform.rotation;

                    renderCamera.SetTargetBuffers(UnderOceanMarkTexture.colorBuffer, UnderOceanMarkDepthTexture.depthBuffer);
                    renderCamera.Render();
                    renderCamera.targetTexture = null;

                    SetValuesToShader();
                    return(DepthTextureMode.None);
                }
                finally
                {
                    underOceanMarkDrawers.Clear();
                }
            }
示例#21
0
            public DepthTextureMode Render(Camera camera, OceanCameraTask data, PreparedContent renderContents)
            {
                var quality = data.projectSetting.DepthEffect;

                if ((renderContents & PreparedContent.RefractionTexture) != 0)
                {
                    switch (quality.RenderMode)
                    {
                    case DepthEffectRenderMode.Camera:
                        return(RenderWhenOpaque(camera, data, quality, renderContents));

                    case DepthEffectRenderMode.Buffer:
                        return(RenderWhenTransparent(camera, data));

                    default:
                        Debug.LogError(new ArgumentOutOfRangeException(nameof(quality.RenderMode), quality.RenderMode, "Unkonw value"), camera);
                        return(DepthTextureMode.None);
                    }
                }
                else if ((renderContents & PreparedContent.RefractionDepthTexture) != 0)
                {
                    switch (quality.RenderMode)
                    {
                    case DepthEffectRenderMode.Buffer:
                        return(RenderDepthOnlyWhenTransparent(camera, data));

                    case DepthEffectRenderMode.Camera:
                        return(RenderDepthOnlyWhenOpaque(camera, data, quality, renderContents));

                    default:
                        Debug.LogError(new ArgumentOutOfRangeException(nameof(quality.RenderMode), quality.RenderMode, "Unkonw value"), camera);
                        return(DepthTextureMode.None);
                    }
                }
                return(DepthTextureMode.None);
            }
示例#22
0
        public void SetValueToShader(OceanCameraTask oceanCamera, PreparedContent preparedContent)
        {
            if ((preparedContent & PreparedContent.FoamArea1) != 0)
            {
                if (observers.Count == 0)
                {
                    ResetShader();
                    return;
                }
                else if (observers.Count == 1)
                {
                    SetValueToShader(observers[0]);
                }
                else
                {
                    Vector3 cameraPos = oceanCamera.transform.position;

                    IFoamArea min    = observers[0];
                    float     minDis = Vector3.Distance(cameraPos, min.Position);

                    for (int i = 1; i < observers.Count; i++)
                    {
                        var current    = observers[i];
                        var currentDis = Vector3.Distance(cameraPos, current.Position);

                        if (currentDis < minDis)
                        {
                            min    = current;
                            minDis = currentDis;
                        }
                    }

                    SetValueToShader(min);
                }
            }
        }
示例#23
0
 public abstract void OnPostOceanRender(OceanCameraTask oceanCamera);
示例#24
0
 public abstract PreparedContent OnPreOceanRender(OceanCameraTask oceanCamera, OceanVolume ocean);
示例#25
0
 private void OnEnable()
 {
     unsubscriber = OceanCameraTask.SubscribeClipMarkDraw(this);
 }
示例#26
0
 void IRippleData.OnSelecte(OceanCameraTask camera)
 {
     Texture = frameAnimation.GetCurrentTexture();
 }
示例#27
0
 bool IRippleData.OnEnter(OceanCameraTask camera)
 {
     return(frameAnimation != null);
 }
示例#28
0
 public abstract PreparedContent GetRenderContents(OceanCameraTask oceanCamera);
示例#29
0
 public DepthTextureMode RenderDepthOnlyWhenTransparent(Camera camera, OceanCameraTask data)
 {
     RemoveCommandBufferColor(camera);
     OceanIsTransparent();
     return(DepthTextureMode.Depth);
 }
示例#30
0
        public override PreparedContent GetRenderContents(OceanCameraTask oceanCamera)
        {
            PreparedContent preparedContents = Data.GetRenderContents(lodLevel);

            return(preparedContents);
        }