コード例 #1
0
ファイル: TerrainNode.cs プロジェクト: Alan-Baylis/SpaceW
        public void DrawQuad(TerrainQuad quad, List <TileSampler> samplers, Mesh mesh, MaterialPropertyBlock mpb)
        {
            if (!quad.IsVisible)
            {
                return;
            }
            if (!quad.Drawable)
            {
                return;
            }

            if (quad.IsLeaf)
            {
                for (byte i = 0; i < samplers.Count; ++i)
                {
                    // Set the unifroms needed to draw the texture for this sampler
                    samplers[i].SetTile(mpb, quad.Level, quad.Tx, quad.Ty);
                }

                DrawMesh(quad, mesh, mpb);
            }
            else
            {
                // Draw quads in a order based on distance to camera
                var done = 0;

                var order = quad.CalculateOrder(LocalCameraPosition.x, LocalCameraPosition.y, quad.Ox + quad.LengthHalf, quad.Oy + quad.LengthHalf);

                for (byte i = 0; i < 4; ++i)
                {
                    if (quad.GetChild(order[i]).Visibility == Frustum.VISIBILITY.INVISIBLE)
                    {
                        done |= (1 << order[i]);
                    }
                    else if (quad.GetChild(order[i]).Drawable)
                    {
                        DrawQuad(quad.GetChild(order[i]), samplers, mesh, mpb);

                        done |= (1 << order[i]);
                    }
                }

                if (done < 15)
                {
                    // If the a leaf quad needs to be drawn but its tiles are not ready then this will draw the next parent tile instead that is ready.
                    // Because of the current set up all tiles always have there tasks run on the frame they are generated so this section of code is never reached.

                    for (byte i = 0; i < samplers.Count; ++i)
                    {
                        // Set the unifroms needed to draw the texture for this sampler
                        samplers[i].SetTile(mpb, quad.Level, quad.Tx, quad.Ty);
                    }

                    DrawMesh(quad, mesh, mpb);
                }
            }
        }
コード例 #2
0
ファイル: TerrainNode.cs プロジェクト: zameran/SpaceW
        public void DrawQuads(TerrainQuad quad, Mesh mesh, MaterialPropertyBlock mpb, int layer)
        {
            if (!quad.IsVisible)
            {
                return;
            }
            if (!quad.Drawable)
            {
                return;
            }

            if (quad.IsLeaf)
            {
                for (var i = 0; i < SamplersSuitable.Count; ++i)
                {
                    // Set the unifroms needed to draw the texture for this sampler
                    SamplersSuitable[i].SetUniforms(mpb, quad);
                }

                DrawMesh(quad, mesh, mpb, layer);
            }
            else
            {
                quad.CalculateOrder(quad.Owner.LocalCameraPosition.x, quad.Owner.LocalCameraPosition.y, quad.Ox + quad.LengthHalf, quad.Oy + quad.LengthHalf);

                // Draw quads in a order based on distance to camera
                var done = 0;

                for (var i = 0; i < 4; ++i)
                {
                    var targetQuad = quad.GetChild(quad.Order[i]);

                    if (targetQuad.Visibility == Frustum3d.VISIBILITY.INVISIBLE)
                    {
                        done |= 1 << quad.Order[i];
                    }
                    else if (targetQuad.Drawable)
                    {
                        DrawQuads(targetQuad, mesh, mpb, layer);

                        done |= 1 << quad.Order[i];
                    }
                }

                if (done < 15)
                {
                    // If the a leaf quad needs to be drawn but its tiles are not ready, then this will draw the next parent tile instead that is ready.
                    // Because of the current set up all tiles always have there tasks run on the frame they are generated, so this section of code is never reached.
                    Debug.LogWarning(string.Format("Looks like rendering false start! {0}:{1}:{2}", quad.Level, quad.Tx, quad.Ty));

                    for (var i = 0; i < SamplersSuitable.Count; ++i)
                    {
                        // Set the unifroms needed to draw the texture for this sampler
                        SamplersSuitable[i].SetUniforms(mpb, quad);
                    }

                    DrawMesh(quad, mesh, mpb, layer);
                }
            }
        }
コード例 #3
0
ファイル: TerrainNode.cs プロジェクト: Alan-Baylis/SpaceW
        public void FindDrawableQuads(TerrainQuad quad, List <TileSampler> samplers)
        {
            quad.Drawable = false;

            if (!quad.IsVisible)
            {
                quad.Drawable = true;

                return;
            }

            if (quad.IsLeaf)
            {
                if (FindDrawableSamplers(quad, samplers))
                {
                    return;
                }
            }
            else
            {
                byte drawableCount = 0;

                for (byte i = 0; i < 4; ++i)
                {
                    FindDrawableQuads(quad.GetChild(i), samplers);

                    if (quad.GetChild(i).Drawable)
                    {
                        ++drawableCount;
                    }
                }

                if (drawableCount < 4)
                {
                    if (FindDrawableSamplers(quad, samplers))
                    {
                        return;
                    }
                }
            }

            quad.Drawable = true;
        }
コード例 #4
0
ファイル: TerrainNode.cs プロジェクト: zameran/SpaceW
        public void FindDrawableQuads(TerrainQuad quad)
        {
            quad.Drawable = false;

            if (!quad.IsVisible)
            {
                quad.Drawable = true;

                return;
            }

            if (quad.IsLeaf)
            {
                if (FindDrawableSamplers(quad))
                {
                    return;
                }
            }
            else
            {
                byte drawableCount = 0;

                for (var i = 0; i < 4; ++i)
                {
                    var targetQuad = quad.GetChild(i);

                    FindDrawableQuads(targetQuad);

                    if (targetQuad.Drawable)
                    {
                        ++drawableCount;
                    }
                }

                if (drawableCount < 4)
                {
                    if (FindDrawableSamplers(quad))
                    {
                        return;
                    }
                }
            }

            quad.Drawable = true;
        }