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 /
This question was closed Sep 28, 2015 at 05:06 PM by getyour411.
avatar image
0
Question by chinapdyh · Oct 09, 2014 at 10:52 AM · textureterrain

Terrain Texture

I write some code to create a terrain and add maps.

This is my code:

============================================================================

   float[, ,] splatmapData = new float[terrain.heightmapWidth, terrain.heightmapWidth, terrain.alphamapLayers];

    for (int y = 0; y < terrain.heightmapWidth; y++)
    {
        for (int x = 0; x < terrain.heightmapWidth; x++)
        {
            // read the height at this location
            float height = terrain.GetHeight(y, x);
            //float height = terArr[x,y];
   
            Vector3 splat = new Vector3(0, 1, 0);
            if (height/128 < 0.2f)
            {
                //splat = Vector3.Lerp(splat, new Vector3(0, 0, 0.3f), height);
                splat = new Vector3(1, 0, 0);
            }
            else if (height / 128 < 0.5f)
            {
                //splat = Vector3.Lerp(splat, new Vector3(0, 0, 0.6f), height);
                splat = new Vector3(0, 1, 0);
            }
            else 
            {
                //splat = Vector3.Lerp(splat, new Vector3(1, 0, 0), height);
                splat = new Vector3(0, 0, 1);
            }
            
            // now assign the values to the correct location in the array
            //splat.Normalize();
            splatmapData[x, y, 0] = splat.x;
            splatmapData[x, y, 1] = splat.y;
            splatmapData[x, y, 2] = splat.z;

        }

============================================================================

This code seems work well.But the only question is the above code only support 3 textures,if I want to add more texture on my Terrain.How can I do ?

Comment
Add comment · Show 5
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 chinapdyh · Oct 10, 2014 at 02:22 AM 0
Share

is there anyone know the answer?

avatar image revolute · Oct 10, 2014 at 02:38 AM 0
Share

What exactly do you wish to happen?

Add a new texture using script or a good way to handle splatmap that may contain more than one texture?

avatar image chinapdyh · Oct 10, 2014 at 07:29 AM 0
Share

I want to use more than four texture,but it doesn't work.The terrain will be Pink

avatar image revolute · Oct 10, 2014 at 07:40 AM 0
Share

Would you explain how you tried to put 4 textures? If a texture was simply added to Terrain textures, then there should be no problem.

avatar image chinapdyh · Oct 10, 2014 at 07:47 AM 0
Share

I add the texture like this:

 //Texture
 public Texture2D[] t;

terrain.splatPrototypes = CreateSplatPrototypes(t, new Vector2(4, 4), new Vector2(0, 0));

 public SplatPrototype CreateSplatPrototype(Texture2D tmpTexture, Vector2 tmpTileSize, Vector2 tmpOffset)
 {
     SplatPrototype outSplatPrototype = new SplatPrototype();
     outSplatPrototype.texture = tmpTexture;
     outSplatPrototype.tileOffset = tmpOffset;
     outSplatPrototype.tileSize = tmpTileSize;
     return outSplatPrototype;
 }

 public SplatPrototype[] CreateSplatPrototypes(Texture2D[] tmpTextures, Vector2 tmpTileSize, Vector2 tmpOffset)
 {
     //Debug.Log(tmpTextures.Length);
     SplatPrototype[] outSplatPrototypes = new SplatPrototype[tmpTextures.Length];

     for (int i = 0; i < tmpTextures.Length; ++i)
     {
         outSplatPrototypes[i] = CreateSplatPrototype(tmpTextures[i], tmpTileSize, tmpOffset);
     }
     return outSplatPrototypes;
 }

alt text

qq图片20141010154612.jpg (26.6 kB)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Terrain Painting Script 0 Answers

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

Terrain texture low quality 0 Answers

Blob Shadow and Trees Using Terrain Cause Issues 0 Answers

create terrain using script 1 Answer


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