示例#1
0
        protected override void CreateRenderItems()
        {
            base.CreateRenderItems();
            if (ApplicationSettings.UseFallbackRendering)
            {
                return;
            }

            Material[] mats = materials;
            if (mats.HasElements())
            {
                mats = mats.Where(m => m != null).ToArray();
            }
            if (filter.meshToRender != null && !filter.isDynamicMesh && mats.HasElements())
            {
                bounds = filter.meshToRender.bounds;

                // TODO: The thought is that this can actually be done at compile time so the initialization will occur at runtime
                renderItems = new RenderItem[mats.Length];
                for (int i = 0; i < mats.Length; i++)
                {
                    RenderItem item = RenderItem.Create(mats[i], filter.meshToRender, i, transform);
                    item.Initialize(Camera.Device);
                    renderItems[i] = item;
                }
            }
            Debug.LogFormat("Created {0} render items on {1}", (renderItems.HasElements()) ? renderItems.Count(r => r != null).ToString() : "no", this);
            createRenderItems = false;
        }
示例#2
0
        public override void Initialize(AssetHelper assets)
        {
            if (isPartOfStaticBatch)
            {
                return;
            }

            filter = (MeshFilter)GetComponent(typeof(MeshFilter));
            Material[] mats = materials;
            if (mats.HasElements())
            {
                mats = mats.Where(m => m != null).ToArray();
            }
            if (filter.meshToRender != null && mats.HasElements())
            {
                bounds = filter.meshToRender.bounds;

                if (!ApplicationSettings.UseFallbackRendering)
                {
                    // TODO: The thought is that this can actually be done at compile time so the initialization will occur at runtime
                    renderItems = new RenderItem[mats.Length];
                    for (int i = 0; i < mats.Length; i++)
                    {
                        RenderItem item = RenderItem.Create(mats[i], filter.meshToRender, i, transform);
                        item.Initialize(Camera.Device);
                        renderItems[i] = item;
                    }
                }
            }
        }
示例#3
0
        internal static RenderItem Create(Material material, Mesh mesh, int subMeshIndex, Transform t)
        {
            RenderItem item;

            string id = material.GetInstanceID() + ":" + mesh.GetInstanceID();

            if (RenderItemPool.ContainsKey(id))
            {
                item = RenderItemPool[id];
                hitPool++;
            }
            else
            {
                missPool++;
                // TODO: The selection needs to be configurable from outside
                if (material.shader.supportsLights && mesh._normals.HasElements())
                {
                    item = new RenderItem <VertexPositionNormalTexture>(material, AddVertexPositionNormalTexture);
                }
                else
                {
                    if (material.shader.supportsVertexColor && mesh.colors.HasElements())
                    {
                        item = new RenderItem <VertexPositionColorTexture>(material, AddVertexPositionColorTexture);
                        item.UseVertexColor = true;
                    }
                    else
                    {
                        item = new RenderItem <VertexPositionTexture>(material, AddVertexPositionTexture);
                    }
                }
                item.Priority = material.renderQueue;
                item.AddMesh(mesh, t.world, subMeshIndex);
                if (material.IsTransparent())
                {
                    item.GetTransformPriority = GetTransparentPriority;
                }
                else
                {
                    item.GetTransformPriority = GetOpaquePriority;
                }
                RenderItemPool[id] = item;
            }
            item.AddTransform(t);
            return(item);
        }
示例#4
0
文件: Camera.cs 项目: mikecrews/FFWD
        internal static void Culling()
        {
            int camCount = _allCameras.Count;

            // Go through the moved renderers and update culling
            Renderer updated = RenderQueue.GetUpdatedRenderer();

            while (updated != null)
            {
                for (int i = 0; i < camCount; i++)
                {
                    if (!_allCameras[i].doFullCullingScan)
                    {
                        // TODO: We should have a method of updating only the cull info of the moved item and not the entrire camera queue
                        updated.UpdateCullingInfo(_allCameras[i]);
                    }
                }
                updated = RenderQueue.GetUpdatedRenderer();
            }

            for (int i = 0; i < camCount; i++)
            {
                Camera cam = _allCameras[i];
                if (cam.doFullCullingScan)
                {
                    cam.doFullCullingScan = false;
                    cam.CulledRenderQueue.Clear();

                    // Initialize the culling queue for this camera
                    // TODO: Here we should use something like an octtree to make full scanning faster
                    int rqCount = RenderQueue.Count;
                    for (int j = 0; j < rqCount; j++)
                    {
                        RenderItem item = RenderQueue[j];
                        if (item.UpdateCullingInfo(cam))
                        {
                            cam.CulledRenderQueue.Add(item);
                        }
                    }
                }
            }
        }
示例#5
0
        internal static RenderItem Create(Material material, Mesh mesh, int subMeshIndex, Transform t)
        {
            RenderItem item;

            // TODO: Select actural render item based on what material we are using
            item = new RenderItem<VertexPositionNormalTexture>(material, AddVertexPositionNormalTexture);

            item.Transform = t;
            item.Priority = material.shader.renderQueue;
            item.AddMesh(mesh, t.world, subMeshIndex);
            item.name = String.Format("{0} - {1} on {2} rendering {3}", item.Priority, item.Material.name, t.ToString(), mesh.name);

            return item;
        }