Example #1
0
        public override void OnRender(RenderView view)
        {
            BoundingFrustum frustum = view.GetFrustum();
            if (frustum.Contains(boundingBox) != ContainmentType.Disjoint)
            {
                int barkNum = varyTreeNum / 2;

                view.AddElement(treeMaterials[8 + barkNum], Voxels[0]);
                view.AddElement(treeMaterials[varyTreeNum], Voxels[1]);
            }
            base.OnRender(view);
        }
Example #2
0
 public override void OnRender(RenderView view)
 {
     List<Matrix>[] transforms = new List<Matrix>[grassHighDetail.Length];
     BoundingFrustum frustum  = view.GetFrustum();
     for (int i = 0; i < grassTransforms.Keys.Count; i++)
     {
         int key = grassTransforms.Keys[i];
         //if (frustum.Contains(grassTransforms[key].Bounds) != ContainmentType.Disjoint)
         {
             int index = grassTransforms[key].GrassGeometryIndex;
             if(transforms[index] == null)
                 transforms[index] = new List<Matrix>();
             transforms[index].Add(grassTransforms[key].Transform);
         }
     }
     for (int i = 0; i < grassHighDetail.Length; i++)
     {
         if (transforms[i] != null)
         {
             grassHighDetail[i].Transform = transforms[i].ToArray();
             view.AddElement(grassMaterial, grassHighDetail[i]);
         }
     }
     base.OnRender(view);
 }
Example #3
0
 public override void OnRender(RenderView view)
 {
     BoundingFrustum frustum = view.GetFrustum();
     if (frustum.Contains(bounds) != ContainmentType.Disjoint)
     {
         view.AddElement(gateMaterial, gateGeometry.renderElement);
     }
     base.OnRender(view);
 }
Example #4
0
 public override void OnRender(RenderView view)
 {
     BoundingFrustum frustm = view.GetFrustum();
     for (int i = 0; i < Voxels.Count; i++)
     {
         if(Voxels.Values[i].CanRender)//if (frustm.Contains(VoxelBounds.Values[i]) != ContainmentType.Disjoint && Voxels.Values[i].CanRender)
         {
             view.AddElement(terrainMaterial, Voxels.Values[i].renderElement);
         }
     }
     base.OnRender(view);
 }
 public void OnRender(RenderView renderView)
 {
     BoundingFrustum frustum = renderView.GetFrustum();
     for (int j = 0; j < patches.Count; j++)
     {
         if (patches.Values[j].CanRender && frustum.Contains(patches.Values[j].Bounds) != ContainmentType.Disjoint)
         {
             for (int i = 0; i < patches.Values[j].Elements.Length; i++)
                 renderView.AddElement(patches.Values[j].Materials[i], patches.Values[j].Elements[i]);
         }
     }
 }
Example #6
0
        public override void OnRender(RenderView view)
        {
            BoundingFrustum frustum = view.GetFrustum();
            view.AddElement(terrainQuadMaterial, giantQuadElement);
            RecursivelyRender(voxelKDTree.GetRoot(), view);
            /*
            if (view.GetRenderType() == RenderViewType.MAIN)
            {
                RecursivelyRenderDebug(voxelKDTree.GetRoot(), view, 0, false);
                GUIElementManager guiElem = GFX.Inst.GetGUI();
                guiElem.AddElement(new GUITextElement(new Vector2(-0.85f, 0.95f), "Depth: " + maxDepth));
            }

            for (int i = 0; i < Voxels.Length; i++)
            {
                if (Voxels[i].CanRender && frustum.Contains(VoxelBounds[i]) != ContainmentType.Disjoint)
                {
                    view.AddElement(terrainMaterial, Voxels[i].renderElement);
                }
            }
            */
            base.OnRender(view);
        }
Example #7
0
        void RecursivelyRender(KDNode<VoxelElement> node, RenderView view)
        {
            if (node == null || (view.GetFrustum().Contains(node.bounds) == ContainmentType.Disjoint))// && node.bounds.Contains(view.GetPosition()) == ContainmentType.Disjoint))
                return;

            if (node.element != null && (view.GetFrustum().Contains(node.element.bounds) != ContainmentType.Disjoint))
            {
                view.AddElement(terrainMaterial, node.element.geometry.renderElement);
            }
            RecursivelyRender(node.leftChild, view);
            RecursivelyRender(node.rightChild, view);
        }
Example #8
0
        public void RenderPostSceneQuery(RenderView view)
        {
            if (!useInstancing)
                return;

            addedToView = false;
            if (transforms.Count > 0)
            {
                Matrix[] tempTransforms = transforms.ToArray();
                for (int i = 0; i < parts.Length; i++)
                {
                    RenderElement elem = parts[i].renderElementInstanced;
                    elem.Transform = tempTransforms;
                    view.AddElement(parts[i].material, elem);
                }
                tempTransforms = null;
                transforms.Clear();
            }
            if (imposterGeometry != null)
            {
                RenderElement elem = imposterGeometry.Element;
                elem.Transform = imposterGeometry.transforms.ToArray();
                view.AddElement(imposterGeometry.ImposterMaterial, elem);
                imposterGeometry.transforms.Clear();
            }
            /*
            if (instanceCount > 0)
            {
                FinalizeInstanceTexture(ref instanceTemp, ref instanceTexture);
                for (int i = 0; i < parts.Length; i++)
                {
                    for(int j = 0; j < instanceTexture.Length; j++)
                        parts[i].material.SetVertexTexture(j, instanceTexture[j]);
                    parts[i].renderElementInstanced.InstanceCount = instanceCount;
                    view.AddElement(parts[i].material, parts[i].renderElementInstanced);
                }
                instanceCount = 0;
            }
            if (imposterGeometry != null)
            {
                if (imposterInstanceCount > 0)
                {
                    FinalizeInstanceTexture(ref imposterInstanceTemp, ref imposterInstanceTexture);
                    imposterGeometry.Element.InstanceCount = imposterInstanceCount;
                    for (int j = 0; j < instanceTexture.Length; j++)
                        imposterGeometry.ImposterMaterial.SetVertexTexture(j, imposterInstanceTexture[j]);
                    view.AddElement(imposterGeometry.ImposterMaterial, imposterGeometry.Element);
                    imposterInstanceCount = 0;
                }
            }
            */
        }
