Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by User Banned · Dec 10, 2012 at 02:01 AM · terrainpaintbrushsplatmap

Blend texture seam between 2 terrains tiles

At the root of this problem is that i cannot for the life of me fathom how to paint a texture onto a terrain via script, the way of editing splatmap data just seems totally counter intuitive to me, rendering me unable to adapt the examples ive seen elsewhere to my situation. In short i am thick.

What im attempting to do is get from this:

alt text

To this:

alt text

Or similar. I can sample a point on Terrain 1 and retrieve the texture no problem. Where i fail miserably is painting it at a target point with a brush effect on Terrain 2. The closest i have got to this is wiping the whole terrain splatmap and turning it black!

So then to anyone more cranially endowed than myself, how do i stamp my retrieved texture using a stencil brush at my target position, assuming all have already been predefined?

textureblend1.jpg (19.9 kB)
textureblend2.jpg (19.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gilley033 · Jan 28, 2013 at 10:36 PM

To start, each terrain should use the same alphamap, i.e., under textures for each terrain you should see your dirt texture and then your grass texture. Make sure the order the textures appear is the same, or else it will make this next bit not work.

Next, you can store the terrain data for each terrain. This assumes you have some variables storing each terrain, which we'll call terrain1 and terrain2. So do:

 var data1 : TerrainData = terrain1.terrainData; 
 var data2 : TerrainData = terrain2.terrainData;

Now get the alphamapWidth and Height. Note that each terrain's width/height should be the same, or else none of this will work. This means we only need data1's (or twos if you want) height/width.

 var width : int = data1.alphamapWidth;
 var height : int = data1.alphamapHeight;

Now we need to actually get the alpha maps of each terrain:

 var map1 : float[,,] = data1.GetAlphamaps(0,0,width,height);
 var map2 : float[,,] = data2.GetAlphamaps(0,0,width,height);

Now that you have the alphamaps, you want to adjust the maps to blend them together. Now, unfortunately you will not be able to achieve exactly what you outlined in the pictures above. In order for the terrains to blend along the edges properly, each neighboring spot on each terrain's alphamap must be the same, so you cannot have dirt on the edge of terrain 1 and dirt/grass on the edge of terrain2. You have to have dirt/grass on the edge of both. The transition should look the same as what you outlined, it will just happen on the edge, rather than to the right of the edge.

What you can do is traverse the edge, finding the average between the two edges splatmap, and replacing these spots with this average. Something like this (Note, this code assumes terrain 1 is sitting to the left of terrain 2. If terrain 1 is below terrain 2 you will have to adjust the code a bit):

 var num_of_splats : int = data1.splatPrototypes.Length;
 
 var avg : float;
 var i : int;
 var y : int;
 for(y = 0; y < height; y++)
 {
    for(i = 0; i < num_of_splats; i++)
    {
       avg = (map1[y,width-1,i] + map2[y,0,i])/2f;
       map1[y,width-1,i] = avg;
       map2[y,0,i] = avg;
    }       
 }
 data1.SetAlphamaps(0,0,map1);
 data2.SetAlphamaps(0,0,map2);

This will traverse the edge from bottom to top. y will run from 0 to height-1. The width-1 defines the column of the alphamap we want to use of terrain 1. Since we are concerned with the right most column of terrain 1, this is why we use width -1. Since we are concerned with the left most column of terrain 2, we use 0 for map2 (map2[y,0,i]).

The i for loop iterates through each splatmap at each point on the alphamap.

Good luck!

Comment
Add comment · Show 1 · Share
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
avatar image User Banned · Feb 09, 2013 at 12:45 AM 0
Share

Comprehensive post which clarifies it nicely, thank you. For some reason my email junked the notification so ive only just noticed it.

I was approaching the problem with the aim of dynamically adding a retrieved texture to another alphamap and simply stamping it on, which seems to be why i was tying myself in knots.

Part of the reason im using seperate terrains though is because i need different alphamaps, or at least i thought i did before your post made me consider the issue, il have to experiment with that.

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

10 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

Related Questions

Detail texture and mesh for grass and bushes not rendering correctly on device 1 Answer

Terrain Painting Script 0 Answers

How to "paint" the terrain in a script? 1 Answer

Painting on the terrain. 2 Answers

How to use get/setAlphamaps? 4 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