Example #1
0
        /// <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;
        }
Example #2
0
        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;

            List <QueryableOverlayResult> .Enumerator enumerator = this.m_containingOverlays.GetEnumerator();
            while (enumerator.MoveNext())
            {
                QueryableOverlayResult current = enumerator.Current;
                try
                {
                    OverlayClipTexture   clipTex   = current.overlay.ClipTex;
                    OverlayHeightTexture heightTex = current.overlay.HeightTex;
                    if (clipTex.IsDrawable && clipTex.tex is Texture2D)
                    {
                        float a = (clipTex.tex as Texture2D).GetPixelBilinear(current.u, current.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(current.u, current.v).a;
                        }
                        if (heightTex.mask != null && heightTex.mask is Texture2D)
                        {
                            num6 = (heightTex.mask as Texture2D).GetPixelBilinear(current.u, current.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;
        }