Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class bakePerlinNoise : MonoBehaviour {
- public Vector2Int resolution = new Vector2Int(128,128);
- public float Tiling = 0.05f;
- public Texture2D perlin;
- void Start() { Bake(); }
- void Bake()
- {
- perlin = new Texture2D(resolution.x, resolution.y)
- {
- name = "Perlin", anisoLevel = 4, filterMode = FilterMode.Trilinear, wrapMode = TextureWrapMode.Repeat,
- };
- Vector4 Shift = new Vector4(Random.value * 214.21f, Random.value * 21.62f, Random.value * 4.21f, Random.value * 523.21f);
- for (int x = 0; x< resolution.x; x++)
- {
- for(int y = 0; y < resolution.y; y++)
- {
- Color toSet = new Color(Mathf.PerlinNoise(x* Tiling, y* Tiling),
- Mathf.PerlinNoise((x + Shift.x)* Tiling, ( y + Shift.y)* Tiling),
- Mathf.PerlinNoise((x+ Shift.z)* Tiling, ( y + Shift.w) * Tiling));
- perlin.SetPixel(x, y, toSet);
- }
- }
- perlin.Apply();
- Shader.SetGlobalTexture("_Perlin", perlin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement