Posts

Showing posts with the label random

random number generation, noise and fbm, glsl

I should really change the name of this blog to Shader Shit.... anyway.. I'll get back to Unity specific crap one day. The following code is all for GLSL & will need adapting for use in a Unity fragment shader. I like to use Kodelife to test out my shader ideas. Look it up & give it some support if you like it! This post is about fake randomness, learnt from The Book of Shaders & The Art of Coding, on the website & youtube channel respectively. Within your main GLSL function, you might need to create a random value, often just a float value (remember you can make a vector from multiple floats). A great thing to feed such a random number generating function is your UV value. Here's an example- float random(vec2 uv){ return fract(sin(dot(uv,vec2(52.2957001,2355.957250024))*574.9829619)); } What we're doing here is getting the dot product of our UV coordinate, with an arbitrary vector that consists of large numbers with plenty of "complex" fractiona l...

repeating code every __ seconds

 lets say you want to spawn a gameobject every 3 seconds. First you'll need a Spawner object. It could be anything - lets use an Empty. Place it wherever you want. Make a new C# script and apply it to the Empty. Here's the code, with some comments using System.Collections; using System.Collections.Generic; using UnityEngine; public class spawner : MonoBehaviour {     public GameObject thing; //the object you want to spawn. Set it in the Inspector         void Start()     {         InvokeRepeating("makeThing", 3.0f, 1.0f); //calls makeThing function after 3 secs, every 1 sec     }     void makeThing() //the actual spawn script     {                  Instantiate(thing, transform.position, Random.rotation); //uses object "thing", at your Empty's position, with a random rotation/...