public RendererTextureStage(MapTextureStageView maptexturestage, int maptexturestagepass, bool UsingMultipass, int mapwidth, int mapheight) { this.maptexturestage = maptexturestage; this.maptexturestagepass = maptexturestagepass; this.mapwidth = mapwidth; this.mapheight = mapheight; this.UsingMultipass = UsingMultipass; }
void terrain_BlendmapInPlaceEdited(MapTextureStageModel maptexturestagemodel, int xleft, int ytop, int xright, int ybottom) { MapTextureStageView maptexturestageview = terrainview.mapviewbymapmodel[maptexturestagemodel]; 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 (maptexturestagemodel.Operation == MapTextureStageModel.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 (maptexturestagemodel.Affects(mapx, mapy, width, height)) { texturestageused = true; } //} } } chunkusestexturestage[maptexturestagemodel][chunkx, chunky] = texturestageused; // if (chunkusestexturestage[texturestageindex][chunkx, chunky]) //{ // Console.WriteLine("texturestage used: " + texturestageindex + " " + chunkx + " " + chunky); //} } else { chunkusestexturestage[maptexturestagemodel][chunkx, chunky] = true; } //} } } }
// determine which chunks are used by each texture stage // only affects blend really void CacheChunkTextureStageUsage() { LogFile.WriteLine("Cachchunktexturestageusage"); int numxchunks = width / chunksize; int numychunks = height / chunksize; chunkusestexturestage = new Dictionary <MapTextureStageModel, bool[, ]>(); foreach (MapTextureStageModel maptexturestage in maptexturestagemodels) { 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 < maptexturestagemodels.Count; texturestageindex++) { MapTextureStageModel texturestagemodel = maptexturestagemodels[texturestageindex]; //MapTextureStageView texturestageview = terrainview.mapviewbymapmodel[texturestagemodel]; //Console.WriteLine("texturestage " + texturestageindex + " " + texturestage.Operation ); if (texturestagemodel.Operation == MapTextureStageModel.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 (texturestagemodel.Affects(mapx, mapy, width, height)) { texturestageused = true; } } } chunkusestexturestage[texturestagemodel][chunkx, chunky] = texturestageused; // if (chunkusestexturestage[texturestageindex][chunkx, chunky]) //{ // Console.WriteLine("texturestage used: " + texturestageindex + " " + chunkx + " " + chunky); //} } else if (texturestagemodel.Operation == MapTextureStageModel.OperationType.Nop) { chunkusestexturestage[texturestagemodel][chunkx, chunky] = false; } else { //Console.WriteLine("RenderableHeightMap,, cache chunk usage, true"); chunkusestexturestage[texturestagemodel][chunkx, chunky] = true; } } } } maxtexels = RendererSdl.GetInstance().MaxTexelUnits; int totaltexturestagesneeded = 0; foreach (MapTextureStageModel maptexturestagemodel in maptexturestagemodels) { totaltexturestagesneeded += terrainview.mapviewbymapmodel[maptexturestagemodel].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 LogFile.WriteLine("Adding rendererpasses"); if (multipass) { for (int i = 0; i < maptexturestagemodels.Count; i++) { MapTextureStageModel maptexturestagemodel = maptexturestagemodels[i]; MapTextureStageView maptexturestage = terrainview.mapviewbymapmodel[maptexturestagemodel]; 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); LogFile.WriteLine("Adding rendererpass: " + rendererpass); } } } }