• 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 dawnmichal · Sep 28, 2015 at 06:04 PM · terrainbuildterrain shader

Different terrain look in editor and in build application.

Hi all. I have trouble with terrain material. I use Unity terrain component. I create terrain component programmatically.

 private bool m_TerrainHeightChanged = false;
 private bool m_TerrainTextureChanged = false;
 private float[,] m_Heights = new float[SectorSize, SectorSize];
 public SplatPrototype[] SplatTextures;
 private float[, ,] m_Alphamaps;
             
 private void Start()
 {
    m_Terrain = gameObject.AddComponent<UnityEngine.Terrain>();
             
    m_TerrainData = new TerrainData();
             
    m_TerrainData.heightmapResolution = SectorSize;
    m_TerrainData.size = new Vector3(SectorSize, SectorHeight, SectorSize);
    m_TerrainData.SetHeights(0, 0, m_Heights);
             
    m_TerrainData.alphamapResolution = SectorSize;
    m_Alphamaps = new float[SectorSize, SectorSize, SplatTextures.Length];
    
    SetAllTexture(5);
    
    m_TerrainData.splatPrototypes = SplatTextures;
    m_TerrainData.SetAlphamaps(0, 0, m_Alphamaps);
    m_TerrainTextureChanged = false;
             
    m_TerrainData.SetDetailResolution(DetailResolution, DetailResolutionPatch);
                         
    m_Terrain.terrainData = m_TerrainData;
                         
    TerrainCollider myCollider = gameObject.AddComponent<TerrainCollider>();
    myCollider.terrainData = m_TerrainData;
             
    gameObject.transform.position = new Vector3(X, 0, Z);
             
    gameObject.tag = "TerrainSector";
    gameObject.layer = 9;
             
    UpdateNeighbors();
 }
             
 public void SetAllTexture(int _Texture)
 {
    for (int x = 0; x < m_Alphamaps.GetLength(0); x++)
    {
       for (int z = 0; z < m_Alphamaps.GetLength(1); z++)
       {
          for (int t = 0; t < m_Alphamaps.GetLength(2); t++)
          {
             m_Alphamaps[z, x, t] = t == _Texture ? 1 : 0;
          }
       }
    }            
    
    m_TerrainTextureChanged = true;
 }
             
 private void Update()
 {
    if (m_TerrainHeightChanged && m_TerrainData != null)
    {
       m_TerrainData.SetHeights(0, 0, m_Heights);
       m_TerrainHeightChanged = false;
    }
             
    if (m_TerrainTextureChanged && m_TerrainData != null)
    {
       m_TerrainData.SetAlphamaps(0, 0, m_Alphamaps);
       m_TerrainTextureChanged = false;
    }
 }

Everything works fine in editor. But after building project and running exe file, my terrain looks glossy. See difference on these pictures. First one is from editor and second from build application.

alt text

alt text

Terrain is matte in editor and glossy in build. I also added shaders (Nature/Terrain/Standard and Nature/Terrain/Diffuse) in Project Settings -> Graphics.

I also see these errors in console after build

  • Shader error in 'Hidden/NFAA': Compiled shader code uses too many instruction slots (112). Max. allowed by the target (ps_2_0) is 96. at line 1 (on d3d9). Compiling Fragment program.

  • Shader error in 'Hidden/NFAA': Compiled shader code uses too many instruction slots (99). Max. allowed by the target (ps_2_0) is 96. at line 1 (on d3d9). Compiling Fragment program

  • Shader error in 'Hidden/NFAA': Too many math instructions for SM2.0 (99 needed, max is 64). Try #pragma target 3.0 at line 78 (on d3d9). Compiling Fragment program

  • Shader error in 'Hidden/NFAA': Too many math instructions for SM2.0 (91 needed, max is 64). Try #pragma target 3.0 at line 114 (on d3d9). Compiling Fragment program

But I'm not sure what it means and if it matters. I'd really appreciate your help.

terrainproblem2.jpg (86.6 kB)
terrainproblem1.jpg (212.4 kB)
Comment
Add comment · Show 9
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 getyour411 · Sep 28, 2015 at 03:30 PM 0
Share

Is this on a laptop or PC with both an integrated and a discrete vid card?

avatar image dawnmichal · Sep 28, 2015 at 03:41 PM 0
Share

Both on same desktop PC with ATI video card. I will try do same thing with terrain added normal way (no using script).

avatar image getyour411 dawnmichal · Sep 28, 2015 at 03:44 PM 0
Share

The "S$$anonymous$$2" stuff - for Shader $$anonymous$$odel 2.0 I assume - made me ask, in case the project or resulting build is falling back to S$$anonymous$$ 2.0 which I think is used by older cards, don't have much experience with Shaders issues personally. I would focus on those errors with some Google/search.

Show more comments
avatar image dawnmichal · Sep 28, 2015 at 05:30 PM 0
Share

I did some tests and I think that problem is that I create terrain programmatically. When I add standard 3D terrain object in editor, it is matte also in build. But my programmatically created terrain is glossy in build. I also noticed that standard terrain is also glossy (in editor and build) until at least one splat texture is assigned to it. $$anonymous$$aybe I'm wrong in assigning splat textures....

avatar image getyour411 dawnmichal · Sep 28, 2015 at 10:05 PM 0
Share

I'm not sure what number (5) as argument on 20 means. Also you might try adding Terrain.Flush() after things in Update.

avatar image dawnmichal · Sep 29, 2015 at 03:17 PM 0
Share

Ok... next test result. When I use this...

 m_Terrain.materialType = UnityEngine.Terrain.$$anonymous$$aterialType.BuiltInStandard;

... problem occurs. But when I set BuiltInLegacyDiffuse like this...

 m_Terrain.materialType = UnityEngine.Terrain.$$anonymous$$aterialType.BuiltInLegacyDiffuse;

... problem fixed. This indicates that the problem is in standard shader setting for build. $$anonymous$$aybe I'm going to focus for Hidden/NFAA errors...

btw. for getyour411: Terrain.Flush() had no effect. Number 5 set splat texture (with index 5) for whole terrain (see method code in my answer). But thank you for your effort!

avatar image getyour411 dawnmichal · Sep 29, 2015 at 07:26 PM 0
Share

Cool, glad you found that. Should I convert your last update to an Answer or is there more work to be done here?

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Gras Dissapears in build 1 Answer

Textures OK in editor but bad in final build 2 Answers

My VR game build crashes when the terrain is enabled. 0 Answers

Why scene containing terrain is running slow in android device...? 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