Exemple #1
0
        void terrain_BlendmapInPlaceEdited(MapTextureStage maptexturestage, int xleft, int ytop, int xright, int ybottom)
        {
            for (int chunkx = xleft / chunksize; chunkx <= xright / chunksize && chunkx < width / chunksize;
                 chunkx++)
            {
                for (int chunky = ytop / chunksize; chunky <= ybottom / chunksize && chunky < height / chunksize;
                     chunky++)
                {
                    //    Console.WriteLine("chunk " + chunkx + " " + chunky);
                    //for (int texturestageindex = 0; texturestageindex < maptexturestages.GetLength(0); texturestageindex++)
                    //{
//                        maptexturestage = maptexturestages[texturestageindex];
                    if (maptexturestage.Operation == MapTextureStage.OperationType.Blend)
                    {
                        bool texturestageused = false;
                        // go through each point in chunk and check if texturestage is used
                        for (int mapx = chunkx * chunksize; mapx < (chunkx + 1) * chunksize && !texturestageused;
                             mapx++)
                        {
                            for (int mapy = chunky * chunksize; mapy < (chunky + 1) * chunksize && !texturestageused;
                                 mapy++)
                            {
                                //if (mapx < width && mapy < height)
                                //{
                                if (maptexturestage.Affects(mapx, mapy, width, height))
                                {
                                    texturestageused = true;
                                }
                                //}
                            }
                        }
                        chunkusestexturestage[maptexturestage][chunkx, chunky] = texturestageused;
                        //  if (chunkusestexturestage[texturestageindex][chunkx, chunky])
                        //{
                        //  Console.WriteLine("texturestage used: " + texturestageindex + " " + chunkx + " " + chunky);
                        //}
                    }
                    else
                    {
                        chunkusestexturestage[maptexturestage][chunkx, chunky] = true;
                    }
                    //}
                }
            }
        }
Exemple #2
0
        // determine which chunks are used by each texture stage
        // only affects blend really
        void CacheChunkTextureStageUsage()
        {
            int numxchunks = width / chunksize;
            int numychunks = height / chunksize;

            chunkusestexturestage = new Dictionary <MapTextureStage, bool[, ]>();
            foreach (MapTextureStage maptexturestage in maptexturestages)
            {
                chunkusestexturestage.Add(maptexturestage, new bool[numxchunks, numychunks]);
            }
            for (int chunkx = 0; chunkx < numxchunks; chunkx++)
            {
                for (int chunky = 0; chunky < numychunks; chunky++)
                {
                    //    Console.WriteLine("chunk " + chunkx + " " + chunky);
                    for (int texturestageindex = 0; texturestageindex < maptexturestages.Count; texturestageindex++)
                    {
                        MapTextureStage texturestage = maptexturestages[texturestageindex];
                        //Console.WriteLine("texturestage " + texturestageindex + " " + texturestage.Operation );
                        if (texturestage.Operation == MapTextureStage.OperationType.Blend)
                        {
                            bool texturestageused = false;
                            // go through each point in chunk and check if texturestage is used
                            for (int mapx = chunkx * chunksize; mapx < (chunkx + 1) * chunksize && !texturestageused;
                                 mapx++)
                            {
                                for (int mapy = chunky * chunksize; mapy < (chunky + 1) * chunksize && !texturestageused;
                                     mapy++)
                                {
                                    if (texturestage.Affects(mapx, mapy, width, height))
                                    {
                                        texturestageused = true;
                                    }
                                }
                            }
                            chunkusestexturestage[texturestage][chunkx, chunky] = texturestageused;
                            //  if (chunkusestexturestage[texturestageindex][chunkx, chunky])
                            //{
                            //  Console.WriteLine("texturestage used: " + texturestageindex + " " + chunkx + " " + chunky);
                            //}
                        }
                        else if (texturestage.Operation == MapTextureStage.OperationType.Nop)
                        {
                            chunkusestexturestage[texturestage][chunkx, chunky] = false;
                        }
                        else
                        {
                            //Console.WriteLine("RenderableHeightMap,, cache chunk usage, true");
                            chunkusestexturestage[texturestage][chunkx, chunky] = true;
                        }
                    }
                }
            }
            maxtexels = RendererSdl.GetInstance().MaxTexelUnits;

            int totaltexturestagesneeded = 0;

            foreach (MapTextureStage maptexturestage in maptexturestages)
            {
                totaltexturestagesneeded += maptexturestage.NumTextureStagesRequired;
            }

            multipass = false;
            if (totaltexturestagesneeded > maxtexels)
            {
                multipass = true;
            }
            rendererpasses = new List <RendererPass>();
            //maxtexels = 2;
            //int currenttexel = 0;

            multipass = true; // force multipass for now for simplicity
            if (multipass)
            {
                for (int i = 0; i < maptexturestages.Count; i++)
                {
                    MapTextureStage maptexturestage          = maptexturestages[i];
                    int             numtexturestagesrequired = maptexturestage.NumTextureStagesRequired;
                    if (numtexturestagesrequired > 0) // exclude Nops
                    {
                        RendererPass rendererpass = new RendererPass(maxtexels);
                        for (int j = 0; j < maptexturestage.NumTextureStagesRequired; j++)
                        {
                            rendererpass.AddStage(new RendererTextureStage(maptexturestage, j, true, width, height));
                        }
                        rendererpasses.Add(rendererpass);
                    }
                }
            }
        }