예제 #1
0
        public void BuildMaterialPasses(PageDecalInfo pageInfo)
        {
            Technique t = FindPageTechnique(pageInfo.Coord);

            if (t != null)
            {
                float pageX = pageInfo.Coord.X * TerrainManager.Instance.PageSize * TerrainManager.oneMeter;
                float pageZ = pageInfo.Coord.Z * TerrainManager.Instance.PageSize * TerrainManager.oneMeter;

                int availableTexUnits = 0;
                int curTexUnit        = 0;
                int texUnitsPerPass   = 8;

                Pass p = null;

                foreach (DecalElement element in pageInfo.Decals)
                {
                    // if there are no texture units available, allocate a new pass
                    if (availableTexUnits == 0)
                    {
                        p = t.CreatePass();
                        pageInfo.Passes.Add(p);

                        p.SetSceneBlending(SceneBlendType.TransparentAlpha);
                        // TODO: Unclear what should happen here.  The new Ogre interface
                        // supports SetDepthBias(constantBias, slopeBias), but the units are
                        // different.  Ask Jeff.
                        p.DepthBias = 1;

                        curTexUnit        = 0;
                        availableTexUnits = texUnitsPerPass;
                    }

                    TextureUnitState texUnit = p.CreateTextureUnitState(element.ImageName, 0);

                    if (curTexUnit == 0)
                    {
                        texUnit.SetColorOperation(LayerBlendOperation.Replace);
                        texUnit.SetAlphaOperation(LayerBlendOperationEx.Source1, LayerBlendSource.Texture, LayerBlendSource.Current, 0, 0, 0);
                    }
                    else
                    {
                        texUnit.SetColorOperation(LayerBlendOperation.AlphaBlend);
                        texUnit.SetAlphaOperation(LayerBlendOperationEx.AddSmooth, LayerBlendSource.Texture, LayerBlendSource.Current, 0, 0, 0);
                    }
                    texUnit.TextureAddressing  = TextureAddressing.Border;
                    texUnit.TextureBorderColor = new ColorEx(0, 0, 0, 0);

                    element.UpdateTextureTransform(texUnit, pageX, pageZ);

                    // bump the counts
                    curTexUnit++;
                    availableTexUnits--;
                }
            }
        }
예제 #2
0
        public void FreeMaterialPass(PageDecalInfo pageInfo)
        {
            Technique t = FindPageTechnique(pageInfo.Coord);

            if (t != null)
            {
                // remove the passes from the material
                foreach (Pass p in pageInfo.Passes)
                {
                    t.RemovePass(p);
                }

                // clear the list of saved passes
                pageInfo.Passes.Clear();
            }
        }
