/// <summary> /// For textures that require their contents to be /// sampled check to see if read/write is enabled. /// </summary> protected void CheckCanSampleTex(Texture tex, string name) { if (tex == null) { return; } if (!(tex is Texture2D))//OYM: 新技巧get { Ocean.LogWarning("Can not query overlays " + name + " if texture is not Texture2D"); return; } Texture2D t = tex as Texture2D; //Is there a better way to do this? try { Color c = t.GetPixel(0, 0); } catch { Ocean.LogWarning("Can not query overlays " + name + " if read/write is not enabled"); } }
public void CreateAndCacheCondition(int fourierSize, float windSpeed, float windDir, float waveAge) { if (this.m_conditionCache == null) { return; } if (this.m_conditionCache.Count >= this.m_maxConditionCacheSize) { Ocean.LogWarning("Condition cache full. Condition not cached."); return; } if (!Mathf.IsPowerOfTwo(fourierSize) || fourierSize < 32 || fourierSize > 512) { Ocean.LogWarning("Fourier size must be a pow2 number from 32 to 512. Condition not cached."); return; } WaveSpectrumCondition waveSpectrumCondition = this.NewSpectrumCondition(fourierSize, windSpeed, windDir, waveAge); if (this.m_conditionCache.ContainsKey(waveSpectrumCondition.Key)) { return; } IThreadedTask createSpectrumConditionTask = waveSpectrumCondition.GetCreateSpectrumConditionTask(); createSpectrumConditionTask.Start(); createSpectrumConditionTask.Run(); createSpectrumConditionTask.End(); this.m_conditionCache.AddFirst(waveSpectrumCondition.Key, waveSpectrumCondition); }
void Start() { try { //Needs at least SM3 for vertex texture fetches. if (SystemInfo.graphicsShaderLevel < 30) { throw new InvalidOperationException("The projected grids needs at least SM3 to render."); } if (oceanTopSideMat == null) { Ocean.LogWarning("Top side material is null. There will be no top ocean mesh rendered"); } if (oceanUnderSideMat == null) { Ocean.LogWarning("Under side material is null. There will be no under ocean mesh rendered"); } } catch (Exception e) { Ocean.LogError(e.ToString()); WasError = true; enabled = false; } }
private void GetFourierSize(out int size, out bool isCpu) { switch (this.fourierSize) { case FOURIER_SIZE.LOW_32_CPU: size = 32; isCpu = true; break; case FOURIER_SIZE.LOW_32_GPU: size = 32; isCpu = false; break; case FOURIER_SIZE.MEDIUM_64_CPU: size = 64; isCpu = true; break; case FOURIER_SIZE.MEDIUM_64_GPU: size = 64; isCpu = false; break; case FOURIER_SIZE.HIGH_128_CPU: size = 128; isCpu = true; break; case FOURIER_SIZE.HIGH_128_GPU: size = 128; isCpu = false; break; case FOURIER_SIZE.ULTRA_256_GPU: size = 256; isCpu = false; break; case FOURIER_SIZE.EXTREME_512_GPU: size = 512; isCpu = false; break; default: size = 64; isCpu = true; break; } bool flag = SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders; if (!isCpu && !this.disableReadBack && !flag) { Ocean.LogWarning("You card does not support dx11. Fourier can not be GPU. Changing to CPU. Disable read backs to use GPU but with no height querys."); this.fourierSize = FOURIER_SIZE.MEDIUM_64_CPU; size = 64; isCpu = true; } }
private void GenerateFoam(float time) { Vector4 vector = this.Choppyness; if (!this.disableFoam && SystemInfo.graphicsShaderLevel < 30) { Ocean.LogWarning("Spectrum foam needs at least SM3 to run. Disabling foam."); this.disableFoam = true; } float sqrMagnitude = vector.sqrMagnitude; this.m_jacobianBuffer.EnableBuffer(-1); if (this.disableFoam || this.foamAmount == 0f || sqrMagnitude == 0f || !this.m_conditions[0].SupportsJacobians) { this.m_jacobianBuffer.DisableBuffer(-1); } if (this.m_jacobianBuffer.EnabledBuffers() == 0) { Shader.SetGlobalTexture("Ceto_FoamMap0", Texture2D.blackTexture); } else { int numGrids = this.m_conditions[0].Key.NumGrids; if (numGrids == 1) { this.m_jacobianBuffer.DisableBuffer(1); this.m_jacobianBuffer.DisableBuffer(2); } else if (numGrids == 2) { this.m_jacobianBuffer.DisableBuffer(2); } if (!this.m_jacobianBuffer.HasRun || this.m_jacobianBuffer.TimeValue != time) { this.m_foamInitMat.SetFloat("Ceto_FoamAmount", this.foamAmount); this.m_jacobianBuffer.InitMaterial = this.m_foamInitMat; this.m_jacobianBuffer.InitPass = numGrids - 1; this.m_jacobianBuffer.Run(this.m_conditions[0], time); } if (!this.m_jacobianBuffer.BeenSampled) { this.m_jacobianBuffer.EnableSampling(); this.m_foamCopyMat.SetTexture("Ceto_JacobianBuffer0", this.m_jacobianBuffer.GetTexture(0)); this.m_foamCopyMat.SetTexture("Ceto_JacobianBuffer1", this.m_jacobianBuffer.GetTexture(1)); this.m_foamCopyMat.SetTexture("Ceto_JacobianBuffer2", this.m_jacobianBuffer.GetTexture(2)); this.m_foamCopyMat.SetTexture("Ceto_HeightBuffer", this.m_displacementBuffer.GetTexture(0)); this.m_foamCopyMat.SetVector("Ceto_FoamChoppyness", vector); this.m_foamCopyMat.SetFloat("Ceto_FoamCoverage", this.foamCoverage); Graphics.Blit(null, this.m_foamMaps[0], this.m_foamCopyMat, numGrids - 1); Shader.SetGlobalTexture("Ceto_FoamMap0", this.m_foamMaps[0]); this.m_jacobianBuffer.DisableSampling(); this.m_jacobianBuffer.BeenSampled = true; } } }
private void Update() { try { Shader.SetGlobalFloat("Ceto_GridEdgeBorder", Mathf.Max(0f, this.borderLength)); int num = this.ResolutionToNumber(this.resolution); Vector2 v = new Vector2((float)num / (float)this.ScreenWidth(), (float)num / (float)this.ScreenHeight()); Shader.SetGlobalVector("Ceto_ScreenGridSize", v); this.CreateGrid(this.resolution); Dictionary <MESH_RESOLUTION, ProjectedGrid.Grid> .Enumerator enumerator = this.m_grids.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <MESH_RESOLUTION, ProjectedGrid.Grid> current = enumerator.Current; ProjectedGrid.Grid value = current.Value; KeyValuePair <MESH_RESOLUTION, ProjectedGrid.Grid> current2 = enumerator.Current; bool flag = current2.Key == this.resolution; if (flag) { this.UpdateGrid(value); this.Activate(value.top, true); this.Activate(value.under, true); } else { this.Activate(value.top, false); this.Activate(value.under, false); } } if (this.m_ocean.UnderWater == null || this.m_ocean.UnderWater.Mode == UNDERWATER_MODE.ABOVE_ONLY) { enumerator = this.m_grids.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <MESH_RESOLUTION, ProjectedGrid.Grid> current3 = enumerator.Current; this.Activate(current3.Value.under, false); } } if (this.oceanTopSideMat != null && this.m_ocean.UnderWater != null && this.m_ocean.UnderWater.DepthMode == DEPTH_MODE.USE_DEPTH_BUFFER && this.oceanTopSideMat.shader.isSupported && this.oceanTopSideMat.renderQueue <= 2500) { Ocean.LogWarning("Underwater depth mode must be USE_OCEAN_DEPTH_PASS if using opaque material. Underwater effect will not look correct."); } } catch (Exception ex) { Ocean.LogError(ex.ToString()); base.WasError = true; base.enabled = false; } }
private void ReadFromGPU(int numGrids) { if (!this.disableReadBack && this.readSdr == null) { Ocean.LogWarning("Trying to read GPU displacement data but the read shader is null"); } bool flag = SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders; if (!this.disableReadBack && this.readSdr != null && this.m_readBuffer != null && flag) { InterpolatedArray2f[] readDisplacements = this.DisplacementBuffer.GetReadDisplacements(); if (numGrids > 0) { CBUtility.ReadFromRenderTexture(this.m_displacementMaps[0], 3, this.m_readBuffer, this.readSdr); this.m_readBuffer.GetData(readDisplacements[0].Data); } else { readDisplacements[0].Clear(); } if (numGrids > 1) { CBUtility.ReadFromRenderTexture(this.m_displacementMaps[1], 3, this.m_readBuffer, this.readSdr); this.m_readBuffer.GetData(readDisplacements[1].Data); } else { readDisplacements[1].Clear(); } if (numGrids > 2) { CBUtility.ReadFromRenderTexture(this.m_displacementMaps[2], 3, this.m_readBuffer, this.readSdr); this.m_readBuffer.GetData(readDisplacements[2].Data); } else { readDisplacements[2].Clear(); } if (numGrids > 3) { } } }
protected void CheckCanSampleTex(Texture tex, string name) { if (tex == null) { return; } if (!(tex is Texture2D)) { Ocean.LogWarning("Can not query overlays " + name + " if texture is not Texture2D"); return; } Texture2D texture2D = tex as Texture2D; try { Color pixel = texture2D.GetPixel(0, 0); } catch { Ocean.LogWarning("Can not query overlays " + name + " if read/write is not enabled"); } }
private WaveSpectrumConditionKey NewSpectrumConditionKey(int fourierSize, float windSpeed, float windDir, float waveAge) { WaveSpectrumConditionKey result; switch (this.spectrumType) { case SPECTRUM_TYPE.UNIFIED: result = new UnifiedSpectrumConditionKey(windSpeed, waveAge, fourierSize, windDir, this.spectrumType, this.numberOfGrids); break; case SPECTRUM_TYPE.PHILLIPS: result = new PhillipsSpectrumConditionKey(windSpeed, fourierSize, windDir, this.spectrumType, this.numberOfGrids); break; case SPECTRUM_TYPE.UNIFIED_PHILLIPS: result = new UnifiedSpectrumConditionKey(windSpeed, waveAge, fourierSize, windDir, this.spectrumType, this.numberOfGrids); break; case SPECTRUM_TYPE.CUSTOM: if (base.CustomWaveSpectrum == null) { Ocean.LogWarning("Custom spectrum type selected but no custom spectrum interface has been added to the wave spectrum. Defaulting to Unified Spectrum"); this.spectrumType = SPECTRUM_TYPE.UNIFIED; result = new UnifiedSpectrumConditionKey(windSpeed, waveAge, fourierSize, windDir, this.spectrumType, this.numberOfGrids); } else { result = base.CustomWaveSpectrum.CreateKey(fourierSize, windDir, this.spectrumType, this.numberOfGrids); } break; default: throw new InvalidOperationException("Invalid spectrum type = " + this.spectrumType); } return(result); }
private void Start() { try { if (SystemInfo.graphicsShaderLevel < 30) { throw new InvalidOperationException("The projected grids needs at least SM3 to render."); } if (this.oceanTopSideMat == null) { Ocean.LogWarning("Top side material is null. There will be no top ocean mesh rendered"); } if (this.m_ocean.UnderWater != null && this.m_ocean.UnderWater.Mode == UNDERWATER_MODE.ABOVE_AND_BELOW && this.oceanUnderSideMat == null) { Ocean.LogWarning("Under side material is null. There will be no under ocean mesh rendered"); } } catch (Exception ex) { Ocean.LogError(ex.ToString()); base.WasError = true; base.enabled = false; } }
void CreateShoreMasks() { //float t = Time.realtimeSinceStartup; Release(); Terrain terrain = GetComponent <Terrain>(); if (terrain == null) { //If there gameobject has not terrain print a warning and return. //Do this rather than have a terrain as a required component as it would be //rather annoying for the script to create a terrain if added to wrong gameobject. Ocean.LogWarning("The AddAutoShoreMask script must be attached to a component with a Terrain. The shore mask will not be created."); enabled = false; return; } if (terrain.terrainData == null) { //This can happen if the terrain data in asset folder is deleted Ocean.LogWarning("The terrain data is null. The shore mask will not be created."); enabled = false; return; } Vector3 size = terrain.terrainData.size; resolution = Mathf.Clamp(resolution, 32, 4096); m_width = size.x; m_height = size.z; float level = Ocean.Instance.level; float[] data = ShoreMaskGenerator.CreateHeightMap(terrain); int actualResolution = terrain.terrainData.heightmapResolution; InterpolatedArray2f heightMap = new InterpolatedArray2f(data, actualResolution, actualResolution, 1, false); if (useHeightMask || useNormalMask || useFoamMask) { m_heightMask = ShoreMaskGenerator.CreateMask(heightMap, resolution, resolution, level, heightSpread, TextureFormat.ARGB32); } if (useEdgeFoam) { m_edgeFoam = ShoreMaskGenerator.CreateMask(heightMap, resolution, resolution, level, foamSpread, TextureFormat.ARGB32); } if (useClipMask) { m_clipMask = ShoreMaskGenerator.CreateClipMask(heightMap, resolution, resolution, level + clipOffset, TextureFormat.ARGB32); } if (useHeightMask) { m_overlays[0].HeightTex.mask = m_heightMask; } if (useNormalMask) { m_overlays[0].NormalTex.mask = m_heightMask; } if (useFoamMask) { m_overlays[0].FoamTex.mask = m_heightMask; } if (useEdgeFoam) { m_overlays[0].FoamTex.tex = m_edgeFoam; } if (useClipMask) { m_overlays[0].ClipTex.tex = m_clipMask; } if (!m_registered) { Ocean.Instance.OverlayManager.Add(m_overlays[0]); m_registered = true; } m_heightSpread = heightSpread; m_foamSpread = foamSpread; m_clipOffset = clipOffset; m_resolution = resolution; //Debug.Log("Shore mask creation time = " + (Time.realtimeSinceStartup - t) * 1000.0f); }
void Update() { try { Shader.SetGlobalFloat("Ceto_GridEdgeBorder", Mathf.Max(0.0f, borderLength)); int r = ResolutionToNumber(resolution); Vector2 screenGridSize = new Vector2(r / (float)ScreenWidth(), r / (float)ScreenHeight()); Shader.SetGlobalVector("Ceto_ScreenGridSize", screenGridSize); //Check to see if the mesh has been created for this resolution setting. //If not create it. CreateGrid(resolution); var e = m_grids.GetEnumerator(); while (e.MoveNext()) { Grid grid = e.Current.Value; //If this mesh is the one for the current resolution setting. bool active = e.Current.Key == resolution; if (active) { UpdateGrid(grid); Activate(grid.top, true); Activate(grid.under, true); } else { //Else it is not being rendered, disable it. Activate(grid.top, false); Activate(grid.under, false); } } //If the underwater mode is set to above only the under side will not //be rendered so disable it. if (m_ocean.UnderWater == null || m_ocean.UnderWater.Mode == UNDERWATER_MODE.ABOVE_ONLY) { e = m_grids.GetEnumerator(); while (e.MoveNext()) { Activate(e.Current.Value.under, false); } } //Check to see if the correct depth mode is being used for the opaque material. if (oceanTopSideMat != null && m_ocean.UnderWater != null && m_ocean.UnderWater.DepthMode == DEPTH_MODE.USE_DEPTH_BUFFER) { if (oceanTopSideMat.shader.isSupported && oceanTopSideMat.renderQueue <= 2500) { Ocean.LogWarning("Underwater depth mode must be USE_OCEAN_DEPTH_PASS if using opaque material. Underwater effect will not look correct."); } } } catch (Exception e) { Ocean.LogError(e.ToString()); WasError = true; enabled = false; } }
private void GenerateDisplacement(float time) { if (!this.disableDisplacements && SystemInfo.graphicsShaderLevel < 30 && this.m_displacementBuffer.IsGPU) { Ocean.LogWarning("Spectrum displacements needs at least SM3 to run on GPU. Disabling displacement."); this.disableDisplacements = true; } this.m_displacementBuffer.EnableBuffer(-1); if (this.disableDisplacements) { this.m_displacementBuffer.DisableBuffer(-1); } if (!this.disableDisplacements && this.choppyness == 0f) { this.m_displacementBuffer.DisableBuffer(1); this.m_displacementBuffer.DisableBuffer(2); } if (!this.disableDisplacements && this.choppyness > 0f) { this.m_displacementBuffer.EnableBuffer(1); this.m_displacementBuffer.EnableBuffer(2); } if (this.m_displacementBuffer.EnabledBuffers() == 0) { Shader.SetGlobalTexture("Ceto_DisplacementMap0", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_DisplacementMap1", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_DisplacementMap2", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_DisplacementMap3", Texture2D.blackTexture); return; } if (this.m_displacementBuffer.Done) { int numGrids = this.m_conditions[0].Key.NumGrids; if (numGrids <= 2) { this.m_displacementBuffer.DisableBuffer(2); } if (!this.m_displacementBuffer.HasRun || this.m_displacementBuffer.TimeValue != time) { this.m_displacementBuffer.InitMaterial = this.m_displacementInitMat; this.m_displacementBuffer.InitPass = numGrids - 1; this.m_displacementBuffer.Run(this.m_conditions[0], time); } if (!this.m_displacementBuffer.BeenSampled) { this.m_displacementBuffer.EnableSampling(); this.m_displacementCopyMat.SetTexture("Ceto_HeightBuffer", this.m_displacementBuffer.GetTexture(0)); this.m_displacementCopyMat.SetTexture("Ceto_DisplacementBuffer", this.m_displacementBuffer.GetTexture(1)); if (numGrids > 0) { Graphics.Blit(null, this.m_displacementMaps[0], this.m_displacementCopyMat, (numGrids != 1) ? 0 : 4); Shader.SetGlobalTexture("Ceto_DisplacementMap0", this.m_displacementMaps[0]); } else { Shader.SetGlobalTexture("Ceto_DisplacementMap0", Texture2D.blackTexture); } if (numGrids > 1) { Graphics.Blit(null, this.m_displacementMaps[1], this.m_displacementCopyMat, 1); Shader.SetGlobalTexture("Ceto_DisplacementMap1", this.m_displacementMaps[1]); } else { Shader.SetGlobalTexture("Ceto_DisplacementMap1", Texture2D.blackTexture); } this.m_displacementCopyMat.SetTexture("Ceto_DisplacementBuffer", this.m_displacementBuffer.GetTexture(2)); if (numGrids > 2) { Graphics.Blit(null, this.m_displacementMaps[2], this.m_displacementCopyMat, 2); Shader.SetGlobalTexture("Ceto_DisplacementMap2", this.m_displacementMaps[2]); } else { Shader.SetGlobalTexture("Ceto_DisplacementMap2", Texture2D.blackTexture); } if (numGrids > 3) { Graphics.Blit(null, this.m_displacementMaps[3], this.m_displacementCopyMat, 3); Shader.SetGlobalTexture("Ceto_DisplacementMap3", this.m_displacementMaps[3]); } else { Shader.SetGlobalTexture("Ceto_DisplacementMap3", Texture2D.blackTexture); } this.m_displacementBuffer.DisableSampling(); this.m_displacementBuffer.BeenSampled = true; if (this.m_displacementBuffer.IsGPU) { this.ReadFromGPU(numGrids); } this.FindRanges(); } } }
private void GenerateSlopes(float time) { if (!this.disableSlopes && SystemInfo.graphicsShaderLevel < 30) { Ocean.LogWarning("Spectrum slopes needs at least SM3 to run. Disabling slopes."); this.disableSlopes = true; } if (this.disableSlopes) { this.m_slopeBuffer.DisableBuffer(-1); } else { this.m_slopeBuffer.EnableBuffer(-1); } if (this.m_slopeBuffer.EnabledBuffers() == 0) { Shader.SetGlobalTexture("Ceto_SlopeMap0", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_SlopeMap1", Texture2D.blackTexture); } else { int numGrids = this.m_conditions[0].Key.NumGrids; if (numGrids <= 2) { this.m_slopeBuffer.DisableBuffer(1); } if (!this.m_slopeBuffer.HasRun || this.m_slopeBuffer.TimeValue != time) { this.m_slopeBuffer.InitMaterial = this.m_slopeInitMat; this.m_slopeBuffer.InitPass = numGrids - 1; this.m_slopeBuffer.Run(this.m_conditions[0], time); } if (!this.m_slopeBuffer.BeenSampled) { this.m_slopeBuffer.EnableSampling(); if (numGrids > 0) { this.m_slopeCopyMat.SetTexture("Ceto_SlopeBuffer", this.m_slopeBuffer.GetTexture(0)); Graphics.Blit(null, this.m_slopeMaps[0], this.m_slopeCopyMat, 0); Shader.SetGlobalTexture("Ceto_SlopeMap0", this.m_slopeMaps[0]); } else { Shader.SetGlobalTexture("Ceto_SlopeMap0", Texture2D.blackTexture); } if (numGrids > 2) { this.m_slopeCopyMat.SetTexture("Ceto_SlopeBuffer", this.m_slopeBuffer.GetTexture(1)); Graphics.Blit(null, this.m_slopeMaps[1], this.m_slopeCopyMat, 0); Shader.SetGlobalTexture("Ceto_SlopeMap1", this.m_slopeMaps[1]); } else { Shader.SetGlobalTexture("Ceto_SlopeMap1", Texture2D.blackTexture); } this.m_slopeBuffer.DisableSampling(); this.m_slopeBuffer.BeenSampled = true; } } }
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 { Shader.SetGlobalFloat("Ceto_GridEdgeBorder", Mathf.Max(0.0f, borderLength)); int r = ResolutionToNumber(resolution); Vector2 screenGridSize = new Vector2(r / (float)ScreenWidth(), r / (float)ScreenHeight()); Shader.SetGlobalVector("Ceto_ScreenGridSize", screenGridSize); //Check to see if the mesh has been created for this resolution setting. //If not create it. CreateGrid(resolution); var e = m_grids.GetEnumerator(); while (e.MoveNext()) { Grid grid = e.Current.Value; //If this mesh is the one for the current resolution setting. bool active = e.Current.Key == (int)resolution; if (active) { UpdateGrid(grid); Activate(grid.top, true); Activate(grid.under, true); } else { //Else it is not being rendered, disable it. Activate(grid.top, false); Activate(grid.under, false); } } //If the underside not needed disable it. if (!UnderSideNeeded()) { e = m_grids.GetEnumerator(); while (e.MoveNext()) { Activate(e.Current.Value.under, false); } } //If the topside not needed disable it. if (!TopSideNeeded()) { e = m_grids.GetEnumerator(); while (e.MoveNext()) { Activate(e.Current.Value.top, false); } } //Check to see if the correct depth mode is being used for the opaque material. if (oceanTopSideMat != null && m_ocean.UnderWater != null && m_ocean.UnderWater.depthMode == DEPTH_MODE.USE_DEPTH_BUFFER) { if (oceanTopSideMat.shader.isSupported && oceanTopSideMat.renderQueue <= 2500) { Ocean.LogWarning("Underwater depth mode must be USE_OCEAN_DEPTH_PASS if using opaque material. Underwater effect will not look correct."); } } } catch (Exception e) { Ocean.LogError(e.ToString()); WasError = true; enabled = false; } }
private void CreateShoreMasks() { this.Release(); Terrain component = base.GetComponent<Terrain>(); if (component == null) { Ocean.LogWarning("The AddAutoShoreMask script must be attached to a component with a Terrain. The shore mask will not be created."); base.enabled = false; return; } if (component.terrainData == null) { Ocean.LogWarning("The terrain data is null. The shore mask will not be created."); base.enabled = false; return; } Vector3 size = component.terrainData.size; this.resolution = Mathf.Clamp(this.resolution, 32, 4096); this.m_width = size.x; this.m_height = size.z; float level = Ocean.Instance.level; float[] data = ShoreMaskGenerator.CreateHeightMap(component); int heightmapResolution = component.terrainData.heightmapResolution; InterpolatedArray2f heightMap = new InterpolatedArray2f(data, heightmapResolution, heightmapResolution, 1, false); if (this.useHeightMask || this.useNormalMask || this.useFoamMask) { this.m_heightMask = ShoreMaskGenerator.CreateMask(heightMap, this.resolution, this.resolution, level, this.heightSpread, TextureFormat.ARGB32); } if (this.useEdgeFoam) { this.m_edgeFoam = ShoreMaskGenerator.CreateMask(heightMap, this.resolution, this.resolution, level, this.foamSpread, TextureFormat.ARGB32); } if (this.useClipMask) { this.m_clipMask = ShoreMaskGenerator.CreateClipMask(heightMap, this.resolution, this.resolution, level + this.clipOffset, TextureFormat.ARGB32); } if (this.useHeightMask) { this.m_overlays[0].HeightTex.mask = this.m_heightMask; } if (this.useNormalMask) { this.m_overlays[0].NormalTex.mask = this.m_heightMask; } if (this.useFoamMask) { this.m_overlays[0].FoamTex.mask = this.m_heightMask; } if (this.useEdgeFoam) { this.m_overlays[0].FoamTex.tex = this.m_edgeFoam; } if (this.useClipMask) { this.m_overlays[0].ClipTex.tex = this.m_clipMask; } if (!this.m_registered) { Ocean.Instance.OverlayManager.Add(this.m_overlays[0]); this.m_registered = true; } this.m_heightSpread = this.heightSpread; this.m_foamSpread = this.foamSpread; this.m_clipOffset = this.clipOffset; this.m_resolution = (float)this.resolution; }
void Update() { try { #if UNITY_WEBGL //There is a issue with the webGL projection matrix in the build when converting the //depth to world position. Have to use the depth pass instead. if (depthMode == DEPTH_MODE.USE_DEPTH_BUFFER) { Ocean.LogWarning("Underwater depth mode for WebGL can not be USE_DEPTH_BUFFER. Changing to USE_OCEAN_DEPTH_PASS"); depthMode = DEPTH_MODE.USE_OCEAN_DEPTH_PASS; } #endif Vector4 absCof = new Vector4(absorptionR, absorptionG, absorptionB, 1.0f); Vector4 sssCof = absCof; Vector4 belowCof = absCof; absCof.w = Mathf.Max(0.0f, aboveAbsorptionModifier.scale); sssCof.w = Mathf.Max(0.0f, subSurfaceScatterModifier.scale); belowCof.w = Mathf.Max(0.0f, belowAbsorptionModifier.scale); Color absTint = aboveAbsorptionModifier.tint * Mathf.Max(0.0f, aboveAbsorptionModifier.intensity); Color sssTint = subSurfaceScatterModifier.tint * Mathf.Max(0.0f, subSurfaceScatterModifier.intensity); Color belowTint = belowAbsorptionModifier.tint * Mathf.Max(0.0f, belowAbsorptionModifier.intensity); Vector4 causticParam = new Vector4(); causticParam.x = (causticTexture.scale.x != 0.0f) ? 1.0f / causticTexture.scale.x : 1.0f; causticParam.y = (causticTexture.scale.y != 0.0f) ? 1.0f / causticTexture.scale.y : 1.0f; causticParam.z = 0.0f; causticParam.w = Mathf.Clamp01(causticModifier.depthFade); Vector2 causticDistortion = new Vector2(); causticDistortion.x = causticModifier.aboveDistortion; causticDistortion.y = causticModifier.belowDistortion; Shader.SetGlobalVector("Ceto_AbsCof", absCof); Shader.SetGlobalColor("Ceto_AbsTint", absTint); Shader.SetGlobalVector("Ceto_SSSCof", sssCof); Shader.SetGlobalColor("Ceto_SSSTint", sssTint); Shader.SetGlobalVector("Ceto_BelowCof", belowCof); Shader.SetGlobalColor("Ceto_BelowTint", belowTint); Color aboveInscatterCol = aboveInscatterModifier.color; aboveInscatterCol.a = Mathf.Clamp01(aboveInscatterModifier.intensity); Shader.SetGlobalFloat("Ceto_AboveInscatterScale", Mathf.Max(0.1f, aboveInscatterModifier.scale)); Shader.SetGlobalVector("Ceto_AboveInscatterMode", InscatterModeToMask(aboveInscatterModifier.mode)); Shader.SetGlobalColor("Ceto_AboveInscatterColor", aboveInscatterCol); Color belowInscatterCol = belowInscatterModifier.color; belowInscatterCol.a = Mathf.Clamp01(belowInscatterModifier.intensity); Shader.SetGlobalFloat("Ceto_BelowInscatterScale", Mathf.Max(0.1f, belowInscatterModifier.scale)); Shader.SetGlobalVector("Ceto_BelowInscatterMode", InscatterModeToMask(belowInscatterModifier.mode)); Shader.SetGlobalColor("Ceto_BelowInscatterColor", belowInscatterCol); Shader.SetGlobalFloat("Ceto_AboveRefractionIntensity", Mathf.Max(0.0f, aboveRefractionIntensity)); Shader.SetGlobalFloat("Ceto_BelowRefractionIntensity", Mathf.Max(0.0f, belowRefractionIntensity)); Shader.SetGlobalFloat("Ceto_RefractionDistortion", refractionDistortion * 0.05f); Shader.SetGlobalFloat("Ceto_MaxDepthDist", Mathf.Max(0.0f, MAX_DEPTH_DIST)); Shader.SetGlobalFloat("Ceto_DepthBlend", Mathf.Clamp01(depthBlend)); Shader.SetGlobalFloat("Ceto_EdgeFade", Mathf.Lerp(20.0f, 2.0f, Mathf.Clamp01(edgeFade))); Shader.SetGlobalTexture("Ceto_CausticTexture", ((causticTexture.tex != null) ? causticTexture.tex : Texture2D.blackTexture)); Shader.SetGlobalVector("Ceto_CausticTextureScale", causticParam); Shader.SetGlobalVector("Ceto_CausticDistortion", causticDistortion); Shader.SetGlobalColor("Ceto_CausticTint", causticModifier.tint * causticModifier.intensity); if (depthMode == DEPTH_MODE.USE_OCEAN_DEPTH_PASS) { Shader.EnableKeyword("CETO_USE_OCEAN_DEPTHS_BUFFER"); if (underwaterMode == UNDERWATER_MODE.ABOVE_ONLY) { SetBottomActive(m_bottomMask, false); } else { SetBottomActive(m_bottomMask, true); UpdateBottomBounds(); } } else { Shader.DisableKeyword("CETO_USE_OCEAN_DEPTHS_BUFFER"); if (underwaterMode == UNDERWATER_MODE.ABOVE_ONLY) { SetBottomActive(m_bottomMask, false); } else { SetBottomActive(m_bottomMask, true); UpdateBottomBounds(); } } } catch (Exception e) { Ocean.LogError(e.ToString()); WasError = true; enabled = false; } }