Esempio n. 1
0
        Texture FindTexture(CameraData data, Camera cam)
        {
            if(Ocean.Instance == null) return null;

            WaveSpectrum spectrum = Ocean.Instance.GetComponent<WaveSpectrum>();

            switch(display)
            {

            case DISPLAY.OVERLAY_HEIGHT:
                return (data.overlay == null) ? null : data.overlay.height;

            case DISPLAY.OVERLAY_NORMAL:
                return (data.overlay == null) ? null : data.overlay.normal;

            case DISPLAY.OVERLAY_FOAM:
                return (data.overlay == null) ? null : data.overlay.foam;

            case DISPLAY.OVERLAY_CLIP:
                return (data.overlay == null) ? null : data.overlay.clip;

            case DISPLAY.REFLECTION:
                return (data.reflection == null) ? null : data.reflection.tex;

            case DISPLAY.OCEAN_MASK:
                return (data.mask == null) ? null : data.mask.cam.targetTexture;

            case DISPLAY.OCEAN_DEPTH:
                return (data.depth == null || data.depth.cam == null) ? null : data.depth.cam.targetTexture;

            case DISPLAY.WAVE_SLOPEMAP0:
                return (spectrum == null) ? null : spectrum.SlopeMaps[0];

            case DISPLAY.WAVE_SLOPEMAP1:
                return (spectrum == null) ? null : spectrum.SlopeMaps[1];

            case DISPLAY.WAVE_DISPLACEMENTMAP0:
                return (spectrum == null) ? null : spectrum.DisplacementMaps[0];

            case DISPLAY.WAVE_DISPLACEMENTMAP1:
                return (spectrum == null) ? null : spectrum.DisplacementMaps[1];

            case DISPLAY.WAVE_DISPLACEMENTMAP2:
                return (spectrum == null) ? null : spectrum.DisplacementMaps[2];

            case DISPLAY.WAVE_DISPLACEMENTMAP3:
                return (spectrum == null) ? null : spectrum.DisplacementMaps[3];

            case DISPLAY.WAVE_FOAM0:
                return (spectrum == null) ? null : spectrum.FoamMaps[0];

            case DISPLAY.WAVE_FOAM1:
                return (spectrum == null) ? null : spectrum.FoamMaps[1];

            default:
                return null;
            }
        }
