Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kampiria · Mar 08, 2020 at 05:21 PM · optimizationterraintextureareasplatmapforloop

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges