Exemplo n.º 1
0
        /// <summary>
        /// Generate the benders lists, for the vertex bending shaders.
        /// </summary>
        public static void UpdateBendersShaderArray()
        {
            if (container == null)
            {
                container = new GrassBendersContainer();
            }

            container.ResetLists();
            // we are going to cull benders only if they are too many, otherwise it's probably just better to just pass them all to the shader
            if (benders.Count > GrassSettings.SettingsPreset.MaxActiveBenders)
            {
                Culling();
                for (int i = 0; i < benders.Count; i++)
                {
                    if (benders[i].visible)
                    {
                        if (benders[i].UniformScale > .001f)
                        {
                            container.AddBender(benders[i].benderData);
                            if (container.currentNumber >= GrassSettings.SettingsPreset.MaxActiveBenders)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < benders.Count; i++)
                {
                    if (benders[i].UniformScale > .001f)
                    {
                        container.AddBender(benders[i].benderData);
                    }
                }
            }

            container.GlobalMaterialUpdate();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate the arrays containing all the data for the permanent shaders.
        /// NOTE: while the vertex bending is global, the permanent is relative to the volume, so it will be calculated here, and not in the GrassBenderManager.
        /// </summary>
        public void GenerateBendersList()
        {
            if (permanentContainer == null)
            {
                permanentContainer = new GrassBendersContainer();
            }
            permanentContainer.ResetLists();
            Bounds      bound = new Bounds(transform.position + transform.lossyScale / 2f, transform.lossyScale);
            GrassBender current;

            for (int i = 0; i < GrassBendersManager.benders.Count; i++)
            {
                current = GrassBendersManager.benders[i];
                if (current.PermanentBending)
                {
                    if (bound.SqrDistance(current.boundingSphere.position) < current.boundingSphere.radius * current.boundingSphere.radius)
                    {
                        permanentContainer.AddBender(current.benderData);
                    }
                }
            }
        }