- Home /
How to move vertices up/down randomly in shader.
Hello!
I have a plane and I'd like to adjust the y positions of the vertices in the shader. Actually moving them is simple enough, but I was wondering what the best way of getting the random values for heights was?
Would I need a random function inside the shader to get a value within a range?
Thanks
Hey, thanks for the reply! Sorry I was vague.
What I'm hoping to achieve is to modify a flat plane so that the vertices will move up and/or down in the y axis, giving it an uneven surface.
I am just using this:
// Vertex modifier
void vert (inout appdata_full v)
{
v.vertex.y += _Amount;
}
where _Amount will be the random value generated. With the function you provided, what float2 input should it take?
Thanks a lot!
Unless you want complete randomness you should probably use some kind of noise function such as perlin noise.
But for optimization purposes you should probably just use a texture as a heightmap to offset your verts!
Answer by Gruffy · Dec 06, 2014 at 02:58 PM
Hey bud, Are you trying to scroll your texture with the shader or something like that ? You would be looking to do this in the Surf shader function
You could call to the _Time property and multiply it by a set of values based on the x and y you set it. yo could then effect them with random values passed into the vars holding the x and y values. I could go on. the code would look similar to this...
fixed yScrollValue = _ScrollYSpeed * _Time;
you might make _ScrollYSpeed an accessible parameter in the inspector for the shader allowing you to adjust/tweak it visually afterwards.
You could be looking for a a small function to run on a float in your code like so....
float randomNum(in float2 uv)
float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453));
return abs(noise.x + noise.y) * 0.5;
}
but without your code, who knows ? Then again, who even knows, if you are using Unitys shader language, Cg, HLSL ?
So... Could you possibly add in your shader code please, so we can get to the bottom of it faster for you.
Hope that helps some Take care Bud Gruffy
Your answer
![](https://koobas.hobune.stream/wayback/20220613173352im_/https://answers.unity.com/themes/thub/images/avi.jpg)