- Home /
Optimizing Terrain painting during runtime.
Hey sorry for the topic that has been asked to death already but I think I have a bit of a new take on it. and if the formatting of the question is odd sorry I don't ask questions here alot...
i currently have a script that paints the terrain in a sphere, naturally because splat mapping an area on a terrain takes an insane amount of power(i have no clue why)
and i've already optimized it so its usable during runtime but i want to ask if there is a way to increase the speed of the painting.
IEnumerator Loop()
{
for (int r = 0; r < radius; r++)
{
//N is the amount of times it will the points of the terrain
if(r == 0)
{
N = 1;
}
if(r == 1)
{
N = 8;
}
if (r == 2)
{
N = 16;
}
if (r == 3)
{
N = 32;
}
if (r == 4)
{
N = 64;
}
if (r == 5)
{
N = 64;
}
if (r == 6)
{
N = 158;
}
if (r == 7)
{
N = 228;
}
if (r == 8)
{
N = 228;
}
if (r == 9)
{
N = 360;
}
if (r == 10)
{
N = 360;
}
if(r > 10)
{
float f = r * Mathf.PI * 10;
N = (int)f;
}
for (int i = 0; i < N; i++)
{
if (r < 5)//if r is less then 5 just do it at once since it wont be enough to make your entire game crawl
{
float angle = i;
Vector2 pos = new Vector2(Mathf.Sin(angle) * r, Mathf.Cos(angle) * r);
changeTexture((int)positionx + (int)pos.x, (int)positiony - (int)pos.y, sellectedtexture);
}
else
{
if (i % 50 == 0)//everytime that i is dividable by 50 give the game a short break
{
yield return new WaitForSeconds(0.0000000001f); //short break
float angle = i;
Vector2 pos = new Vector2(Mathf.Sin(angle) * r, Mathf.Cos(angle) * r);
changeTexture((int)positionx + (int)pos.x, (int)positiony - (int)pos.y, sellectedtexture);
}
else
{
float angle = i;
Vector2 pos = new Vector2(Mathf.Sin(angle) * r, Mathf.Cos(angle) * r);
changeTexture((int)positionx + (int)pos.x, (int)positiony - (int)pos.y, sellectedtexture);
}
}
}
}
}
Sorry if it is a bit of a mess but to explain what is going on here, because painting an area all at the same time makes your game crawl I put it in a coroutine and let the game have a short break while running the forloops, causing a significant increase in fps.
Currently you see the circle getting textured and have to wait before its finished texturing. however the current painting of the terrain is a bit too slow, even though the radius is under normal circumstances not above 10 it still takes 2 to 3 seconds for the entire circle gets painted.
At the moment its just triggered once per mouse click(otherwise the game chrashes)
I would like to either get it down to 1 second so it'd be usable by the player, or could there be a way to hide the spot on the terrain until its finished painting, or make it seem its already there and then remove the fake one after the real one is finished painting? if anyone could help me it would be greatly appreciated.
Your answer
Follow this Question
Related Questions
splatmap textures not applying in build 0 Answers
Terrain texture thumbnail is invisible 1 Answer
Terrain Splatmap Optimization - 4 Texture still true? 1 Answer
How can I export the terrain splatmap? 0 Answers
Terrain texture painting 0 Answers