mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
SimpleNoise algorithm improved
This commit is contained in:
parent
e2c630daae
commit
ccf5ddd609
@ -2,27 +2,31 @@ float noise_random_value(vec2 uv){
|
||||
return fract(sin(dot(uv.xy, vec2(12.9898,78.233))) * 43758.5453123);
|
||||
}
|
||||
|
||||
float value_noise(vec2 uv) {
|
||||
vec2 uv_index = floor(uv);
|
||||
vec2 uv_fract = fract(uv);
|
||||
float a = noise_random_value(uv_index);
|
||||
float b = noise_random_value(uv_index + vec2(1.0, 0.0));
|
||||
float c = noise_random_value(uv_index + vec2(0.0, 1.0));
|
||||
float d = noise_random_value(uv_index + vec2(1.0, 1.0));
|
||||
vec2 blur = smoothstep(0.0, 1.0, uv_fract);
|
||||
return mix(a, b, blur.x) + ((c - a) * blur.y * (1.0 - blur.x)) + ((d - b) * blur.x * blur.y);
|
||||
float value_noise(vec2 uv){
|
||||
vec2 _floor = floor(uv);
|
||||
vec2 _fraction = fract(uv);
|
||||
_fraction = _fraction * _fraction * (3.0 - 2.0 * _fraction);
|
||||
vec2 _corner = vec2(1.0, 0.0);
|
||||
|
||||
float _c0 = noise_random_value(_floor + _corner.yy);
|
||||
float _c1 = noise_random_value(_floor + _corner.xy);
|
||||
float _c2 = noise_random_value(_floor + _corner.yx);
|
||||
float _c3 = noise_random_value(_floor + _corner.xx);
|
||||
|
||||
vec2 _blur = smoothstep(0.0, 1.0, _fraction);
|
||||
float mix_one = mix(_c0, _c1, _blur.x) + (_c2 - _c0) * _blur.y * (1.0 - _blur.x) + (_c3 - _c1) * _blur.x * _blur.y;
|
||||
return mix_one;
|
||||
}
|
||||
|
||||
float simple_noise(vec2 uv, float scale){
|
||||
int octaves = 6;
|
||||
float amplitude = 0.5;
|
||||
float frequency = scale;
|
||||
float amplitude = 0.25;
|
||||
float value = 0.0;
|
||||
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
value += amplitude * value_noise(frequency * uv);
|
||||
amplitude *= 0.5;
|
||||
frequency *= 2.0;
|
||||
value += amplitude * value_noise(scale * uv);
|
||||
amplitude *= 0.85;
|
||||
scale *= 3.0;
|
||||
}
|
||||
return value;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user