- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Bajtix · Jun 07, 2020 at 11:01 AM ·
terrain generationsplatmap
How to create splat map based on mesh normals?
Hi! I have recently started making my new game which contains a procedurally generated mesh terrain. I wanted to texture it based on the normal and a few other parameters that I am going to define later. I've created a shader that takes in a grayscale splat map and mixes different textures based on it. Now my problem is, that I have no idea how to create the splatmap. I want it to be based around normal of the face, but with my current code:
int i = 0;
pixelLog = $"Length of the array: {verts.Length}";
for(int x = 0; x < s; x++)
{
for (int y = 0; y < s; y++)
{
Vector3 norm = transform.TransformDirection(normals[i]);
float clor = Mathf.Pow(norm.y, 80);
normals_tx.SetPixel(x, y, new Color(clor, clor, clor));
pixelLog = pixelLog + $"\n Added pixel at {x} :: {y} with i = {i} of color {clor}"; //just logging all the operations, temporary
i++;
}
}
yield return new WaitForEndOfFrame();
normals_tx.Apply();
byte[] png = normals_tx.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/file.png", png); //saving the results for preview
File.WriteAllText(Application.persistentDataPath + "/filelog.txt", pixelLog);
GetComponent<MeshRenderer>().material.SetTexture("_SplatMap", normals_tx);
it just creates seemingly random jibberish: Does anyone know a good solution?
file.png
(2.1 kB)
Comment
Your answer
Follow this Question
Related Questions
Can you change terrain material? 4 Answers
Deleting terrain splatmap through scripts. 1 Answer
Writing a Custom Collider 0 Answers
Terrain trees below surface 0 Answers