- Home /
Adjusting terrain texture tiling.
I have one terrain object in my game and I have "stages" which zooms the camera out. Now, what i want is to adjust the tiling of textures on my terrain, when the camera zooms out to a new "stage".
Is it possible to adjust the tiling at runtime?
Cheers.
It should be possible by setting the texture scale for the terrain shaders. I will try it later and answer your question.
It is a normal unity terrain. What do you mean by custom terrain? Like a custom 3d-model?
Answer by Marnix · Apr 11, 2011 at 03:11 PM
Ok, this is a try. I'm not writing this fully for you, but you could try something like this:
- Add an extra
MonoBehaviour
class to your terrain gameobject - in the
Update()
method, get the renderer from the terrain component (see example) - foreach
Material
:mat.SetTextureScale("name: like _Scale probably?", new Vector2(someFormula));
- You can get the main camera with:
Camera.main;
Example, not tested and more like pseudo-code:
public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () {}
// Update is called once per frame
void Update () {
// get the materials from the terrain
Material [] ms = this.gameObject.GetComponent<Terrain>().renderer.materials;
Camera main = Camera.main; // get the main camera
// set texture scale each frame,
//because the camera will probably change each frame
foreach (Material m in ms)
{
m.SetTextureScale("...", new Vector2(someFormula));
}
}
}
I am not certain about the name of SetTextureScale, because it depends fully on the shader it uses. I am also uncertain about just saying: GetComponent<Terrain>().renderer
. Don't know if that works. But it's worth a try.
Your answer

Follow this Question
Related Questions
How to make trees in a terrain transparent in runtime? 0 Answers
lowering Terrain at run-time, C# 0 Answers
Paint Terrain Texture From Vector3 List 0 Answers
Modify a mesh at runtime 0 Answers
Make a simple tree 1 Answer