Example #9
0
        public void RenderNoLOD(Matrix transform, RenderView view)
        {
            BoundingFrustum frustum = new BoundingFrustum(transform * view.GetViewProjection());

            for (int i = 0; i < parts.Length; i++)
            {
                if (frustum.Contains(parts[i].bounds) != ContainmentType.Disjoint)
                {
                    RenderElement element = parts[i].renderElement;
                    element.Transform = new Matrix[1] { transform };
                    view.AddElement(parts[i].material, element);
                }
            }
        }
Example #10
0
        public void RenderImposters(Matrix transform, RenderView view, bool performCulling)
        {
            if (useInstancing && !addedToView)
            {
                view.AddMeshToRender(this);
                addedToView = true;
            }

            if (performCulling)
            {
                BoundingFrustum frustum = view.GetFrustum();
                Matrix oldMat = frustum.Matrix;
                frustum.Matrix = transform * view.GetViewProjection();
                if (imposterGeometry != null && frustum.Contains(meshBounds) != ContainmentType.Disjoint)
                {
                    Matrix tempTransform = imposterGeometry.Scale * transform;
                    if (useInstancing)
                    {
                        imposterGeometry.transforms.Add(tempTransform);
                        //InjectTransform(ref tempTransform, ref imposterInstanceTemp, ref imposterInstanceCount, ref imposterInstanceTexture);
                    }
                    else
                    {
                        imposterGeometry.Element.Transform = new Matrix[1] {tempTransform};
                        view.AddElement(imposterGeometry.ImposterMaterial, imposterGeometry.Element);
                    }
                }
                frustum.Matrix = oldMat;
            }
            else if (imposterGeometry != null)
            {
                Matrix tempTransform = imposterGeometry.Scale * transform;
                if (useInstancing)
                {
                    imposterGeometry.transforms.Add(tempTransform);
                    //InjectTransform(ref transform, ref imposterInstanceTemp, ref imposterInstanceCount, ref imposterInstanceTexture);
                }
                else
                {
                    imposterGeometry.Element.Transform = new Matrix[1] {tempTransform};
                    view.AddElement(imposterGeometry.ImposterMaterial, imposterGeometry.Element);
                }
            }
        }
Example #11
0
 public void Render(Matrix transform, VertexBuffer animBuffer, RenderView view, bool performCulling)
 {
     if (performCulling)
     {
         BoundingFrustum frustum = view.GetFrustum();
         Matrix oldMat = frustum.Matrix;
         frustum.Matrix = transform * view.GetViewProjection();
         for (int i = 0; i < parts.Length; i++)
         {
             if (frustum.Contains(parts[i].bounds) != ContainmentType.Disjoint)
             {
                 RenderElement element = parts[i].renderElement;
                 element.VertexBuffer = animBuffer;
                 element.Transform = new Matrix[1] { transform };
                 element.IsAnimated = true;
                 view.AddElement(parts[i].material, element);
             }
         }
         frustum.Matrix = oldMat;
     }
     else
     {
         for (int i = 0; i < parts.Length; i++)
         {
             RenderElement element = parts[i].renderElement;
             element.VertexBuffer = animBuffer;
             element.Transform = new Matrix[1] { transform };
             element.IsAnimated = true;
             view.AddElement(parts[i].material, element);
         }
     }
 }
Example #12
0
 public void Render(Matrix[] animTransforms, RenderView view, bool performCulling)
 {
     for (int i = 0; i < parts.Length; i++)
     {
         RenderElement element = parts[i].renderElement;
         element.Transform = animTransforms;
         element.IsAnimated = true;
         view.AddElement(parts[i].material, element);
     }
 }
Example #13
0
        public void Render(Matrix transform, RenderView view, bool performCulling)
        {
            if (useInstancing && !addedToView)
            {
                view.AddMeshToRender(this);
                addedToView = true;
            }

            if (performCulling)
            {
                BoundingFrustum frustum = view.GetFrustum();
                Matrix oldMat = frustum.Matrix;
                frustum.Matrix = transform * view.GetViewProjection();
                if (frustum.Contains(meshBounds) != ContainmentType.Disjoint)
                {
                    if (useInstancing)
                    {
                        transforms.Add(transform);
                        //InjectTransform(ref transform, ref instanceTemp, ref instanceCount, ref instanceTexture);
                    }
                    else
                    {
                        for (int i = 0; i < parts.Length; i++)
                        {
                            if (frustum.Contains(parts[i].bounds) != ContainmentType.Disjoint)
                            {
                                parts[i].renderElement.Transform = new Matrix[1] {transform};
                                view.AddElement(parts[i].material, parts[i].renderElement);
                            }
                        }
                    }

                }
                frustum.Matrix = oldMat;
            }
            else
            {
                if (useInstancing)
                {
                    transforms.Add(transform);
                    //InjectTransform(ref transform, ref instanceTemp, ref instanceCount, ref instanceTexture);
                }
                else
                {
                    for (int i = 0; i < parts.Length; i++)
                    {
                        parts[i].renderElement.Transform = new Matrix[1] { transform };
                        view.AddElement(parts[i].material, parts[i].renderElement);
                    }
                }
            }
        }