Example #1
0
        public override void OnRender(RenderView view)
        {
            base.OnRender(view);

            int zStart = camZ - CloudBlocksH;
            int zEnd = camZ + CloudBlocksH;
            int yStart = camY - CloudBlocksV;
            int yEnd = camY + CloudBlocksV;
            int xStart = camX - CloudBlocksH;
            int xEnd = camX + CloudBlocksH;
            Vector3 camPos = view.GetPosition();
            BoundingFrustum camFrustum = view.GetFrustum();
            for (int z = zStart; z <= zEnd; z++)
            {
                long zOff = sliceArea * (long)z;
                for (int y = yStart; y <= yEnd; y++)
                {
                    long yOff = width * (long)y;

                    for (int x = xStart; x <= xEnd; x++)
                    {
                        long idx = (long)x + yOff + zOff;
                        if (clusterCollection.ContainsKey(idx))
                        {
                            ForestManager currCluster = clusterCollection[idx];
                            clusterCollection[idx].OnRender(view);
                        }
                    }
                }
            }
        }
Example #2
0
        void RecursivelyRender(KDNode<ForestElement> node, RenderView view)
        {
            if (node == null || view.GetFrustum().Contains(node.bounds) == ContainmentType.Disjoint)
                return;

            if (node.element != null && (view.GetFrustum().Contains(node.element.Bounds) != ContainmentType.Disjoint))
            {
                if (view.GetRenderType() == RenderViewType.MAIN && useImposters)
                {
                    float distToCamera = Vector3.DistanceSquared(node.element.Transform.GetPosition(), view.GetPosition());
                    node.element.RenderImposters = (distToCamera >= GFXShaderConstants.IMPOSTERDISTANCESQUARED) ? ImposterState.Enabled : ImposterState.Disabled;
                    if (node.element.RenderImposters == ImposterState.Enabled && distToCamera <= GFXShaderConstants.IMPOSTER_DISTANCE_FALLOFF)
                    {
                        node.element.RenderImposters = ImposterState.Both;
                    }
                    if (distToCamera > GFXShaderConstants.GRASS_FADE_SQUARED)
                        node.element.RenderImposters = ImposterState.None;
                }

                    if (useImposters)
                    {
                        if (node.element.RenderImposters != ImposterState.None)
                        {
                            if (node.element.RenderImposters == ImposterState.Enabled || node.element.RenderImposters == ImposterState.Both)
                                node.element.Mesh.RenderImposters(node.element.Transform.GetTransform(), view, false);
                            if (node.element.RenderImposters == ImposterState.Disabled || node.element.RenderImposters == ImposterState.Both)
                                node.element.Mesh.Render(node.element.Transform.GetTransform(), view, false);
                        }
                    }
                    else
                        node.element.Mesh.Render(node.element.Transform.GetTransform(), view, false);

                    nodesRendered++;
            }
            RecursivelyRender(node.leftChild, view);
            RecursivelyRender(node.rightChild, view);
        }