- Home /
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.
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.
Is this on a laptop or PC with both an integrated and a discrete vid card?
Both on same desktop PC with ATI video card. I will try do same thing with terrain added normal way (no using script).
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.
that could be something shader related. I will check it out.
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....
I'm not sure what number (5) as argument on 20 means. Also you might try adding Terrain.Flush() after things in Update.
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!
Cool, glad you found that. Should I convert your last update to an Answer or is there more work to be done here?
This is not real fix. It is workaround. Now I use legacy terrain material insted of standard terrain material. There is more work to do. I will let you know ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220612035215im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Terrain Grass black in build only. 1 Answer
Why is there no texture on my terrain after I build the game? 1 Answer
Terrain not appearing shaded unless very close 1 Answer
Terrain building with errors 0 Answers