/// <summary> /// /// </summary> public void ClearBuffers(WaveOverlayData data) { RTUtility.ClearColor(data.height, m_clearColor); RTUtility.ClearColor(data.normal, m_clearColor); RTUtility.ClearColor(data.foam, m_clearColor); RTUtility.ClearColor(data.clip, m_clearColor); }
/// <summary> /// Create the overlay buffers for this camera at the required size. /// </summary> public void CreateOverlays(Camera cam, WaveOverlayData overlay, OVERLAY_MAP_SIZE normalOverlaySize, OVERLAY_MAP_SIZE heightOverlaySize, OVERLAY_MAP_SIZE foamOverlaySize, OVERLAY_MAP_SIZE clipOverlaySize) { //If the manager has a overlay of this type then create the map it renders into if (HasNormalOverlay) { RenderTextureFormat format = RenderTextureFormat.ARGBHalf; //The mask will work but adding normals will not with this format. TODO - fix this if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGB32; } CreateBuffer("Normal", cam, normalOverlaySize, format, true, ref overlay.normal); } if (HasHeightOverlay) { RenderTextureFormat format = RenderTextureFormat.RGHalf; if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGBHalf; } if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGB32; } CreateBuffer("Height", cam, heightOverlaySize, format, true, ref overlay.height); } if (HasFoamOverlay) { RenderTextureFormat format = RenderTextureFormat.ARGB32; CreateBuffer("Foam", cam, foamOverlaySize, format, false, ref overlay.foam); } if (HasClipOverlay) { RenderTextureFormat format = RenderTextureFormat.R8; if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.RHalf; } if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGB32; } CreateBuffer("Clip", cam, clipOverlaySize, format, true, ref overlay.clip); } }
public void DestroyBuffers(WaveOverlayData data) { RTUtility.ReleaseAndDestroy(data.normal); RTUtility.ReleaseAndDestroy(data.height); RTUtility.ReleaseAndDestroy(data.foam); RTUtility.ReleaseAndDestroy(data.clip); data.normal = null; data.height = null; data.foam = null; data.clip = null; }
public void CreateOverlays(Camera cam, WaveOverlayData overlay, OVERLAY_MAP_SIZE normalOverlaySize, OVERLAY_MAP_SIZE heightOverlaySize, OVERLAY_MAP_SIZE foamOverlaySize, OVERLAY_MAP_SIZE clipOverlaySize) { if (this.HasNormalOverlay) { RenderTextureFormat format = RenderTextureFormat.ARGBHalf; if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGB32; } this.CreateBuffer("Normal", cam, normalOverlaySize, format, true, ref overlay.normal); } if (this.HasHeightOverlay) { RenderTextureFormat format2 = RenderTextureFormat.RGHalf; if (!SystemInfo.SupportsRenderTextureFormat(format2)) { format2 = RenderTextureFormat.ARGBHalf; } if (!SystemInfo.SupportsRenderTextureFormat(format2)) { format2 = RenderTextureFormat.ARGB32; } this.CreateBuffer("Height", cam, heightOverlaySize, format2, true, ref overlay.height); } if (this.HasFoamOverlay) { RenderTextureFormat format3 = RenderTextureFormat.ARGB32; this.CreateBuffer("Foam", cam, foamOverlaySize, format3, false, ref overlay.foam); } if (this.HasClipOverlay) { RenderTextureFormat format4 = RenderTextureFormat.R8; if (!SystemInfo.SupportsRenderTextureFormat(format4)) { format4 = RenderTextureFormat.RHalf; } if (!SystemInfo.SupportsRenderTextureFormat(format4)) { format4 = RenderTextureFormat.ARGB32; } this.CreateBuffer("Clip", cam, clipOverlaySize, format4, true, ref overlay.clip); } }
/// <summary> /// Renders the wave overlays for this camera. /// </summary> public void RenderWaveOverlays(Camera cam, WaveOverlayData data) { if (!m_beenCleared) { ClearBuffers(data); m_beenCleared = true; } if (m_waveOverlays.Count == 0) { return; } // Plane[] planes = GeometryUtility.CalculateFrustumPlanes(cam); GetFrustumPlanes(cam.projectionMatrix * cam.worldToCameraMatrix); m_heightOverlays.Clear(); m_normalOverlays.Clear(); m_foamOverlays.Clear(); m_clipOverlays.Clear(); var e = m_waveOverlays.GetEnumerator(); while (e.MoveNext()) { WaveOverlay overlay = e.Current; if (!overlay.Hide && GeometryUtility.TestPlanesAABB(m_planes, overlay.BoundingBox)) { if (overlay.HeightTex.IsDrawable) { m_heightOverlays.Add(overlay); } if (overlay.NormalTex.IsDrawable) { m_normalOverlays.Add(overlay); } if (overlay.FoamTex.IsDrawable) { m_foamOverlays.Add(overlay); } if (overlay.ClipTex.IsDrawable) { m_clipOverlays.Add(overlay); } } } RenderHeightOverlays(data.height); RenderNormalOverlays(data.normal); RenderFoamOverlays(data.foam); RenderClipOverlays(data.clip); //If buffer has been created apply it to shaders if (data.normal != null) { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", data.normal); } else { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture); } if (data.height != null) { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", data.height); } else { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture); } if (data.foam != null) { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", data.foam); } else { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture); } if (data.clip != null) { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", data.clip); } else { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture); } m_beenCleared = false; }
/// <summary> /// Renders the wave overlays for this camera. /// </summary> public void RenderWaveOverlays(Camera cam, WaveOverlayData data) { if(!m_beenCleared) { ClearBuffers(data); m_beenCleared = true; } if(m_waveOverlays.Count == 0) return; Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.current); m_heightOverlays.Clear(); m_normalOverlays.Clear(); m_foamOverlays.Clear(); m_clipOverlays.Clear(); var e = m_waveOverlays.GetEnumerator(); while(e.MoveNext()) { WaveOverlay overlay = e.Current; if (!overlay.Hide && GeometryUtility.TestPlanesAABB(planes, overlay.BoundingBox)) { if(overlay.HeightTex.IsDrawable) { m_heightOverlays.Add(overlay); } if(overlay.NormalTex.IsDrawable) { m_normalOverlays.Add(overlay); } if(overlay.FoamTex.IsDrawable) { m_foamOverlays.Add(overlay); } if(overlay.ClipTex.IsDrawable) { m_clipOverlays.Add(overlay); } } } RenderHeightOverlays(m_heightOverlays, data.height); RenderNormalOverlays(m_normalOverlays, data.normal); RenderFoamOverlays(m_foamOverlays, data.foam); RenderClipOverlays(m_clipOverlays, data.clip); //If buffer has been created apply it to shaders if (data.normal != null) Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", data.normal); else Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture); if (data.height != null) Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", data.height); else Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture); if (data.foam != null) Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", data.foam); else Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture); if (data.clip != null) Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", data.clip); else Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture); m_beenCleared = false; }
/// <summary> /// /// </summary> public void DestroyBuffers(WaveOverlayData data) { RTUtility.ReleaseAndDestroy(data.normal); RTUtility.ReleaseAndDestroy(data.height); RTUtility.ReleaseAndDestroy(data.foam); RTUtility.ReleaseAndDestroy(data.clip); data.normal = null; data.height = null; data.foam = null; data.clip = null; }
/// <summary> /// Create the overlay buffers for this camera at the required size. /// </summary> public void CreateOverlays(Camera cam, WaveOverlayData overlay, OVERLAY_MAP_SIZE normalOverlaySize, OVERLAY_MAP_SIZE heightOverlaySize, OVERLAY_MAP_SIZE foamOverlaySize, OVERLAY_MAP_SIZE clipOverlaySize) { //If the manager has a overlay of this type then create the map it renders into if (HasNormalOverlay) { RenderTextureFormat format = RenderTextureFormat.ARGBHalf; if (!SystemInfo.SupportsRenderTextureFormat(format)) format = RenderTextureFormat.ARGB32; //The mask will work but adding normals will not with this format. CreateBuffer("Normal", cam, normalOverlaySize, format, true, ref overlay.normal); } if (HasHeightOverlay) { RenderTextureFormat format = RenderTextureFormat.RGHalf; if (!SystemInfo.SupportsRenderTextureFormat(format)) format = RenderTextureFormat.ARGB32; CreateBuffer("Height", cam, heightOverlaySize, format, true, ref overlay.height); } if (HasFoamOverlay) { RenderTextureFormat format = RenderTextureFormat.ARGB32; CreateBuffer("Foam", cam, foamOverlaySize, format, false, ref overlay.foam); } if (HasClipOverlay) { RenderTextureFormat format = RenderTextureFormat.R8; if (!SystemInfo.SupportsRenderTextureFormat(format)) format = RenderTextureFormat.RHalf; if (!SystemInfo.SupportsRenderTextureFormat(format)) format = RenderTextureFormat.ARGB32; CreateBuffer("Clip", cam, clipOverlaySize, format, true, ref overlay.clip); } }
public void RenderWaveOverlays(Camera cam, WaveOverlayData data) { if (!this.m_beenCleared) { this.ClearBuffers(data); this.m_beenCleared = true; } if (this.m_waveOverlays.Count == 0) { return; } this.GetFrustumPlanes(cam.projectionMatrix * cam.worldToCameraMatrix); this.m_heightOverlays.Clear(); this.m_normalOverlays.Clear(); this.m_foamOverlays.Clear(); this.m_clipOverlays.Clear(); foreach (WaveOverlay waveOverlay in this.m_waveOverlays) { if (!waveOverlay.Hide && GeometryUtility.TestPlanesAABB(this.m_planes, waveOverlay.BoundingBox)) { if (waveOverlay.HeightTex.IsDrawable) { this.m_heightOverlays.Add(waveOverlay); } if (waveOverlay.NormalTex.IsDrawable) { this.m_normalOverlays.Add(waveOverlay); } if (waveOverlay.FoamTex.IsDrawable) { this.m_foamOverlays.Add(waveOverlay); } if (waveOverlay.ClipTex.IsDrawable) { this.m_clipOverlays.Add(waveOverlay); } } } this.RenderHeightOverlays(data.height); this.RenderNormalOverlays(data.normal); this.RenderFoamOverlays(data.foam); this.RenderClipOverlays(data.clip); if (data.normal != null) { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", data.normal); } else { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture); } if (data.height != null) { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", data.height); } else { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture); } if (data.foam != null) { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", data.foam); } else { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture); } if (data.clip != null) { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", data.clip); } else { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture); } this.m_beenCleared = false; }
/// <summary> /// Renders the wave overlays for this camera. /// </summary> public void RenderWaveOverlays(Camera cam, WaveOverlayData data) { if (!m_beenCleared) { ClearBuffers(data); m_beenCleared = true; } if (m_waveOverlays.Count == 0) { return; } //Copy camera planes into m_planes array. GetFrustumPlanes(cam.projectionMatrix * cam.worldToCameraMatrix); m_heightOverlays.Clear(); m_normalOverlays.Clear(); m_foamOverlays.Clear(); m_clipOverlays.Clear(); //rest the bounds check for the overlay parent if set. var e = m_waveOverlays.GetEnumerator(); while (e.MoveNext()) { if (e.Current.ParentBounds != null) { e.Current.ParentBounds.BoundsChecked = false; } } e = m_waveOverlays.GetEnumerator(); while (e.MoveNext()) { WaveOverlay overlay = e.Current; //If camera farther than draw distance dont draw overlay. float distance = (overlay.Position - cam.transform.position).magnitude; if (distance > overlay.DrawDistance) { continue; } //If overlay has a parent check if its bounds is visible. bool parentVisible = true; if (overlay.ParentBounds != null) { parentVisible = false; if (overlay.ParentBounds.BoundsChecked) { parentVisible = overlay.ParentBounds.BoundsVisible; } else { parentVisible = GeometryUtility.TestPlanesAABB(m_planes, overlay.ParentBounds.BoundingBox); overlay.ParentBounds.BoundsVisible = parentVisible; overlay.ParentBounds.BoundsChecked = true; } } //Parent not visible so continue. if (!parentVisible) { continue; } //Parent is visible so update overlay bounds. //Use a stamp so bounds will not be updated again if second camera renders it. if (overlay.BoundsUpdateStamp != Time.frameCount) { overlay.CalculateBounds(); overlay.BoundsUpdateStamp = Time.frameCount; } //Create a alpha based on the draw distance. //Used to fade in the overlay as the camera enters the draw distance. //Only used for the foam atm. float distanceAlpha = 0.0f; if (overlay.DrawDistance != 0.0f && !float.IsInfinity(overlay.DrawDistance)) { distanceAlpha = distance / overlay.DrawDistance; } overlay.DistanceAlpha = 1.0f - distanceAlpha * distanceAlpha * distanceAlpha; if (!overlay.Hide && GeometryUtility.TestPlanesAABB(m_planes, overlay.BoundingBox)) { if (overlay.HeightTex.IsDrawable) { m_heightOverlays.Add(overlay); } if (overlay.NormalTex.IsDrawable) { m_normalOverlays.Add(overlay); } if (overlay.FoamTex.IsDrawable) { m_foamOverlays.Add(overlay); } if (overlay.ClipTex.IsDrawable) { m_clipOverlays.Add(overlay); } } } //OYM: 这一部分是处理renderer,计算坐标 RenderHeightOverlays(data.height); RenderNormalOverlays(data.normal); RenderFoamOverlays(data.foam); RenderClipOverlays(data.clip); //If buffer has been created apply it to shaders //OYM: 这里是渲染到海面上 if (data.normal != null) { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", data.normal); } else { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture); } if (data.height != null) { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", data.height); } else { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture); } if (data.foam != null) { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", data.foam); //CetoTest.AddPicture(data.foam); } else { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture); } if (data.clip != null) { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", data.clip); //CetoTest.AddPicture(data.clip); } else { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture); } m_beenCleared = false; }
public void RenderWaveOverlays(Camera cam, WaveOverlayData data) { if (!this.m_beenCleared) { this.ClearBuffers(data); this.m_beenCleared = true; } if (this.m_waveOverlays.Count == 0) { return; } this.GetFrustumPlanes(cam.projectionMatrix * cam.worldToCameraMatrix); this.m_heightOverlays.Clear(); this.m_normalOverlays.Clear(); this.m_foamOverlays.Clear(); this.m_clipOverlays.Clear(); LinkedList <WaveOverlay> .Enumerator enumerator = this.m_waveOverlays.GetEnumerator(); while (enumerator.MoveNext()) { WaveOverlay current = enumerator.Current; if (!current.Hide && GeometryUtility.TestPlanesAABB(this.m_planes, current.BoundingBox)) { if (current.HeightTex.IsDrawable) { this.m_heightOverlays.Add(current); } if (current.NormalTex.IsDrawable) { this.m_normalOverlays.Add(current); } if (current.FoamTex.IsDrawable) { this.m_foamOverlays.Add(current); } if (current.ClipTex.IsDrawable) { this.m_clipOverlays.Add(current); } } } this.RenderHeightOverlays(data.height); this.RenderNormalOverlays(data.normal); this.RenderFoamOverlays(data.foam); this.RenderClipOverlays(data.clip); if (data.normal != null) { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", data.normal); } else { Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture); } if (data.height != null) { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", data.height); } else { Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture); } if (data.foam != null) { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", data.foam); } else { Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture); } if (data.clip != null) { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", data.clip); } else { Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture); } this.m_beenCleared = false; }