Differential D13043 Diff 44271 source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl
| /* The fractal_noise functions are all exactly the same except for the input type. */ | /* The fractal_noise functions are all exactly the same except for the input type. */ | ||||
| float fractal_noise(float p, float octaves, float roughness) | float fractal_noise(float p, float octaves, float roughness) | ||||
| { | { | ||||
| float fscale = 1.0; | float fscale = 1.0; | ||||
| float amp = 1.0; | float amp = 1.0; | ||||
| float maxamp = 0.0; | float maxamp = 0.0; | ||||
| float sum = 0.0; | float sum = 0.0; | ||||
| octaves = clamp(octaves, 0.0, 16.0); | octaves = clamp(octaves, 0.0, 15.0); | ||||
| int n = int(octaves); | int n = int(octaves); | ||||
| for (int i = 0; i <= n; i++) { | for (int i = 0; i <= n; i++) { | ||||
| float t = noise(fscale * p); | float t = noise(fscale * p); | ||||
| sum += t * amp; | sum += t * amp; | ||||
| maxamp += amp; | maxamp += amp; | ||||
| amp *= clamp(roughness, 0.0, 1.0); | amp *= clamp(roughness, 0.0, 1.0); | ||||
| fscale *= 2.0; | fscale *= 2.0; | ||||
| } | } | ||||
| Show All 12 Lines | |||||
| /* The fractal_noise functions are all exactly the same except for the input type. */ | /* The fractal_noise functions are all exactly the same except for the input type. */ | ||||
| float fractal_noise(vec2 p, float octaves, float roughness) | float fractal_noise(vec2 p, float octaves, float roughness) | ||||
| { | { | ||||
| float fscale = 1.0; | float fscale = 1.0; | ||||
| float amp = 1.0; | float amp = 1.0; | ||||
| float maxamp = 0.0; | float maxamp = 0.0; | ||||
| float sum = 0.0; | float sum = 0.0; | ||||
| octaves = clamp(octaves, 0.0, 16.0); | octaves = clamp(octaves, 0.0, 15.0); | ||||
| int n = int(octaves); | int n = int(octaves); | ||||
| for (int i = 0; i <= n; i++) { | for (int i = 0; i <= n; i++) { | ||||
| float t = noise(fscale * p); | float t = noise(fscale * p); | ||||
| sum += t * amp; | sum += t * amp; | ||||
| maxamp += amp; | maxamp += amp; | ||||
| amp *= clamp(roughness, 0.0, 1.0); | amp *= clamp(roughness, 0.0, 1.0); | ||||
| fscale *= 2.0; | fscale *= 2.0; | ||||
| } | } | ||||
| Show All 12 Lines | |||||
| /* The fractal_noise functions are all exactly the same except for the input type. */ | /* The fractal_noise functions are all exactly the same except for the input type. */ | ||||
| float fractal_noise(vec3 p, float octaves, float roughness) | float fractal_noise(vec3 p, float octaves, float roughness) | ||||
| { | { | ||||
| float fscale = 1.0; | float fscale = 1.0; | ||||
| float amp = 1.0; | float amp = 1.0; | ||||
| float maxamp = 0.0; | float maxamp = 0.0; | ||||
| float sum = 0.0; | float sum = 0.0; | ||||
| octaves = clamp(octaves, 0.0, 16.0); | octaves = clamp(octaves, 0.0, 15.0); | ||||
| int n = int(octaves); | int n = int(octaves); | ||||
| for (int i = 0; i <= n; i++) { | for (int i = 0; i <= n; i++) { | ||||
| float t = noise(fscale * p); | float t = noise(fscale * p); | ||||
| sum += t * amp; | sum += t * amp; | ||||
| maxamp += amp; | maxamp += amp; | ||||
| amp *= clamp(roughness, 0.0, 1.0); | amp *= clamp(roughness, 0.0, 1.0); | ||||
| fscale *= 2.0; | fscale *= 2.0; | ||||
| } | } | ||||
| Show All 12 Lines | |||||
| /* The fractal_noise functions are all exactly the same except for the input type. */ | /* The fractal_noise functions are all exactly the same except for the input type. */ | ||||
| float fractal_noise(vec4 p, float octaves, float roughness) | float fractal_noise(vec4 p, float octaves, float roughness) | ||||
| { | { | ||||
| float fscale = 1.0; | float fscale = 1.0; | ||||
| float amp = 1.0; | float amp = 1.0; | ||||
| float maxamp = 0.0; | float maxamp = 0.0; | ||||
| float sum = 0.0; | float sum = 0.0; | ||||
| octaves = clamp(octaves, 0.0, 16.0); | octaves = clamp(octaves, 0.0, 15.0); | ||||
| int n = int(octaves); | int n = int(octaves); | ||||
| for (int i = 0; i <= n; i++) { | for (int i = 0; i <= n; i++) { | ||||
| float t = noise(fscale * p); | float t = noise(fscale * p); | ||||
| sum += t * amp; | sum += t * amp; | ||||
| maxamp += amp; | maxamp += amp; | ||||
| amp *= clamp(roughness, 0.0, 1.0); | amp *= clamp(roughness, 0.0, 1.0); | ||||
| fscale *= 2.0; | fscale *= 2.0; | ||||
| } | } | ||||
| Show All 12 Lines | |||||