예제 #3
0
        protected PageDecalInfo[,] BuildPageInfos()
        {
            PageDecalInfo[,] pageInfos = new PageDecalInfo[numPages, numPages];

            int pageRadius    = numPages >> 1;
            int pageStartX    = cameraPage.X - pageRadius;
            int pageStartZ    = cameraPage.Z - pageRadius;
            int pageEndX      = cameraPage.X + pageRadius;
            int pageEndZ      = cameraPage.Z + pageRadius;
            int pageInfoCount = 0;

            foreach (DecalElement element in elements)
            {
                int startX = Math.Max(element.MinPageCoord.X, pageStartX);
                int startZ = Math.Max(element.MinPageCoord.Z, pageStartZ);
                int endX   = Math.Min(element.MaxPageCoord.X, pageEndX);
                int endZ   = Math.Min(element.MaxPageCoord.Z, pageEndZ);

                if ((startX <= endX) && (startZ <= endZ))
                { // element overlaps the visible pages
                    for (int z = startZ; z <= endZ; z++)
                    {
                        for (int x = startX; x <= endX; x++)
                        {
                            PageDecalInfo pageInfo = pageInfos[x - pageStartX, z - pageStartZ];
                            if (pageInfo == null)
                            {
                                // this is the first decal on this page, so make a new page info object
                                pageInfo = pageInfos[x - pageStartX, z - pageStartZ] = new PageDecalInfo(new PageCoord(x, z));
                                pageInfoCount++;
                            }

                            // add the decal to this page
                            pageInfo.Decals.Add(element);
                        }
                    }
                }
            }

            if (pageInfoCount == 0)
            {
                // if there are no visible decals, then return null rather than an empty array
                pageInfos = null;
            }

            return(pageInfos);
        }
        protected PageDecalInfo[,] BuildPageInfos()
        {
            PageDecalInfo[,] pageInfos = new PageDecalInfo[numPages,numPages];

            int pageRadius = numPages >> 1;
            int pageStartX = cameraPage.X - pageRadius;
            int pageStartZ = cameraPage.Z - pageRadius;
            int pageEndX = cameraPage.X + pageRadius;
            int pageEndZ = cameraPage.Z + pageRadius;
            int pageInfoCount = 0;

            foreach (DecalElement element in elements)
            {
                int startX = Math.Max(element.MinPageCoord.X, pageStartX);
                int startZ = Math.Max(element.MinPageCoord.Z, pageStartZ);
                int endX = Math.Min(element.MaxPageCoord.X, pageEndX);
                int endZ = Math.Min(element.MaxPageCoord.Z, pageEndZ);

                if ((startX <= endX) && (startZ <= endZ))
                { // element overlaps the visible pages
                    for (int z = startZ; z <= endZ; z++)
                    {
                        for (int x = startX; x <= endX; x++)
                        {
                            PageDecalInfo pageInfo = pageInfos[x - pageStartX, z - pageStartZ];
                            if ( pageInfo == null )
                            {
                                // this is the first decal on this page, so make a new page info object
                                pageInfo = pageInfos[x - pageStartX, z - pageStartZ] = new PageDecalInfo(new PageCoord(x, z));
                                pageInfoCount++;
                            }

                            // add the decal to this page
                            pageInfo.Decals.Add(element);
                        }
                    }
                }
            }

            if (pageInfoCount == 0)
            {
                // if there are no visible decals, then return null rather than an empty array
                pageInfos = null;
            }

            return pageInfos;
        }
 public void FreePasses(PageDecalInfo[,] pageInfos)
 {
     foreach (PageDecalInfo pageInfo in pageInfos)
     {
         if (pageInfo != null)
         {
             FreeMaterialPass(pageInfo);
         }
     }
 }
        public void FreeMaterialPass(PageDecalInfo pageInfo)
        {
            Technique t = FindPageTechnique(pageInfo.Coord);

            if (t != null)
            {
                // remove the passes from the material
                foreach (Pass p in pageInfo.Passes)
                {
                    t.RemovePass(p);
                }

                // clear the list of saved passes
                pageInfo.Passes.Clear();
            }
        }
 public void BuildPasses(PageDecalInfo[,] pageInfos)
 {
     foreach (PageDecalInfo pageInfo in pageInfos)
     {
         if (pageInfo != null)
         {
             BuildMaterialPasses(pageInfo);
         }
     }
 }
        public void BuildMaterialPasses(PageDecalInfo pageInfo)
        {
            Technique t = FindPageTechnique(pageInfo.Coord);
            if (t != null)
            {

                float pageX = pageInfo.Coord.X * TerrainManager.Instance.PageSize * TerrainManager.oneMeter;
                float pageZ = pageInfo.Coord.Z * TerrainManager.Instance.PageSize * TerrainManager.oneMeter;

                int availableTexUnits = 0;
                int curTexUnit = 0;
                int texUnitsPerPass = 8;

                Pass p = null;

                foreach (DecalElement element in pageInfo.Decals)
                {
                    // if there are no texture units available, allocate a new pass
                    if (availableTexUnits == 0)
                    {
                        p = t.CreatePass();
                        pageInfo.Passes.Add(p);

                        p.SetSceneBlending(SceneBlendType.TransparentAlpha);
                        // TODO: Unclear what should happen here.  The new Ogre interface
                        // supports SetDepthBias(constantBias, slopeBias), but the units are
                        // different.  Ask Jeff.
                        p.DepthBias = 1;

                        curTexUnit = 0;
                        availableTexUnits = texUnitsPerPass;
                    }

                    TextureUnitState texUnit = p.CreateTextureUnitState(element.ImageName, 0);

                    if (curTexUnit == 0)
                    {
                        texUnit.SetColorOperation(LayerBlendOperation.Replace);
                        texUnit.SetAlphaOperation(LayerBlendOperationEx.Source1, LayerBlendSource.Texture, LayerBlendSource.Current, 0, 0, 0);
                    }
                    else
                    {
                        texUnit.SetColorOperation(LayerBlendOperation.AlphaBlend);
                        texUnit.SetAlphaOperation(LayerBlendOperationEx.AddSmooth, LayerBlendSource.Texture, LayerBlendSource.Current, 0, 0, 0);
                    }
                    texUnit.TextureAddressing = TextureAddressing.Border;
                    texUnit.TextureBorderColor = new ColorEx(0, 0, 0, 0);

                    element.UpdateTextureTransform(texUnit, pageX, pageZ);

                    // bump the counts
                    curTexUnit++;
                    availableTexUnits--;
                }
            }
        }