Esempio n. 2
0
 private Texture FindTexture(CameraData data, Camera cam)
 {
     if (Ocean.Instance == null)
     {
         return null;
     }
     WaveSpectrum component = Ocean.Instance.GetComponent<WaveSpectrum>();
     switch (this.display)
     {
     case DisplayTexture.DISPLAY.OVERLAY_HEIGHT:
         return (data.overlay != null) ? data.overlay.height : null;
     case DisplayTexture.DISPLAY.OVERLAY_NORMAL:
         return (data.overlay != null) ? data.overlay.normal : null;
     case DisplayTexture.DISPLAY.OVERLAY_FOAM:
         return (data.overlay != null) ? data.overlay.foam : null;
     case DisplayTexture.DISPLAY.OVERLAY_CLIP:
         return (data.overlay != null) ? data.overlay.clip : null;
     case DisplayTexture.DISPLAY.REFLECTION:
         return (data.reflection != null) ? data.reflection.tex : null;
     case DisplayTexture.DISPLAY.OCEAN_MASK:
         return (data.mask != null) ? data.mask.cam.targetTexture : null;
     case DisplayTexture.DISPLAY.OCEAN_DEPTH:
         return (data.depth != null && !(data.depth.cam == null)) ? data.depth.cam.targetTexture : null;
     case DisplayTexture.DISPLAY.WAVE_SLOPEMAP0:
         return (!(component == null)) ? component.SlopeMaps[0] : null;
     case DisplayTexture.DISPLAY.WAVE_SLOPEMAP1:
         return (!(component == null)) ? component.SlopeMaps[1] : null;
     case DisplayTexture.DISPLAY.WAVE_DISPLACEMENTMAP0:
         return (!(component == null)) ? component.DisplacementMaps[0] : null;
     case DisplayTexture.DISPLAY.WAVE_DISPLACEMENTMAP1:
         return (!(component == null)) ? component.DisplacementMaps[1] : null;
     case DisplayTexture.DISPLAY.WAVE_DISPLACEMENTMAP2:
         return (!(component == null)) ? component.DisplacementMaps[2] : null;
     case DisplayTexture.DISPLAY.WAVE_DISPLACEMENTMAP3:
         return (!(component == null)) ? component.DisplacementMaps[3] : null;
     case DisplayTexture.DISPLAY.WAVE_FOAM0:
         return (!(component == null)) ? component.FoamMaps[0] : null;
     case DisplayTexture.DISPLAY.WAVE_FOAM1:
         return (!(component == null)) ? component.FoamMaps[1] : null;
     default:
         return null;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Update the projection data for this camera.
        /// If this is the scene view camera you may not want to project
        /// the grid from its point of view but instead from the main
        /// cameras view so you can see how the mesh is being projected.
        /// </summary>
        public void UpdateProjection(Camera camera, CameraData data)
        {
            Camera cam = camera;

            if (cam == null || data == null)
            {
                return;
            }

            if (data.projection == null)
            {
                data.projection = new ProjectionData();
            }

            if (data.projection.IsViewUpdated(camera))
            {
                return;
            }

            //Used to debug projection.
            if (Ocean.DISABLE_PROJECT_SCENE_VIEW && cam.name == "SceneCamera" && Camera.main != null)
            {
                cam = Camera.main;
            }

            //Aim the projector given the current camera position.
            //Find the most practical but visually pleasing projection.
            //Sets the m_projectorV and m_projectorP matrices.
            AimProjector(cam);

            //Create a view projection matrix.
            MulMatrixByMatrix(m_projectorVP, m_projectorP, m_projectorV);

            //Create the m_projectorR matrix.
            //Finds the range the projection must fit
            //for the projected grid to cover the screen.
            CreateRangeMatrix(cam, m_projectorVP);

            //Create the inverse view projection range matrix.
            Inverse(MATRIX_BUFFER0, m_projectorVP);
            MulMatrixByMatrix(m_projectorIVP, MATRIX_BUFFER0, m_projectorR);

            //Set the interpolation points based on IVP matrix.
            HProject(m_projectorIVP, m_quad[0], VECTOR_BUFFER);
            SetRow(0, m_projectorI, VECTOR_BUFFER);

            HProject(m_projectorIVP, m_quad[1], VECTOR_BUFFER);
            SetRow(1, m_projectorI, VECTOR_BUFFER);

            HProject(m_projectorIVP, m_quad[2], VECTOR_BUFFER);
            SetRow(2, m_projectorI, VECTOR_BUFFER);

            HProject(m_projectorIVP, m_quad[3], VECTOR_BUFFER);
            SetRow(3, m_projectorI, VECTOR_BUFFER);

            //Save a copy of the view projection range matrix and the interpolation matrix.
            Inverse(MATRIX_BUFFER0, m_projectorR);
            MulMatrixByMatrix(MATRIX_BUFFER1, MATRIX_BUFFER0, m_projectorVP);

            CopyMatrix(ref data.projection.projectorVP, MATRIX_BUFFER1);
            CopyMatrix(ref data.projection.interpolation, m_projectorI);

            data.projection.SetViewAsUpdated(camera);
        }
Esempio n. 4
0
        /// <summary>
        /// If called it means a grid is about to be rendered by the current camera.
        /// </summary>
        //OYM:  调用来表示当前相机渲染的网格
        void ApplyProjection(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                Camera cam = Camera.current;

                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                if (data.projection == null)
                {
                    data.projection = new ProjectionData();//OYM:  获取...这啥,创建投影数据?
                }
                //OYM:  作者说,如果相机还没计算项目的投影的话,则立即计算.
                //If the projection for this camera has
                //not been calculated yet do it now.
                if (!data.projection.IsViewUpdated(cam))//OYM:
                {
                    //Update set to true in this function call
                    m_ocean.Projection.UpdateProjection(cam, data);

                    Shader.SetGlobalMatrix("Ceto_Interpolation", data.projection.interpolation);
                    Shader.SetGlobalMatrix("Ceto_ProjectorVP", data.projection.projectorVP);
                }

                //If the projection has been flipped it will reverse
                //the mesh triangle so need to flip the cull face.
                if (!data.projection.checkedForFlipping)
                {
                    int back  = (int)CullMode.Back;
                    int front = (int)CullMode.Front;

                    if (!Ocean.DISABLE_PROJECTION_FLIPPING)
                    {
                        bool isFlipped = m_ocean.Projection.IsFlipped;

                        if (oceanTopSideMat != null)
                        {
                            oceanTopSideMat.SetInt("_CullFace", (isFlipped) ? front : back);
                        }

                        if (oceanUnderSideMat != null)
                        {
                            oceanUnderSideMat.SetInt("_CullFace", (isFlipped) ? back : front);
                        }
                    }
                    else
                    {
                        if (oceanTopSideMat != null)
                        {
                            oceanTopSideMat.SetInt("_CullFace", back);
                        }

                        if (oceanUnderSideMat != null)
                        {
                            oceanUnderSideMat.SetInt("_CullFace", front);
                        }
                    }

                    data.projection.checkedForFlipping = true;
                }

                UpdateBounds(go, cam);
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Render depth information about a object using a replacement shader.
        /// If the ocean renders into the depth buffer then the shader can not get
        /// depth info about what has been rendered under it as Unity will have already
        /// written the ocean mesh into depth buffer by then.
        /// Will also create the refraction grab if needed.
        /// </summary>
        public override void RenderOceanDepth(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                Camera cam = Camera.current;
                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                if (data.depth == null)
                {
                    data.depth = new DepthData();
                }

                if (data.depth.updated)
                {
                    return;
                }

                //zero the texture so if there is a issue the underwater effect will not screw up the rest of the rendering.
                Shader.SetGlobalTexture(Ocean.REFRACTION_GRAB_TEXTURE_NAME, Texture2D.blackTexture);
                Shader.SetGlobalTexture(Ocean.DEPTH_GRAB_TEXTURE_NAME, Texture2D.whiteTexture);
                Shader.SetGlobalTexture("Ceto_OceanDepth", Texture2D.whiteTexture);

                //If this camera has disable the underwater turn it off in the shader and return.
                if (GetDisableUnderwater(data.settings))
                {
                    Shader.DisableKeyword("CETO_UNDERWATER_ON");
                    data.depth.updated = true;
                    return;
                }
                else
                {
                    Shader.EnableKeyword("CETO_UNDERWATER_ON");
                }

                if (cam.name == "SceneCamera" || SystemInfo.graphicsShaderLevel < 30)
                {
                    //Adding command to scene camera is causing some problems and may as
                    //well not use the ocean depth pass so its consistent between modes
                    //so just bind something that wont cause a issue.

                    //If not using the ocean depths all thats needed is the IVP
                    //to extract the world pos from the depth buffer.
                    Matrix4x4 ivp = cam.projectionMatrix * cam.worldToCameraMatrix;
                    Shader.SetGlobalMatrix("Ceto_Camera_IVP", ivp.inverse);

                    data.depth.updated = true;
                }
                else if (depthMode == DEPTH_MODE.USE_DEPTH_BUFFER)
                {
                    //Cam must have depth mode enabled to use depth buffer.
                    cam.depthTextureMode |= DepthTextureMode.Depth;

                    //If not using the ocean depths all thats needed is the IVP
                    //to extract the world pos from the depth buffer.
                    Matrix4x4 ivp = cam.projectionMatrix * cam.worldToCameraMatrix;
                    Shader.SetGlobalMatrix("Ceto_Camera_IVP", ivp.inverse);

                    //Add the command to camera.
                    //The default implementation will just grab the depth and the screen.
                    CreateRefractionGrab(cam, data.depth);

                    data.depth.updated = true;
                }
                else if (depthMode == DEPTH_MODE.USE_OCEAN_DEPTH_PASS)
                {
                    CreateDepthCameraFor(cam, data.depth);
                    CreateRefractionGrab(cam, data.depth);

                    data.depth.cam.cullingMask = GetOceanDepthsLayermask(data.settings);
                    data.depth.cam.cullingMask = OceanUtility.HideLayer(data.depth.cam.cullingMask, Ocean.OCEAN_LAYER);

                    NotifyOnEvent.Disable = true;
                    data.depth.cam.RenderWithShader(oceanDepthSdr, "RenderType");
                    NotifyOnEvent.Disable = false;

                    Shader.SetGlobalTexture("Ceto_OceanDepth", data.depth.cam.targetTexture);

                    data.depth.updated = true;
                }
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Called before camera culls the ocean.
 /// </summary>
 public virtual void OceanOnPreCull(Camera cam, CameraData data)
 {
 }
Esempio n. 7
0
        /// <summary>
        /// This game object is about to be rendered
        /// and requires the wave overlays.
        /// Create them for the camera rendering the object
        /// if they have not already been updated this frame.
        /// </summary>
        public void RenderWaveOverlays(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                Camera cam = Camera.current;

                if (!m_cameraData.ContainsKey(cam))
                {
                    m_cameraData.Add(cam, new CameraData());
                }

                CameraData data = m_cameraData[cam];

                if (data.overlay == null)
                {
                    data.overlay = new WaveOverlayData();
                }

                if (data.projection == null)
                {
                    data.projection = new ProjectionData();
                }

                if (data.overlay.IsViewUpdated(cam))
                {
                    return;
                }

                //If the projection for this camera has not been updated this frame do it now.
                if (!data.projection.IsViewUpdated(cam))
                {
                    Projection.UpdateProjection(cam, data);

                    Shader.SetGlobalMatrix("Ceto_Interpolation", data.projection.interpolation);
                    Shader.SetGlobalMatrix("Ceto_ProjectorVP", data.projection.projectorVP);
                }

                //If overlays have been disabled for this camera
                //clear the buffers and return;
                if (GetDisableAllOverlays(data.settings))
                {
                    OverlayManager.DestroyBuffers(data.overlay);
                    Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture);
                    Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture);
                    Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture);
                    Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture);
                }
                else
                {
                    OVERLAY_MAP_SIZE normalSize = (data.settings != null) ? data.settings.normalOverlaySize : normalOverlaySize;
                    OVERLAY_MAP_SIZE heightSize = (data.settings != null) ? data.settings.heightOverlaySize : heightOverlaySize;
                    OVERLAY_MAP_SIZE foamSize   = (data.settings != null) ? data.settings.foamOverlaySize : foamOverlaySize;
                    OVERLAY_MAP_SIZE clipSize   = (data.settings != null) ? data.settings.clipOverlaySize : clipOverlaySize;

                    //Create the overlay buffers.
                    OverlayManager.CreateOverlays(cam, data.overlay, normalSize, heightSize, foamSize, clipSize);

                    //Update blend modes.
                    OverlayManager.HeightOverlayBlendMode = heightBlendMode;
                    OverlayManager.FoamOverlayBlendMode   = foamBlendMode;

                    //Render the overlays
                    OverlayManager.RenderWaveOverlays(cam, data.overlay);
                }

                data.overlay.SetViewAsUpdated(cam);
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
Esempio n. 8
0
 public virtual void OceanOnPreCull(Camera cam, CameraData data)
 {
 }
Esempio n. 9
0
        /// <summary>
        /// Render the reflections for this objects position
        /// and the current camera.
        /// </summary>
        public void RenderReflection(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                Camera cam = Camera.current;
                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                //Create the data needed if not already created.
                if (data.reflection == null)
                {
                    data.reflection = new ReflectionData();
                }

                if (data.reflection.IsViewUpdated(cam))
                {
                    return;
                }

                //If this camera has disable the reflection turn it off in the shader and return.
                if (GetDisableReflections(data.settings))
                {
                    Shader.DisableKeyword("CETO_REFLECTION_ON");
                    data.reflection.SetViewAsUpdated(cam);
                    return;
                }
                else
                {
                    Shader.EnableKeyword("CETO_REFLECTION_ON");
                }

                RenderTexture reflections0 = null;
                RenderTexture reflections1 = null;

                if (data.reflection.cam != null)
                {
                    DisableFog disableFog = data.reflection.cam.GetComponent <DisableFog>();
                    if (disableFog != null)
                    {
                        disableFog.enabled = !fogInReflection;
                    }
                }

                if (RenderReflectionCustom != null)
                {
                    //If using a custom method
                    //Destroy the camera if already created as its no longer needed.
                    if (data.reflection.cam != null)
                    {
                        data.reflection.DestroyTargets();
                    }

                    CreateRenderTarget(data.reflection, cam.pixelWidth, cam.pixelHeight, cam.allowHDR, false, data.settings);

                    //Create the dummy object if null
                    if (m_dummy == null)
                    {
                        m_dummy           = new GameObject("Ceto Reflection Dummy Gameobject");
                        m_dummy.hideFlags = HideFlags.HideAndDontSave;
                    }

                    //Set the position of the reflection plane.
                    m_dummy.transform.position = new Vector3(0.0f, m_ocean.level, 0.0f);
                    //Copy returned texture in target.
                    Graphics.Blit(RenderReflectionCustom(m_dummy), data.reflection.target0);
                    reflections0 = data.reflection.target0;
                    reflections1 = null; //Custom stero not supported.
                }
                else
                {
                    //Else use normal method.
                    CreateReflectionCameraFor(cam, data.reflection);
                    CreateRenderTarget(data.reflection, cam.pixelWidth, cam.pixelHeight, cam.allowHDR, cam.stereoEnabled, data.settings);

                    if (cam.stereoEnabled)
                    {
                        RenderSteroReflection(data.reflection, cam, data.settings);
                        reflections0 = data.reflection.target0;
                        reflections1 = data.reflection.target1;
                    }
                    else
                    {
                        Shader.DisableKeyword("CETO_STERO_CAMERA");
                        RenderReflection(data.reflection.cam, data.reflection.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix, data.settings);
                        reflections0 = data.reflection.target0;
                        reflections1 = null;
                    }
                }

                //The reflections texture should now contain the rendered
                //reflections for the current cameras view.
                if (reflections0 != null)
                {
                    m_imageBlur.BlurIterations = blurIterations;
                    m_imageBlur.BlurMode       = blurMode;
                    m_imageBlur.BlurSpread     = blurSpread;
                    m_imageBlur.Blur(reflections0);

                    Shader.SetGlobalTexture(Ocean.REFLECTION_TEXTURE_NAME0, reflections0);
                }

                if (reflections1 != null)
                {
                    m_imageBlur.BlurIterations = blurIterations;
                    m_imageBlur.BlurMode       = blurMode;
                    m_imageBlur.BlurSpread     = blurSpread;
                    m_imageBlur.Blur(reflections1);

                    Shader.SetGlobalTexture(Ocean.REFLECTION_TEXTURE_NAME1, reflections1);
                }

                data.reflection.SetViewAsUpdated(cam);
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Called after this camera has rendered the ocean.
        /// </summary>
        public override void OceanOnPostRender(Camera cam, CameraData data)
        {
            if (!enabled || cam == null || data == null) return;

            Grid grid = null;
            m_grids.TryGetValue(resolution, out grid);

            if(grid == null) return;

            //Need to reset bounds after rendering so the next
            //camera to render grid will not cull it if the
            //bounds are not visible to it.
            ResetBounds(grid);
        }
Esempio n. 11
0
 private void Update()
 {
     try
     {
         this.WindDirVector = this.CalculateWindDirVector();
         this.UpdateOceanScheduler();
         this.OverlayManager.Update();
         this.specularRoughness = Mathf.Clamp01(this.specularRoughness);
         this.specularIntensity = Mathf.Max(0f, this.specularIntensity);
         this.minFresnel        = Mathf.Clamp01(this.minFresnel);
         this.fresnelPower      = Mathf.Max(0f, this.fresnelPower);
         this.foamIntensity     = Math.Max(0f, this.foamIntensity);
         float value = Mathf.Lerp(2E-05f, 0.02f, this.specularRoughness);
         Shader.SetGlobalColor("Ceto_DefaultSkyColor", this.defaultSkyColor);
         Shader.SetGlobalColor("Ceto_DefaultOceanColor", this.defaultOceanColor);
         Shader.SetGlobalFloat("Ceto_SpecularRoughness", value);
         Shader.SetGlobalFloat("Ceto_FresnelPower", this.fresnelPower);
         Shader.SetGlobalFloat("Ceto_SpecularIntensity", this.specularIntensity);
         Shader.SetGlobalFloat("Ceto_MinFresnel", this.minFresnel);
         Shader.SetGlobalFloat("Ceto_OceanLevel", this.level);
         Shader.SetGlobalFloat("Ceto_MaxWaveHeight", 40f);
         Shader.SetGlobalColor("Ceto_FoamTint", this.foamTint * this.foamIntensity);
         Shader.SetGlobalVector("Ceto_SunDir", this.SunDir());
         Shader.SetGlobalVector("Ceto_SunColor", this.SunColor());
         Vector4 value2 = default(Vector4);
         value2.x = ((this.foamTexture0.scale.x == 0f) ? 1f : (1f / this.foamTexture0.scale.x));
         value2.y = ((this.foamTexture0.scale.y == 0f) ? 1f : (1f / this.foamTexture0.scale.y));
         value2.z = this.foamTexture0.scrollSpeed * this.OceanTime.Now;
         value2.w = 0f;
         Vector4 value3 = default(Vector4);
         value3.x = ((this.foamTexture1.scale.x == 0f) ? 1f : (1f / this.foamTexture1.scale.x));
         value3.y = ((this.foamTexture1.scale.y == 0f) ? 1f : (1f / this.foamTexture1.scale.y));
         value3.z = this.foamTexture1.scrollSpeed * this.OceanTime.Now;
         value3.w = 0f;
         Shader.SetGlobalTexture("Ceto_FoamTexture0", (!(this.foamTexture0.tex != null)) ? Texture2D.whiteTexture : this.foamTexture0.tex);
         Shader.SetGlobalVector("Ceto_FoamTextureScale0", value2);
         Shader.SetGlobalTexture("Ceto_FoamTexture1", (!(this.foamTexture1.tex != null)) ? Texture2D.whiteTexture : this.foamTexture1.tex);
         Shader.SetGlobalVector("Ceto_FoamTextureScale1", value3);
         foreach (KeyValuePair <Camera, CameraData> keyValuePair in this.m_cameraData)
         {
             CameraData value4 = keyValuePair.Value;
             if (value4.mask != null && !value4.mask.updated)
             {
                 value4.mask.updatedLastFrame = false;
             }
             if (value4.mask != null)
             {
                 value4.mask.updated = false;
             }
             if (value4.depth != null)
             {
                 value4.depth.updated = false;
             }
             if (value4.overlay != null)
             {
                 value4.overlay.updated = false;
             }
             if (value4.reflection != null)
             {
                 value4.reflection.updated = false;
             }
             if (value4.projection != null)
             {
                 value4.projection.updated            = false;
                 value4.projection.checkedForFlipping = false;
             }
         }
     }
     catch (Exception ex)
     {
         Ocean.LogError(ex.ToString());
         this.DisableOcean();
     }
 }
Esempio n. 12
0
 public override void OceanOnPostRender(Camera cam, CameraData data)
 {
     if (!base.enabled || cam == null || data == null)
     {
         return;
     }
     ProjectedGrid.Grid grid = null;
     this.m_grids.TryGetValue(this.resolution, out grid);
     if (grid == null)
     {
         return;
     }
     this.ResetBounds(grid);
 }
Esempio n. 13
0
        Texture FindTexture(CameraData data, Camera cam)
        {
            if (Ocean.Instance == null)
            {
                return(null);
            }

            WaveSpectrum spectrum = Ocean.Instance.GetComponent <WaveSpectrum>();

            switch (display)
            {
            case DISPLAY.OVERLAY_HEIGHT:
                return((data.overlay == null) ? null : data.overlay.height);

            case DISPLAY.OVERLAY_NORMAL:
                return((data.overlay == null) ? null : data.overlay.normal);

            case DISPLAY.OVERLAY_FOAM:
                return((data.overlay == null) ? null : data.overlay.foam);

            case DISPLAY.OVERLAY_CLIP:
                return((data.overlay == null) ? null : data.overlay.clip);

            case DISPLAY.REFLECTION0:
                return((data.reflection == null) ? null : data.reflection.target0);

            case DISPLAY.REFLECTION1:
                return((data.reflection == null) ? null : data.reflection.target1);

            case DISPLAY.OCEAN_MASK0:
                return((data.mask == null) ? null : data.mask.target0);

            case DISPLAY.OCEAN_MASK1:
                return((data.mask == null) ? null : data.mask.target1);

            case DISPLAY.OCEAN_DEPTH0:
                return((data.depth == null) ? null : data.depth.target0);

            case DISPLAY.OCEAN_DEPTH1:
                return((data.depth == null) ? null : data.depth.target1);

            case DISPLAY.WAVE_SLOPEMAP0:
                return((spectrum == null) ? null : spectrum.SlopeMaps[0]);

            case DISPLAY.WAVE_SLOPEMAP1:
                return((spectrum == null) ? null : spectrum.SlopeMaps[1]);

            case DISPLAY.WAVE_DISPLACEMENTMAP0:
                return((spectrum == null) ? null : spectrum.DisplacementMaps[0]);

            case DISPLAY.WAVE_DISPLACEMENTMAP1:
                return((spectrum == null) ? null : spectrum.DisplacementMaps[1]);

            case DISPLAY.WAVE_DISPLACEMENTMAP2:
                return((spectrum == null) ? null : spectrum.DisplacementMaps[2]);

            case DISPLAY.WAVE_DISPLACEMENTMAP3:
                return((spectrum == null) ? null : spectrum.DisplacementMaps[3]);

            case DISPLAY.WAVE_FOAM0:
                return((spectrum == null) ? null : spectrum.FoamMaps[0]);

            case DISPLAY.WAVE_FOAM1:
                return((spectrum == null) ? null : spectrum.FoamMaps[1]);

            default:
                return(null);
            }
        }
Esempio n. 14
0
        void Update()
        {
            // ####################################################### Modificação #######################################################################
            int    indice = 0;
            string line;

            System.IO.StreamReader file =
                new System.IO.StreamReader(@"\\VISUALIZADOR_04\server\ultimo_oceano.txt");
            while (((line = file.ReadLine()) != null) && (indice < 30))
            {
                dados [indice] = line;
                indice++;
            }
            file.Close();
            pegaDados();
            // ##############################################################################################################################################
            try
            {
                WindDirVector = CalculateWindDirVector();

                Projection.TightFit = tightProjectionFit;

                UpdateOceanScheduler();

                OverlayManager.Update();

                specularRoughness = Mathf.Clamp01(specularRoughness);
                specularIntensity = Mathf.Max(0.0f, specularIntensity);
                minFresnel        = Mathf.Clamp01(minFresnel);
                fresnelPower      = Mathf.Max(0.0f, fresnelPower);
                foamIntensity     = Math.Max(0.0f, foamIntensity);

                float sr = Mathf.Lerp(2e-5f, 2e-2f, specularRoughness);

                Shader.SetGlobalColor("Ceto_DefaultSkyColor", defaultSkyColor);
                Shader.SetGlobalColor("Ceto_DefaultOceanColor", defaultOceanColor);
                Shader.SetGlobalFloat("Ceto_SpecularRoughness", sr);
                Shader.SetGlobalFloat("Ceto_FresnelPower", fresnelPower);
                Shader.SetGlobalFloat("Ceto_SpecularIntensity", specularIntensity);
                Shader.SetGlobalFloat("Ceto_MinFresnel", minFresnel);
                Shader.SetGlobalFloat("Ceto_OceanLevel", level);
                Shader.SetGlobalFloat("Ceto_MaxWaveHeight", MAX_SPECTRUM_WAVE_HEIGHT);
                Shader.SetGlobalColor("Ceto_FoamTint", foamTint * foamIntensity); //Brian here: THIS line might give me something(duplicate it for OilTint, change shader?...Like you know how to work a shader)
                Shader.SetGlobalColor("Ceto_OilTint", oilTint);                   //proto mod
                Shader.SetGlobalVector("Ceto_SunDir", SunDir());
                Shader.SetGlobalVector("Ceto_SunColor", SunColor());

                Vector4 foamParam0 = new Vector4();
                foamParam0.x = (foamTexture0.scale.x != 0.0f) ? 1.0f / foamTexture0.scale.x : 1.0f;
                foamParam0.y = (foamTexture0.scale.y != 0.0f) ? 1.0f / foamTexture0.scale.y : 1.0f;
                foamParam0.z = foamTexture0.scrollSpeed * OceanTime.Now;
                foamParam0.w = 0.0f;

                Vector4 foamParam1 = new Vector4();
                foamParam1.x = (foamTexture1.scale.x != 0.0f) ? 1.0f / foamTexture1.scale.x : 1.0f;
                foamParam1.y = (foamTexture1.scale.y != 0.0f) ? 1.0f / foamTexture1.scale.y : 1.0f;
                foamParam1.z = foamTexture1.scrollSpeed * OceanTime.Now;
                foamParam1.w = 0.0f;

                Shader.SetGlobalTexture("Ceto_FoamTexture0", ((foamTexture0.tex != null) ? foamTexture0.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale0", foamParam0);

                Shader.SetGlobalTexture("Ceto_FoamTexture1", ((foamTexture1.tex != null) ? foamTexture1.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale1", foamParam1);

                //Rest each data element so they are updated this frame.
                var e = m_cameraData.GetEnumerator();
                while (e.MoveNext())
                {
                    CameraData data = e.Current.Value;

                    if (data.mask != null)
                    {
                        data.mask.ClearUpdatedViews();
                    }
                    if (data.depth != null)
                    {
                        data.depth.ClearUpdatedViews();
                    }
                    if (data.overlay != null)
                    {
                        data.overlay.ClearUpdatedViews();
                    }
                    if (data.reflection != null)
                    {
                        data.reflection.ClearUpdatedViews();
                    }

                    if (data.projection != null)
                    {
                        data.projection.ClearUpdatedViews();
                        data.projection.checkedForFlipping = false;
                    }
                }
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
Esempio n. 15
0
 public override void RenderReflection(GameObject go)
 {
     try
     {
         if (base.enabled)
         {
             Camera current = Camera.current;
             if (!(current == null))
             {
                 CameraData cameraData = this.m_ocean.FindCameraData(current);
                 if (cameraData.reflection == null)
                 {
                     cameraData.reflection = new ReflectionData();
                 }
                 if (!cameraData.reflection.updated)
                 {
                     if (this.GetDisableReflections(cameraData.settings))
                     {
                         Shader.DisableKeyword("CETO_REFLECTION_ON");
                         cameraData.reflection.updated = true;
                     }
                     else
                     {
                         Shader.EnableKeyword("CETO_REFLECTION_ON");
                         if (cameraData.reflection.cam != null)
                         {
                             DisableFog component = cameraData.reflection.cam.GetComponent <DisableFog>();
                             if (component != null)
                             {
                                 component.enabled = !this.fogInReflection;
                             }
                         }
                         RenderTexture renderTexture;
                         if (this.RenderReflectionCustom != null)
                         {
                             if (cameraData.reflection.cam != null)
                             {
                                 RTUtility.ReleaseAndDestroy(cameraData.reflection.cam.targetTexture);
                                 cameraData.reflection.cam.targetTexture = null;
                                 UnityEngine.Object.Destroy(cameraData.reflection.cam.gameObject);
                                 UnityEngine.Object.Destroy(cameraData.reflection.cam);
                                 cameraData.reflection.cam = null;
                             }
                             this.CreateRenderTarget(cameraData.reflection, current.name, current.pixelWidth, current.pixelHeight, current.hdr, cameraData.settings);
                             if (this.m_dummy == null)
                             {
                                 this.m_dummy           = new GameObject("Ceto Reflection Dummy Gameobject");
                                 this.m_dummy.hideFlags = HideFlags.HideAndDontSave;
                             }
                             this.m_dummy.transform.position = new Vector3(0f, this.m_ocean.level, 0f);
                             renderTexture = this.RenderReflectionCustom(this.m_dummy);
                         }
                         else
                         {
                             this.CreateReflectionCameraFor(current, cameraData.reflection);
                             this.CreateRenderTarget(cameraData.reflection, current.name, current.pixelWidth, current.pixelHeight, current.hdr, cameraData.settings);
                             if (current.stereoEnabled)
                             {
                             }
                             NotifyOnEvent.Disable = true;
                             this.RenderReflectionFor(current, cameraData.reflection.cam, cameraData.settings);
                             NotifyOnEvent.Disable = false;
                             renderTexture         = cameraData.reflection.cam.targetTexture;
                         }
                         if (renderTexture != null)
                         {
                             if (this.blitmaterial == null)
                             {
                                 this.blitmaterial = new Material(Shader.Find("Hidden/TheForestBlitCopyFullscreen"));
                             }
                             Graphics.Blit(renderTexture, cameraData.reflection.tex, this.blitmaterial);
                             this.m_imageBlur.BlurIterations = this.blurIterations;
                             this.m_imageBlur.BlurMode       = this.blurMode;
                             this.m_imageBlur.BlurSpread     = this.blurSpread;
                             this.m_imageBlur.Blur(cameraData.reflection.tex);
                             Shader.SetGlobalTexture(Ocean.REFLECTION_TEXTURE_NAME, cameraData.reflection.tex);
                         }
                         cameraData.reflection.updated = true;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Ocean.LogError(ex.ToString());
         base.WasError = true;
         base.enabled  = false;
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Update the projection data for this camera.
        /// If this is the scene view camera you may not want to project 
        /// the grid from its point of view but instead from the main 
        /// cameras view so you can see how the mesh is being projected.
        /// </summary>
        public void UpdateProjection(Camera cam, CameraData data, bool projectSceneView)
        {
            if(cam == null || data == null) return;

            if(data.projection == null)
                data.projection = new ProjectionData();

            if(data.projection.updated) return;

            if(!projectSceneView && cam.name == "SceneCamera" && Camera.main != null)
                cam = Camera.main;

            //Aim the projector given the current camera position.
            //Find the most practical but visually pleasing projection.
            //Sets the m_projectorV and m_projectorP matrices.
            AimProjector(cam);

            //Create a view projection matrix.
            MulMatrixByMatrix(m_projectorVP, m_projectorP, m_projectorV);

            //Create the m_projectorR matrix.
            //Finds the range the projection must fit
            //for the projected grid to cover the screen.
            CreateRangeMatrix(cam, m_projectorVP);

            //Create the inverse view projection range matrix.
            Inverse(MATRIX_BUFFER0, m_projectorVP);
            MulMatrixByMatrix(m_projectorIVP, MATRIX_BUFFER0, m_projectorR);

            //Set the interpolation points based on IVP matrix.
            HProject(m_projectorIVP, m_quad[0], VECTOR_BUFFER);
            SetRow(0, m_projectorI, VECTOR_BUFFER);

            HProject(m_projectorIVP, m_quad[1], VECTOR_BUFFER);
            SetRow(1, m_projectorI, VECTOR_BUFFER);

            HProject(m_projectorIVP, m_quad[2], VECTOR_BUFFER);
            SetRow(2, m_projectorI, VECTOR_BUFFER);

            HProject(m_projectorIVP, m_quad[3], VECTOR_BUFFER);
            SetRow(3, m_projectorI, VECTOR_BUFFER);

            //Save a copy of the view projection range matrix and the interpolation matrix.
            Inverse(MATRIX_BUFFER0, m_projectorR);
            MulMatrixByMatrix(MATRIX_BUFFER1, MATRIX_BUFFER0, m_projectorVP);

            CopyMatrix(ref data.projection.projectorVP, MATRIX_BUFFER1);
            CopyMatrix(ref data.projection.interpolation, m_projectorI);

            data.projection.updated = true;
        }
Esempio n. 17
0
        /// <summary>
        /// Update the projection data for this camera.
        /// If this is the scene view camera you may not want to project 
        /// the grid from its point of view but instead from the main 
        /// cameras view so you can see how the mesh is being projected.
        /// </summary>
        public void UpdateProjection(Camera cam, CameraData data, bool projectSceneView)
        {
            if(cam == null || data == null) return;

            if(data.projection == null)
                data.projection = new ProjectionData();

            if(data.projection.updated) return;

            if(!projectSceneView && cam.name == "SceneCamera" && Camera.main != null)
                cam = Camera.main;

            //Aim the projector given the current camera position.
            //Find the most practical but visually pleasing projection.
            //Sets the m_projectorV and m_projectorP matrices.
            AimProjector(cam);

            //Create a view projection matrix.
            Matrix4x4 projectorVP = m_projectorP * m_projectorV;

            //Create the m_projectorR matrix.
            //Finds the range the projection must fit
            //for the projected grid to cover the screen.
            CreateRangeMatrix(cam, projectorVP);
            //Create the inverse view projection range matrix.
            Matrix4x4 IVP = (projectorVP).inverse * m_projectorR;

            //Set the interpolation points based on IVP matrix.
            m_projectorI.SetRow(0, HProject(IVP, m_quad[0]));
            m_projectorI.SetRow(1, HProject(IVP, m_quad[1]));
            m_projectorI.SetRow(2, HProject(IVP, m_quad[2]));
            m_projectorI.SetRow(3, HProject(IVP, m_quad[3]));

            //Save a copy of the view projection range matrix and the interpolation matrix.
            data.projection.projectorVP = m_projectorR.inverse * projectorVP;
            data.projection.interpolation = m_projectorI;

            data.projection.updated = true;
        }
Esempio n. 18
0
 public override void RenderOceanDepth(GameObject go)
 {
     try
     {
         if (base.enabled)
         {
             Camera current = Camera.current;
             if (!(current == null))
             {
                 CameraData cameraData = this.m_ocean.FindCameraData(current);
                 if (cameraData.depth == null)
                 {
                     cameraData.depth = new DepthData();
                 }
                 if (!cameraData.depth.updated)
                 {
                     if (this.GetDisableUnderwater(cameraData.settings))
                     {
                         Shader.DisableKeyword("CETO_UNDERWATER_ON");
                         cameraData.depth.updated = true;
                     }
                     else
                     {
                         Shader.EnableKeyword("CETO_UNDERWATER_ON");
                         if (SystemInfo.graphicsShaderLevel < 30)
                         {
                             Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME, Texture2D.whiteTexture);
                             Shader.SetGlobalTexture(Ocean.DEPTH_GRAB_TEXTURE_NAME, Texture2D.whiteTexture);
                             Shader.SetGlobalTexture(Ocean.NORMAL_FADE_TEXTURE_NAME, Texture2D.blackTexture);
                             Shader.SetGlobalMatrix("Ceto_Camera_IVP", (current.projectionMatrix * current.worldToCameraMatrix).inverse);
                             cameraData.depth.updated = true;
                         }
                         else if (this.depthMode == DEPTH_MODE.USE_DEPTH_BUFFER)
                         {
                             Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME, Texture2D.whiteTexture);
                             current.depthTextureMode |= DepthTextureMode.Depth;
                             current.depthTextureMode |= DepthTextureMode.DepthNormals;
                             Shader.SetGlobalMatrix("Ceto_Camera_IVP", (current.projectionMatrix * current.worldToCameraMatrix).inverse);
                             this.CreateRefractionCommand(current, cameraData.depth);
                             cameraData.depth.updated = true;
                         }
                         else if (this.depthMode == DEPTH_MODE.USE_OCEAN_DEPTH_PASS)
                         {
                             Shader.SetGlobalTexture(Ocean.DEPTH_GRAB_TEXTURE_NAME, Texture2D.whiteTexture);
                             Shader.SetGlobalTexture(Ocean.NORMAL_FADE_TEXTURE_NAME, Texture2D.blackTexture);
                             this.CreateDepthCameraFor(current, cameraData.depth);
                             this.CreateRefractionCommand(current, cameraData.depth);
                             cameraData.depth.cam.cullingMask = this.GetOceanDepthsLayermask(cameraData.settings);
                             cameraData.depth.cam.cullingMask = OceanUtility.HideLayer(cameraData.depth.cam.cullingMask, Ocean.OCEAN_LAYER);
                             NotifyOnEvent.Disable            = true;
                             cameraData.depth.cam.RenderWithShader(this.oceanDepthSdr, "RenderType");
                             NotifyOnEvent.Disable = false;
                             Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME, cameraData.depth.cam.targetTexture);
                             cameraData.depth.updated = true;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Ocean.LogError(ex.ToString());
         base.WasError = true;
         base.enabled  = false;
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Render the reflections for this objects position
        /// and the current camera.
        /// </summary>
        public override void RenderReflection(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                Camera cam = Camera.current;
                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                //Create the data needed if not already created.
                if (data.reflection == null)
                {
                    data.reflection = new ReflectionData();
                }

                if (data.reflection.updated)
                {
                    return;
                }

                //If this camera has disable the reflection turn it off in the shader and return.
                if (GetDisableReflections(data.settings))
                {
                    Shader.DisableKeyword("CETO_REFLECTION_ON");
                    data.reflection.updated = true;
                    return;
                }
                else
                {
                    Shader.EnableKeyword("CETO_REFLECTION_ON");
                }

                RenderTexture reflections = null;

                if (data.reflection.cam != null)
                {
                    DisableFog disableFog = data.reflection.cam.GetComponent <DisableFog>();
                    if (disableFog != null)
                    {
                        disableFog.enabled = !fogInReflection;
                    }
                }

                if (RenderReflectionCustom != null)
                {
                    //If using a custom method

                    //Destroy the camera if already created as its no longer needed.
                    if (data.reflection.cam != null)
                    {
                        RTUtility.ReleaseAndDestroy(data.reflection.cam.targetTexture);
                        data.reflection.cam.targetTexture = null;

                        Destroy(data.reflection.cam.gameObject);
                        Destroy(data.reflection.cam);
                        data.reflection.cam = null;
                    }

                    CreateRenderTarget(data.reflection, cam.name, cam.pixelWidth, cam.pixelHeight, cam.allowHDR, data.settings);

                    //Create the dummy object if null
                    if (m_dummy == null)
                    {
                        m_dummy           = new GameObject("Ceto Reflection Dummy Gameobject");
                        m_dummy.hideFlags = HideFlags.HideAndDontSave;
                    }

                    //Set the position of the reflection plane.
                    m_dummy.transform.position = new Vector3(0.0f, m_ocean.level, 0.0f);
                    reflections = RenderReflectionCustom(m_dummy);
                }
                else
                {
                    //Else use normal method.

                    CreateReflectionCameraFor(cam, data.reflection);
                    CreateRenderTarget(data.reflection, cam.name, cam.pixelWidth, cam.pixelHeight, cam.allowHDR, data.settings);

                    NotifyOnEvent.Disable = true;
                    RenderReflectionFor(cam, data.reflection.cam, data.settings);
                    NotifyOnEvent.Disable = false;

                    reflections = data.reflection.cam.targetTexture;
                }

                //The reflections texture should now contain the rendered
                //reflections for the current cameras view.
                if (reflections != null)
                {
                    //Blit into another texture to take a copy.
                    Graphics.Blit(reflections, data.reflection.tex);

                    m_imageBlur.BlurIterations = blurIterations;
                    m_imageBlur.BlurMode       = blurMode;
                    m_imageBlur.BlurSpread     = blurSpread;
                    m_imageBlur.Blur(data.reflection.tex);

                    Shader.SetGlobalTexture(Ocean.REFLECTION_TEXTURE_NAME, data.reflection.tex);
                }

                data.reflection.updated = true;
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }
Esempio n. 20
0
 public virtual void OceanOnPostRender(Camera cam, CameraData data)
 {
 }
Esempio n. 21
0
        /// <summary>
        /// Renders the ocean mask. The mask is used in the underwater post effect
        /// shader and contains a 1 or 0 in the rgb channels if the pixel is on the
        /// top of the ocean mesh, on the under side of mesh or below the ocean mesh.
        /// The w channel also contains the meshes depth value as if the normal ocean
        /// material does not write to depth buffer the shader wont be able to get its
        /// depth value.
        /// </summary>
        public void RenderOceanMask(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                if (oceanMaskSdr == null)
                {
                    return;
                }

                if (underwaterMode == UNDERWATER_MODE.ABOVE_ONLY)
                {
                    return;
                }

                Camera cam = Camera.current;
                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                if (data.mask == null)
                {
                    data.mask = new MaskData();
                }

                if (data.mask.IsViewUpdated(cam))
                {
                    return;
                }

                if (cam.name == "SceneCamera" || cam.GetComponent <UnderWaterPostEffect>() == null || SystemInfo.graphicsShaderLevel < 30 || GetDisableUnderwater(data.settings))
                {
                    //Scene camera should never need the mask so just bind something that wont cause a issue.
                    //If the camera is not using a post effect there is no need for the mask to be rendered.

                    Shader.SetGlobalTexture(Ocean.OCEAN_MASK_TEXTURE_NAME0, Texture2D.blackTexture);
                    Shader.SetGlobalTexture(Ocean.OCEAN_MASK_TEXTURE_NAME1, Texture2D.blackTexture);
                    data.mask.SetViewAsUpdated(cam);
                }
                else
                {
                    CreateMaskCameraFor(cam, data.mask);

                    FitBottomToCamera();

                    Shader sdr = (m_ocean.Projection.IsFlipped) ? oceanMaskFlippedSdr : oceanMaskSdr;

                    if (cam.stereoEnabled)
                    {
                        RenderSteroOceanMask(data.mask, cam, sdr);
                    }
                    else
                    {
                        Shader.DisableKeyword("CETO_STERO_CAMERA");
                        RenderOceanMask(data.mask, data.mask.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix, sdr);
                        Shader.SetGlobalTexture(Ocean.OCEAN_MASK_TEXTURE_NAME0, data.mask.target0);
                    }

                    data.mask.SetViewAsUpdated(cam);
                }
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }
Esempio n. 22
0
        void Update()
        {
            try
            {
                WindDirVector = CalculateWindDirVector();

                Projection.TightFit = tightProjectionFit;

                UpdateOceanScheduler();

                OverlayManager.Update();

                specularRoughness = Mathf.Clamp01(specularRoughness);
                specularIntensity = Mathf.Max(0.0f, specularIntensity);
                minFresnel        = Mathf.Clamp01(minFresnel);
                fresnelPower      = Mathf.Max(0.0f, fresnelPower);
                foamIntensity     = Math.Max(0.0f, foamIntensity);

                float sr = Mathf.Lerp(2e-5f, 2e-2f, specularRoughness);

                Shader.SetGlobalColor("Ceto_DefaultSkyColor", defaultSkyColor);
                Shader.SetGlobalColor("Ceto_DefaultOceanColor", defaultOceanColor);
                Shader.SetGlobalFloat("Ceto_SpecularRoughness", sr);
                Shader.SetGlobalFloat("Ceto_FresnelPower", fresnelPower);
                Shader.SetGlobalFloat("Ceto_SpecularIntensity", specularIntensity);
                Shader.SetGlobalFloat("Ceto_MinFresnel", minFresnel);
                Shader.SetGlobalFloat("Ceto_OceanLevel", level);
                Shader.SetGlobalFloat("Ceto_MaxWaveHeight", MAX_SPECTRUM_WAVE_HEIGHT);
                Shader.SetGlobalColor("Ceto_FoamTint", foamTint * foamIntensity);
                Shader.SetGlobalVector("Ceto_SunDir", SunDir());
                Shader.SetGlobalVector("Ceto_SunColor", SunColor());

                Vector4 foamParam0 = new Vector4();
                foamParam0.x = (foamTexture0.scale.x != 0.0f) ? 1.0f / foamTexture0.scale.x : 1.0f;
                foamParam0.y = (foamTexture0.scale.y != 0.0f) ? 1.0f / foamTexture0.scale.y : 1.0f;
                foamParam0.z = foamTexture0.scrollSpeed * OceanTime.Now;
                foamParam0.w = 0.0f;

                Vector4 foamParam1 = new Vector4();
                foamParam1.x = (foamTexture1.scale.x != 0.0f) ? 1.0f / foamTexture1.scale.x : 1.0f;
                foamParam1.y = (foamTexture1.scale.y != 0.0f) ? 1.0f / foamTexture1.scale.y : 1.0f;
                foamParam1.z = foamTexture1.scrollSpeed * OceanTime.Now;
                foamParam1.w = 0.0f;

                Shader.SetGlobalTexture("Ceto_FoamTexture0", ((foamTexture0.tex != null) ? foamTexture0.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale0", foamParam0);

                Shader.SetGlobalTexture("Ceto_FoamTexture1", ((foamTexture1.tex != null) ? foamTexture1.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale1", foamParam1);

                //Rest each data element so they are updated this frame.
                var e = m_cameraData.GetEnumerator();
                while (e.MoveNext())
                {
                    CameraData data = e.Current.Value;

                    if (data.mask != null)
                    {
                        data.mask.ClearUpdatedViews();
                    }
                    if (data.depth != null)
                    {
                        data.depth.ClearUpdatedViews();
                    }
                    if (data.overlay != null)
                    {
                        data.overlay.ClearUpdatedViews();
                    }
                    if (data.reflection != null)
                    {
                        data.reflection.ClearUpdatedViews();
                    }

                    if (data.projection != null)
                    {
                        data.projection.ClearUpdatedViews();
                        data.projection.checkedForFlipping = false;
                    }
                }
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Render depth information about a object using a replacement shader.
        /// If the ocean renders into the depth buffer then the shader can not get
        /// depth info about what has been rendered under it as Unity will have already
        /// written the ocean mesh into depth buffer by then.
        /// Will also create the refraction grab if needed.
        /// </summary>
        public void RenderOceanDepth(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                Camera cam = Camera.current;
                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                if (data.depth == null)
                {
                    data.depth = new DepthData();
                }

                if (data.depth.IsViewUpdated(cam))
                {
                    return;
                }

                //If this camera has disable the underwater turn it off in the shader and return.
                if (GetDisableUnderwater(data.settings))
                {
                    Shader.DisableKeyword("CETO_UNDERWATER_ON");
                    data.depth.SetViewAsUpdated(cam);
                    return;
                }
                else
                {
                    Shader.EnableKeyword("CETO_UNDERWATER_ON");
                }

                if (/*cam.name == "SceneCamera" ||*/ SystemInfo.graphicsShaderLevel < 30)
                {
                    //These texture will not be generated so zero to some that will not cause a issue if sampled.
                    Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME0, Texture2D.whiteTexture);
                    Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME1, Texture2D.whiteTexture);
                    Shader.SetGlobalTexture(Ocean.DEPTH_GRAB_TEXTURE_NAME, Texture2D.whiteTexture);
                    Shader.SetGlobalTexture(Ocean.NORMAL_FADE_TEXTURE_NAME, Texture2D.blackTexture);

                    //If not using the ocean depths all thats needed is the IVP
                    //to extract the world pos from the depth buffer.
                    BindIVPMatrix(cam.projectionMatrix, cam.worldToCameraMatrix);

                    data.depth.SetViewAsUpdated(cam);
                }
                else if (depthMode == DEPTH_MODE.USE_DEPTH_BUFFER)
                {
                    //These texture will not be generated so zero to some that will not cause a issue if sampled.
                    Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME0, Texture2D.whiteTexture);
                    Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME1, Texture2D.whiteTexture);

                    //Cam must have depth mode enabled to use depth buffer.
                    cam.depthTextureMode |= DepthTextureMode.Depth;
                    cam.depthTextureMode |= DepthTextureMode.DepthNormals;

                    CreateRefractionCommand(cam, data.depth);

                    //If not using the ocean depths all thats needed is the IVP
                    //to extract the world pos from the depth buffer.
                    BindIVPMatrix(cam.projectionMatrix, cam.worldToCameraMatrix);

                    data.depth.SetViewAsUpdated(cam);
                }
                else if (depthMode == DEPTH_MODE.USE_OCEAN_DEPTH_PASS)
                {
                    //These texture will not be generated so zero to some that will not cause a issue if sampled.
                    Shader.SetGlobalTexture(Ocean.DEPTH_GRAB_TEXTURE_NAME, Texture2D.whiteTexture);
                    Shader.SetGlobalTexture(Ocean.NORMAL_FADE_TEXTURE_NAME, Texture2D.blackTexture);

                    CreateDepthCameraFor(cam, data.depth);
                    CreateRefractionCommand(cam, data.depth);

                    data.depth.cam.cullingMask = GetOceanDepthsLayermask(data.settings);
                    data.depth.cam.cullingMask = OceanUtility.HideLayer(data.depth.cam.cullingMask, Ocean.OCEAN_LAYER);

                    if (cam.stereoEnabled)
                    {
                        RenderSteroOceanDepth(data.depth, cam);
                    }
                    else
                    {
                        Shader.DisableKeyword("CETO_STERO_CAMERA");
                        RenderOceanDepth(data.depth, data.depth.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix);
                        Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME0, data.depth.target0);
                    }

                    data.depth.SetViewAsUpdated(cam);
                }
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Called before camera renders the ocean.
 /// </summary>
 public virtual void OceanOnPreRender(Camera cam, CameraData data)
 {
 }
Esempio n. 25
0
        /// <summary>
        /// Renders the ocean mask. The mask is used in the underwater post effect
        /// shader and contains a 1 or 0 in the rgb channels if the pixel is on the
        /// top of the ocean mesh, on the under side of mesh or below the ocean mesh.
        /// The w channel also contains the meshes depth value as if the normal ocean
        /// material does not write to depth buffer the shader wont be able to get its
        /// depth value.
        /// </summary>
        public override void RenderOceanMask(GameObject go)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }

                if (oceanMaskSdr == null)
                {
                    return;
                }

                if (underwaterMode == UNDERWATER_MODE.ABOVE_ONLY)
                {
                    return;
                }

                Camera cam = Camera.current;
                if (cam == null)
                {
                    return;
                }

                CameraData data = m_ocean.FindCameraData(cam);

                if (data.mask == null)
                {
                    data.mask = new MaskData();
                }

                if (data.mask.updated)
                {
                    return;
                }

                if (cam.name == "SceneCamera" || cam.GetComponent <UnderWaterPostEffect>() == null || SystemInfo.graphicsShaderLevel < 30 || GetDisableUnderwater(data.settings))
                {
                    //Scene camera should never need the mask so just bind something that wont cause a issue.
                    //If the camera is not using a post effect there is no need for the mask to be rendered.

                    Shader.SetGlobalTexture("Ceto_OceanMask", Texture2D.blackTexture);
                    data.mask.updated = true;
                }
                else
                {
                    CreateMaskCameraFor(cam, data.mask);

                    FitBottomToCamera();

                    NotifyOnEvent.Disable = true;
                    data.mask.cam.RenderWithShader(oceanMaskSdr, "OceanMask");
                    NotifyOnEvent.Disable = false;

                    Shader.SetGlobalTexture("Ceto_OceanMask", data.mask.cam.targetTexture);

                    data.mask.updated = true;
                }
            }
            catch (Exception e)
            {
                Ocean.LogError(e.ToString());
                WasError = true;
                enabled  = false;
            }
        }