Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="group"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static ImpostorTexture GetTexture(ImpostorPage group, Entity entity)
        {
            //Search for an existing impostor texture for the given entity
            string          entityKey = ImpostorBatch.GenerateEntityKey(entity);
            ImpostorTexture texture   = null;

            if (!mSelfList.TryGetValue(entityKey, out texture))
            {
                if (group != null)
                {
                    texture = new ImpostorTexture(group, entity);
                }
            }
            return(texture);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="group"></param>
        /// <param name="entity"></param>
        protected ImpostorTexture(ImpostorPage group, Entity entity)
        {
            //Store scene manager and entity
            mSceneMgr = group.SceneManager;
            mEntity   = entity;

            //Add self to list of ImpostorTexture's
            mEntityKey = ImpostorBatch.GenerateEntityKey(entity);
            mSelfList.Add(mEntityKey, this);

            //Calculate the entity's bounding box and it's diameter
            mBoundingBox = entity.BoundingBox;

            //Note - this radius calculation assumes the object is somewhat rounded (like trees/rocks/etc.)
            float tmp = 0;

            mEntityRadius = mBoundingBox.Maximum.x - mBoundingBox.Center.x;
            tmp           = mBoundingBox.Maximum.y - mBoundingBox.Center.y;
            if (tmp > mEntityRadius)
            {
                mEntityRadius = tmp;
            }
            tmp = mBoundingBox.Maximum.z - mBoundingBox.Center.z;
            if (tmp > mEntityRadius)
            {
                mEntityRadius = tmp;
            }

            mEntityDiameter = 2.0f * mEntityRadius;
            mEntityCenter   = mBoundingBox.Center;

            //Render impostor textures
            RenderTextures(false);
            //Set up materials
            for (int o = 0; o < ImpostorYawAngles; o++)
            {
                for (int i = 0; i < ImpostorPitchAngles; i++)
                {
                    mMaterial[i, o] = (Material)MaterialManager.Instance.Create(GetUniqueID("ImpostorMaterial"), "Impostors");

                    Material m = mMaterial[i, o];
                    Pass     p = m.GetTechnique(0).GetPass(0);

                    TextureUnitState t = p.CreateTextureUnitState(mTexture.Name);
                    t.TextureScrollU = (float)(o / ImpostorYawAngles);
                    t.TextureScrollV = (float)(i / ImpostorPitchAngles);

                    p.LightingEnabled = false;
                    m.ReceiveShadows  = false;

                    if (group.BlendMode == ImpostorBlendMode.AlphaReject)
                    {
                        p.AlphaRejectFunction = CompareFunction.GreaterEqual;
                        p.AlphaRejectValue    = 128;
                    }
                    else if (group.BlendMode == ImpostorBlendMode.AlphaBlend)
                    {
                        p.SetSceneBlending(SceneBlendFactor.SourceAlpha, SceneBlendFactor.OneMinusSourceAlpha);
                    }
                }
            }
        }