public override void QueryWaves(WaveQuery query) { if (!base.enabled) { return; } IDisplacementBuffer displacementBuffer = this.DisplacementBuffer; if (displacementBuffer == null) { return; } if (this.disableReadBack && displacementBuffer.IsGPU) { return; } if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION) { return; } if (!query.sampleSpectrum[0] && !query.sampleSpectrum[1] && !query.sampleSpectrum[2] && !query.sampleSpectrum[3]) { return; } displacementBuffer.QueryWaves(query, this.m_queryScaling); }
/// <summary> /// Run the task. /// Warning - this will not run on the main thread. /// </summary> public override IEnumerator Run() { var e = Querys.GetEnumerator(); while (e.MoveNext()) { //Task has been cancelled. Stop and return. if (Cancelled) { break; } WaveQuery query = e.Current; query.result.Clear(); //Sample the spectrum waves. if (Displacements != null) { QueryDisplacements.QueryWaves(query, EnabledBuffers, Displacements, Scaling); } query.result.height += OceanLevel; } FinishedRunning(); return(null); }
public void QueryWaves(WaveQuery query, QueryGridScaling scaling) { int enabled = EnabledBuffers(); //If no buffers are enabled there is nothing to sample. if(enabled == 0) return; QueryDisplacements.QueryWaves(query, enabled, m_displacements, scaling); }
public void QueryWaves(WaveQuery query, QueryGridScaling scaling) { int num = this.EnabledBuffers(); if (num == 0) { return; } QueryDisplacements.QueryWaves(query, num, this.m_displacements, scaling); }
public void QueryWaves(WaveQuery query, QueryGridScaling scaling) { int num = this.EnabledBuffers(); if (num == 0) { return; } InterpolatedArray2f[] readDisplacements = this.GetReadDisplacements(); QueryDisplacements.QueryWaves(query, num, readDisplacements, scaling); }
public void QueryWaves(WaveQuery query, QueryGridScaling scaling) { int enabled = EnabledBuffers(); //If no buffers are enabled there is nothing to sample. if (enabled == 0) { return; } QueryDisplacements.QueryWaves(query, enabled, m_displacements, scaling); }
public void QueryWaves(WaveQuery query, QueryGridScaling scaling) { int enabled = EnabledBuffers(); //If no buffers are enabled there is nothing to sample. if (enabled == 0) { return; } InterpolatedArray2f[] displacements = GetReadDisplacements(); QueryDisplacements.QueryWaves(query, enabled, displacements, scaling); }
public void QueryWaves(WaveQuery query) { query.result.Clear(); if (base.enabled) { if (this.Spectrum != null) { this.Spectrum.QueryWaves(query); } if (this.OverlayManager != null) { this.OverlayManager.QueryWaves(query); } } query.result.height = query.result.height + this.level; }
/// <summary> /// Run the task. /// This will run on the main thread. /// </summary> public override IEnumerator Run() { int count = 0; int querysPerIteration = Math.Max(1, QuerysPerIteration); var e = Querys.GetEnumerator(); while (e.MoveNext()) { //Task has been cancelled. Stop and return. if (Cancelled) { yield break; } WaveQuery query = e.Current; query.result.Clear(); //Sample the spectrum waves. if (Displacements != null) { QueryDisplacements.QueryWaves(query, EnabledBuffers, Displacements, Scaling); } //Sample the overlay waves. if (OverlaySampler != null) { OverlaySampler.QueryWaves(query); } query.result.height += OceanLevel; //If count has reached the number of querys to perform //each iteration the yield and come back next frame. if (count % querysPerIteration == querysPerIteration - 1) { yield return(null); } count++; } FinishedRunning(); yield break; }
bool UnderWaterIsVisible(Camera cam) { if (Ocean.Instance == null) { return(false); } Vector3 pos = cam.transform.position; if (disableOnClip) { WaveQuery query = new WaveQuery(pos); query.mode = QUERY_MODE.CLIP_TEST; Ocean.Instance.QueryWaves(query); if (query.result.isClipped) { return(false); } } float upperRange = Ocean.Instance.FindMaxDisplacement(true) + Ocean.Instance.level; if (pos.y < upperRange) { return(true); } Matrix4x4 ivp = (cam.projectionMatrix * cam.worldToCameraMatrix).inverse; for (int i = 0; i < 4; i++) { Vector4 p = ivp * m_corners[i]; p.y /= p.w; if (p.y < upperRange) { return(true); } } return(false); }
public void QueryWaves(IEnumerable <WaveQuery> querys) { foreach (WaveQuery waveQuery in querys) { waveQuery.result.Clear(); if (base.enabled) { if (this.Spectrum != null) { this.Spectrum.QueryWaves(waveQuery); } if (this.OverlayManager != null) { this.OverlayManager.QueryWaves(waveQuery); } } WaveQuery waveQuery2 = waveQuery; waveQuery2.result.height = waveQuery2.result.height + this.level; } }
/// <summary> /// Query the waves at world position xz. /// </summary> public void QueryWaves(WaveQuery query) { //Clear previous result in query. query.result.Clear(); if (enabled) { if (Spectrum != null) { Spectrum.QueryWaves(query); } if (OverlayManager != null) { OverlayManager.QueryWaves(query); } } query.result.height += level; }
public void QueryWaves(IEnumerable <WaveQuery> querys) { foreach (WaveQuery current in querys) { current.result.Clear(); if (base.enabled) { if (this.Spectrum != null) { this.Spectrum.QueryWaves(current); } if (this.OverlayManager != null) { this.OverlayManager.QueryWaves(current); } } WaveQuery expr_63_cp_0 = current; expr_63_cp_0.result.height = expr_63_cp_0.result.height + this.level; } }
private void RunQueries() { IEnumerator <WaveQuery> enumerator = this.m_querys.GetEnumerator(); while (enumerator.MoveNext()) { if (this.Cancelled) { return; } WaveQuery current = enumerator.Current; current.result.Clear(); if (current.mode == QUERY_MODE.DISPLACEMENT || current.mode == QUERY_MODE.POSITION) { QueryDisplacements.QueryWaves(current, this.m_enabled, this.m_displacements, this.m_scaling); } WaveQuery expr_64_cp_0 = current; expr_64_cp_0.result.height = expr_64_cp_0.result.height + this.m_level; } }
private void RunQueries() { IEnumerator <WaveQuery> enumerator = this.m_querys.GetEnumerator(); while (enumerator.MoveNext()) { if (base.Cancelled) { return; } WaveQuery waveQuery = enumerator.Current; waveQuery.result.Clear(); if (waveQuery.mode == QUERY_MODE.DISPLACEMENT || waveQuery.mode == QUERY_MODE.POSITION) { QueryDisplacements.QueryWaves(waveQuery, this.m_enabled, this.m_displacements, this.m_scaling); } WaveQuery waveQuery2 = waveQuery; waveQuery2.result.height = waveQuery2.result.height + this.m_level; } }
void Start() { m_material = new Material(underWaterPostEffectSdr); m_imageBlur = new ImageBlur(blurShader); m_query = new WaveQuery(); //Dont think you need to toggle depth mode //if image effect not using ImageEffectOpaque tag /* * Camera cam = GetComponent<Camera>(); * * //If rendering mode deferred and dx9 then toggling the depth * //mode cause some strange issue with underwater effect * //if using the opaque ocean materials. * if (cam.actualRenderingPath == RenderingPath.Forward) * GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth; */ }
void RunQueries() { var e = m_querys.GetEnumerator(); while (e.MoveNext()) { if (Cancelled) { return; } WaveQuery query = e.Current; query.result.Clear(); //Only these modes are relevant to this code. if (query.mode == QUERY_MODE.DISPLACEMENT || query.mode == QUERY_MODE.POSITION) { QueryDisplacements.QueryWaves(query, m_enabled, m_displacements, m_scaling); } query.result.height += m_level; } }
private void Start() { this.m_material = new Material(this.underWaterPostEffectSdr); this.m_imageBlur = new ImageBlur(this.blurShader); this.m_query = new WaveQuery(); }
/// <summary> /// Queries the waves. /// </summary> public override void QueryWaves(WaveQuery query) { if(!enabled) return; IDisplacementBuffer buffer = DisplacementBuffer; if(buffer == null) return; //Nothing to query if displacement done on GPU but read back disabled. if(disableReadBack && buffer.IsGPU) return; //Only these modes are relevant to this code. if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION) return; //No spectrum grids will be sampled so return. if(!query.sampleSpectrum[0] && !query.sampleSpectrum[1] && !query.sampleSpectrum[2] && !query.sampleSpectrum[3]) return; buffer.QueryWaves(query, m_queryScaling); }
public void QueryWaves(WaveQuery query, QueryGridScaling scaling) { int enabled = EnabledBuffers(); //If no buffers are enabled there is nothing to sample. if(enabled == 0) return; InterpolatedArray2f[] displacements = GetReadDisplacements(); QueryDisplacements.QueryWaves(query, enabled, displacements, scaling); }
/// <summary> /// Query the waves for the wave height at a location. /// </summary> public abstract void QueryWaves(WaveQuery query);
public static void QueryWaves(WaveQuery query, int enabled, IList<InterpolatedArray2f> displacements, QueryGridScaling scaling) { if (displacements.Count != QueryDisplacements.GRIDS) { throw new InvalidOperationException("Query Displacements requires a displacement buffer for each of the " + QueryDisplacements.GRIDS + " grids."); } if (displacements[0].Channels != QueryDisplacements.CHANNELS) { throw new InvalidOperationException("Query Displacements requires displacement buffers have " + QueryDisplacements.CHANNELS + " channels."); } if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION) { return; } float num = query.posX + scaling.offset.x; float num2 = query.posZ + scaling.offset.z; if (enabled == 0) { return; } if (enabled == 1 || query.mode == QUERY_MODE.DISPLACEMENT) { QueryDisplacements.SampleHeightOnly(query.result.displacement, displacements, query.sampleSpectrum, num, num2, scaling, scaling.tmp); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = 0f; query.result.displacementZ = 0f; query.result.iterations = 0; query.result.error = 0f; query.result.height = Mathf.Clamp(query.result.height, -40f, 40f); } else { float num3 = num; float num4 = num2; float num5 = num; float num6 = num2; float num7 = query.minError; if (num7 < 0.1f) { num7 = 0.1f; } num7 *= num7; int num8 = 0; float num9; float num10; float num13; do { num5 += num - num3; num6 += num2 - num4; QueryDisplacements.Sample(query.result.displacement, displacements, query.sampleSpectrum, num5, num6, scaling, scaling.tmp); num9 = query.result.displacement[0].x + query.result.displacement[1].x + query.result.displacement[2].x + query.result.displacement[3].x; num10 = query.result.displacement[0].z + query.result.displacement[1].z + query.result.displacement[2].z + query.result.displacement[3].z; num3 = num5 + num9; num4 = num6 + num10; num8++; float num11 = num - num3; float num12 = num2 - num4; num13 = num11 * num11 + num12 * num12; } while (num13 > num7 && num8 <= WaveQuery.MAX_ITERATIONS); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = num9; query.result.displacementZ = num10; query.result.iterations = num8; query.result.error = num13; query.result.height = Mathf.Clamp(query.result.height, -40f, 40f); } }
/// <summary> /// Queries the waves. /// </summary> public void QueryWaves(WaveQuery query) { if (m_queryableOverlays.Count == 0) { return; } if (!query.sampleOverlay) { return; } bool clipOnly = query.mode == QUERY_MODE.CLIP_TEST; float x = query.posX; float z = query.posZ; //Find all the overlays that have a affect on the wave height at this position //This will be overlays with a height tex, a height mask or a clip texture GetQueryableContaining(x, z, query.overrideIgnoreQuerys, clipOnly); float clipSum = 0.0f; float heightSum = 0.0f; float maskSum = 0.0f; OverlayClipTexture clipTex = null; OverlayHeightTexture heightTex = null; for (int i = 0; i < m_containingOverlays.Count; i++) { QueryableOverlayResult result = m_containingOverlays[i]; //If enable read/write is not enabled on tex it will throw a exception. //Catch and ignore. try { clipTex = result.overlay.ClipTex; heightTex = result.overlay.HeightTex; //If overlay has a clip tex sample it. if (clipTex.IsDrawable && clipTex.tex is Texture2D) { float clip = (clipTex.tex as Texture2D).GetPixelBilinear(result.u, result.v).a; clipSum += clip * Mathf.Max(0.0f, clipTex.alpha); } //If overlay has a height or mask tex sample it. if (!clipOnly && heightTex.IsDrawable) { float alpha = heightTex.alpha; float maskAlpha = Mathf.Max(0.0f, heightTex.maskAlpha); float height = 0.0f; float mask = 0.0f; if (heightTex.tex != null && heightTex.tex is Texture2D) { height = (heightTex.tex as Texture2D).GetPixelBilinear(result.u, result.v).a; } if (heightTex.mask != null && heightTex.mask is Texture2D) { mask = (heightTex.mask as Texture2D).GetPixelBilinear(result.u, result.v).a; mask = Mathf.Clamp01(mask * maskAlpha); } //Apply the height and mask depending on mask mode. if (heightTex.maskMode == OVERLAY_MASK_MODE.WAVES) { height *= alpha; } else if (heightTex.maskMode == OVERLAY_MASK_MODE.OVERLAY) { height *= alpha * mask; mask = 0; } else if (heightTex.maskMode == OVERLAY_MASK_MODE.WAVES_AND_OVERLAY) { height *= alpha * (1.0f - mask); } else if (heightTex.maskMode == OVERLAY_MASK_MODE.WAVES_AND_OVERLAY_BLEND) { height *= alpha * mask; } if (HeightOverlayBlendMode == OVERLAY_BLEND_MODE.ADD) { heightSum += height; maskSum += mask; } else if (HeightOverlayBlendMode == OVERLAY_BLEND_MODE.MAX) { heightSum = Mathf.Max(height, heightSum); maskSum = Mathf.Max(mask, maskSum); } } } catch {} } clipSum = Mathf.Clamp01(clipSum); if (0.5f - clipSum < 0.0f) { query.result.isClipped = true; } maskSum = 1.0f - Mathf.Clamp01(maskSum); query.result.height *= maskSum; query.result.displacementX *= maskSum; query.result.displacementZ *= maskSum; query.result.height += heightSum; query.result.overlayHeight = heightSum; }
public abstract void QueryWaves(WaveQuery query);
/// <summary> /// Queries the waves. /// </summary> public void QueryWaves(WaveQuery query) { if(m_queryableOverlays.Count == 0) return; if(!query.sampleOverlay) return; bool clipOnly = query.mode == QUERY_MODE.CLIP_TEST; float x = query.posX; float z = query.posZ; //Find all the overlays that have a affect on the wave height at this position //This will be overlays with a height tex, a height mask or a clip texture GetQueryableContaining(x, z, query.overrideIgnoreQuerys, clipOnly); float clipSum = 0.0f; float heightSum = 0.0f; float maskSum = 0.0f; OverlayClipTexture clipTex = null; OverlayHeightTexture heightTex = null; var e = m_containingOverlays.GetEnumerator(); while(e.MoveNext()) { QueryableOverlayResult result = e.Current; //If enable read/write is not enabled on tex it will throw a exception. //Catch and ignore. try { clipTex = result.overlay.ClipTex; heightTex = result.overlay.HeightTex; //If overlay has a clip tex sample it. if(clipTex.IsDrawable && clipTex.tex is Texture2D) { float clip = (clipTex.tex as Texture2D).GetPixelBilinear(result.u, result.v).a; clipSum += clip * Mathf.Max(0.0f, clipTex.alpha); } //If overlay has a height or mask tex sample it. if(!clipOnly && heightTex.IsDrawable) { float alpha = heightTex.alpha; float maskAlpha = Mathf.Max(0.0f, heightTex.maskAlpha); float height = 0.0f; float mask = 0.0f; if(heightTex.tex != null && heightTex.tex is Texture2D) { height = (heightTex.tex as Texture2D).GetPixelBilinear(result.u, result.v).a; } if(heightTex.mask != null && heightTex.mask is Texture2D) { mask = (heightTex.mask as Texture2D).GetPixelBilinear(result.u, result.v).a; mask = Mathf.Clamp01(mask * maskAlpha); } //Apply the height and mask depending on mask mode. if(heightTex.maskMode == OVERLAY_MASK_MODE.WAVES) { height *= alpha; } else if(heightTex.maskMode == OVERLAY_MASK_MODE.OVERLAY) { height *= alpha * mask; mask = 0; } else if(heightTex.maskMode == OVERLAY_MASK_MODE.WAVES_AND_OVERLAY) { height *= alpha * (1.0f-mask); } else if(heightTex.maskMode == OVERLAY_MASK_MODE.WAVES_AND_OVERLAY_BLEND) { height *= alpha * mask; } heightSum += height; maskSum += mask; } } catch {} } clipSum = Mathf.Clamp01(clipSum); if(0.5f - clipSum < 0.0f) { query.result.isClipped = true; } maskSum = 1.0f - Mathf.Clamp01(maskSum); query.result.height *= maskSum; query.result.displacementX *= maskSum; query.result.displacementZ *= maskSum; query.result.height += heightSum; query.result.overlayHeight = heightSum; }
bool UnderWaterIsVisible(Camera cam) { if (Ocean.Instance == null) return false; Vector3 pos = cam.transform.position; if(disableOnClip) { WaveQuery query = new WaveQuery(pos); query.mode = QUERY_MODE.CLIP_TEST; Ocean.Instance.QueryWaves(query); if (query.result.isClipped) return false; } float upperRange = Ocean.Instance.FindMaxDisplacement(true) + Ocean.Instance.level; if (pos.y < upperRange) return true; Matrix4x4 ivp = (cam.projectionMatrix * cam.worldToCameraMatrix).inverse; for (int i = 0; i < 4; i++) { Vector4 p = ivp * m_corners[i]; p.y /= p.w; if (p.y < upperRange) { return true; } } return false; }
public static void QueryWaves(WaveQuery query, int enabled, IList <InterpolatedArray2f> displacements, QueryGridScaling scaling) { if (displacements.Count != GRIDS) { throw new InvalidOperationException("Query Displacements requires a displacement buffer for each of the " + GRIDS + " grids."); } if (displacements[0].Channels != CHANNELS) { throw new InvalidOperationException("Query Displacements requires displacement buffers have " + CHANNELS + " channels."); } //Only these modes are relevant to this code. if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION) { return; } float x = query.posX + scaling.offset.x; float z = query.posZ + scaling.offset.z; if (enabled == 0) { return; } else if (enabled == 1 || query.mode == QUERY_MODE.DISPLACEMENT) { SampleHeightOnly(query.result.displacement, displacements, query.sampleSpectrum, x, z, scaling, scaling.tmp); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = 0.0f; query.result.displacementZ = 0.0f; query.result.iterations = 0; query.result.error = 0.0f; query.result.height = Mathf.Clamp(query.result.height, -Ocean.MAX_SPECTRUM_WAVE_HEIGHT, Ocean.MAX_SPECTRUM_WAVE_HEIGHT); } else { float lx, lz; float dx = x; float dz = z; float u = x; float v = z; float displacementX; float displacementZ; float minError2 = query.minError; if (minError2 < 0.1f) { minError2 = 0.1f; } minError2 = minError2 * minError2; float error; int i = 0; do { u += x - dx; v += z - dz; Sample(query.result.displacement, displacements, query.sampleSpectrum, u, v, scaling, scaling.tmp); displacementX = query.result.displacement[0].x + query.result.displacement[1].x + query.result.displacement[2].x + query.result.displacement[3].x; displacementZ = query.result.displacement[0].z + query.result.displacement[1].z + query.result.displacement[2].z + query.result.displacement[3].z; dx = u + displacementX; dz = v + displacementZ; i++; lx = x - dx; lz = z - dz; error = lx * lx + lz * lz; }while (error > minError2 && i <= WaveQuery.MAX_ITERATIONS); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = displacementX; query.result.displacementZ = displacementZ; query.result.iterations = i; query.result.error = error; query.result.height = Mathf.Clamp(query.result.height, -Ocean.MAX_SPECTRUM_WAVE_HEIGHT, Ocean.MAX_SPECTRUM_WAVE_HEIGHT); } }
public void QueryWaves(WaveQuery query) { if (this.m_queryableOverlays.Count == 0) { return; } if (!query.sampleOverlay) { return; } bool flag = query.mode == QUERY_MODE.CLIP_TEST; float posX = query.posX; float posZ = query.posZ; this.GetQueryableContaining(posX, posZ, query.overrideIgnoreQuerys, flag); float num = 0f; float num2 = 0f; float num3 = 0f; foreach (QueryableOverlayResult queryableOverlayResult in this.m_containingOverlays) { try { OverlayClipTexture clipTex = queryableOverlayResult.overlay.ClipTex; OverlayHeightTexture heightTex = queryableOverlayResult.overlay.HeightTex; if (clipTex.IsDrawable && clipTex.tex is Texture2D) { float a = (clipTex.tex as Texture2D).GetPixelBilinear(queryableOverlayResult.u, queryableOverlayResult.v).a; num += a * Mathf.Max(0f, clipTex.alpha); } if (!flag && heightTex.IsDrawable) { float alpha = heightTex.alpha; float num4 = Mathf.Max(0f, heightTex.maskAlpha); float num5 = 0f; float num6 = 0f; if (heightTex.tex != null && heightTex.tex is Texture2D) { num5 = (heightTex.tex as Texture2D).GetPixelBilinear(queryableOverlayResult.u, queryableOverlayResult.v).a; } if (heightTex.mask != null && heightTex.mask is Texture2D) { num6 = (heightTex.mask as Texture2D).GetPixelBilinear(queryableOverlayResult.u, queryableOverlayResult.v).a; num6 = Mathf.Clamp01(num6 * num4); } if (heightTex.maskMode == OVERLAY_MASK_MODE.WAVES) { num5 *= alpha; } else if (heightTex.maskMode == OVERLAY_MASK_MODE.OVERLAY) { num5 *= alpha * num6; num6 = 0f; } else if (heightTex.maskMode == OVERLAY_MASK_MODE.WAVES_AND_OVERLAY) { num5 *= alpha * (1f - num6); } else if (heightTex.maskMode == OVERLAY_MASK_MODE.WAVES_AND_OVERLAY_BLEND) { num5 *= alpha * num6; } if (this.HeightOverlayBlendMode == OVERLAY_BLEND_MODE.ADD) { num2 += num5; num3 += num6; } else if (this.HeightOverlayBlendMode == OVERLAY_BLEND_MODE.MAX) { num2 = Mathf.Max(num5, num2); num3 = Mathf.Max(num6, num3); } } } catch { } } num = Mathf.Clamp01(num); if (0.5f - num < 0f) { query.result.isClipped = true; } num3 = 1f - Mathf.Clamp01(num3); query.result.height = query.result.height * num3; query.result.displacementX = query.result.displacementX * num3; query.result.displacementZ = query.result.displacementZ * num3; query.result.height = query.result.height + num2; query.result.overlayHeight = num2; }
public static void QueryWaves(WaveQuery query, int enabled, IList<InterpolatedArray2f> displacements, QueryGridScaling scaling) { if(displacements.Count != GRIDS) throw new InvalidOperationException("Query Displacements requires a displacement buffer for each of the " + GRIDS + " grids."); if(displacements[0].Channels != CHANNELS) throw new InvalidOperationException("Query Displacements requires displacement buffers have " + CHANNELS + " channels."); //Only these modes are relevant to this code. if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION) return; float x = query.posX + scaling.offset.x; float z = query.posZ + scaling.offset.z; if (enabled == 0) { return; } else if(enabled == 1 || query.mode == QUERY_MODE.DISPLACEMENT) { SampleHeightOnly(query.result.displacement, displacements, query.sampleSpectrum, x, z, scaling, scaling.tmp); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = 0.0f; query.result.displacementZ = 0.0f; query.result.iterations = 0; query.result.error = 0.0f; query.result.height = Mathf.Clamp(query.result.height, -Ocean.MAX_SPECTRUM_WAVE_HEIGHT, Ocean.MAX_SPECTRUM_WAVE_HEIGHT); } else { float lx, lz; float dx = x; float dz = z; float u = x; float v = z; float displacementX; float displacementZ; float minError2 = query.minError; if(minError2 < 0.1f) minError2 = 0.1f; minError2 = minError2*minError2; float error; int i = 0; do { u += x - dx; v += z - dz; Sample(query.result.displacement, displacements, query.sampleSpectrum, u, v, scaling, scaling.tmp); displacementX = query.result.displacement[0].x + query.result.displacement[1].x + query.result.displacement[2].x + query.result.displacement[3].x; displacementZ = query.result.displacement[0].z + query.result.displacement[1].z + query.result.displacement[2].z + query.result.displacement[3].z; dx = u + displacementX; dz = v + displacementZ; i++; lx = x-dx; lz = z-dz; error = lx*lx + lz*lz; } while (error > minError2 && i <= WaveQuery.MAX_ITERATIONS); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = displacementX; query.result.displacementZ = displacementZ; query.result.iterations = i; query.result.error = error; query.result.height = Mathf.Clamp(query.result.height, -Ocean.MAX_SPECTRUM_WAVE_HEIGHT, Ocean.MAX_SPECTRUM_WAVE_HEIGHT); } }
/// <summary> /// Query the waves at world position xz. /// </summary> public void QueryWaves(WaveQuery query) { //Clear previous result in query. query.result.Clear(); if(enabled) { if(Spectrum != null) Spectrum.QueryWaves(query); if(OverlayManager != null) OverlayManager.QueryWaves(query); } query.result.height += level; }
public static void QueryWaves(WaveQuery query, int enabled, IList <InterpolatedArray2f> displacements, QueryGridScaling scaling) { if (displacements.Count != QueryDisplacements.GRIDS) { throw new InvalidOperationException("Query Displacements requires a displacement buffer for each of the " + QueryDisplacements.GRIDS + " grids."); } if (displacements[0].Channels != QueryDisplacements.CHANNELS) { throw new InvalidOperationException("Query Displacements requires displacement buffers have " + QueryDisplacements.CHANNELS + " channels."); } if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION) { return; } float num = query.posX + scaling.offset.x; float num2 = query.posZ + scaling.offset.z; if (enabled == 0) { return; } if (enabled == 1 || query.mode == QUERY_MODE.DISPLACEMENT) { QueryDisplacements.SampleHeightOnly(query.result.displacement, displacements, query.sampleSpectrum, num, num2, scaling, scaling.tmp); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = 0f; query.result.displacementZ = 0f; query.result.iterations = 0; query.result.error = 0f; query.result.height = Mathf.Clamp(query.result.height, -40f, 40f); } else { float num3 = num; float num4 = num2; float num5 = num; float num6 = num2; float num7 = query.minError; if (num7 < 0.1f) { num7 = 0.1f; } num7 *= num7; int num8 = 0; float num9; float num10; float num13; do { num5 += num - num3; num6 += num2 - num4; QueryDisplacements.Sample(query.result.displacement, displacements, query.sampleSpectrum, num5, num6, scaling, scaling.tmp); num9 = query.result.displacement[0].x + query.result.displacement[1].x + query.result.displacement[2].x + query.result.displacement[3].x; num10 = query.result.displacement[0].z + query.result.displacement[1].z + query.result.displacement[2].z + query.result.displacement[3].z; num3 = num5 + num9; num4 = num6 + num10; num8++; float num11 = num - num3; float num12 = num2 - num4; num13 = num11 * num11 + num12 * num12; }while (num13 > num7 && num8 <= WaveQuery.MAX_ITERATIONS); query.result.height = query.result.displacement[0].y + query.result.displacement[1].y + query.result.displacement[2].y + query.result.displacement[3].y; query.result.displacementX = num9; query.result.displacementZ = num10; query.result.iterations = num8; query.result.error = num13; query.result.height = Mathf.Clamp(query.result.height, -40f, 40f); } }