Blender  V2.93
svm_fractal_noise.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
20 ccl_device_noinline float fractal_noise_1d(float p, float octaves, float roughness)
21 {
22  float fscale = 1.0f;
23  float amp = 1.0f;
24  float maxamp = 0.0f;
25  float sum = 0.0f;
26  octaves = clamp(octaves, 0.0f, 16.0f);
27  int n = float_to_int(octaves);
28  for (int i = 0; i <= n; i++) {
29  float t = noise_1d(fscale * p);
30  sum += t * amp;
31  maxamp += amp;
32  amp *= clamp(roughness, 0.0f, 1.0f);
33  fscale *= 2.0f;
34  }
35  float rmd = octaves - floorf(octaves);
36  if (rmd != 0.0f) {
37  float t = noise_1d(fscale * p);
38  float sum2 = sum + t * amp;
39  sum /= maxamp;
40  sum2 /= maxamp + amp;
41  return (1.0f - rmd) * sum + rmd * sum2;
42  }
43  else {
44  return sum / maxamp;
45  }
46 }
47 
48 /* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
49 ccl_device_noinline float fractal_noise_2d(float2 p, float octaves, float roughness)
50 {
51  float fscale = 1.0f;
52  float amp = 1.0f;
53  float maxamp = 0.0f;
54  float sum = 0.0f;
55  octaves = clamp(octaves, 0.0f, 16.0f);
56  int n = float_to_int(octaves);
57  for (int i = 0; i <= n; i++) {
58  float t = noise_2d(fscale * p);
59  sum += t * amp;
60  maxamp += amp;
61  amp *= clamp(roughness, 0.0f, 1.0f);
62  fscale *= 2.0f;
63  }
64  float rmd = octaves - floorf(octaves);
65  if (rmd != 0.0f) {
66  float t = noise_2d(fscale * p);
67  float sum2 = sum + t * amp;
68  sum /= maxamp;
69  sum2 /= maxamp + amp;
70  return (1.0f - rmd) * sum + rmd * sum2;
71  }
72  else {
73  return sum / maxamp;
74  }
75 }
76 
77 /* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
78 ccl_device_noinline float fractal_noise_3d(float3 p, float octaves, float roughness)
79 {
80  float fscale = 1.0f;
81  float amp = 1.0f;
82  float maxamp = 0.0f;
83  float sum = 0.0f;
84  octaves = clamp(octaves, 0.0f, 16.0f);
85  int n = float_to_int(octaves);
86  for (int i = 0; i <= n; i++) {
87  float t = noise_3d(fscale * p);
88  sum += t * amp;
89  maxamp += amp;
90  amp *= clamp(roughness, 0.0f, 1.0f);
91  fscale *= 2.0f;
92  }
93  float rmd = octaves - floorf(octaves);
94  if (rmd != 0.0f) {
95  float t = noise_3d(fscale * p);
96  float sum2 = sum + t * amp;
97  sum /= maxamp;
98  sum2 /= maxamp + amp;
99  return (1.0f - rmd) * sum + rmd * sum2;
100  }
101  else {
102  return sum / maxamp;
103  }
104 }
105 
106 /* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
107 ccl_device_noinline float fractal_noise_4d(float4 p, float octaves, float roughness)
108 {
109  float fscale = 1.0f;
110  float amp = 1.0f;
111  float maxamp = 0.0f;
112  float sum = 0.0f;
113  octaves = clamp(octaves, 0.0f, 16.0f);
114  int n = float_to_int(octaves);
115  for (int i = 0; i <= n; i++) {
116  float t = noise_4d(fscale * p);
117  sum += t * amp;
118  maxamp += amp;
119  amp *= clamp(roughness, 0.0f, 1.0f);
120  fscale *= 2.0f;
121  }
122  float rmd = octaves - floorf(octaves);
123  if (rmd != 0.0f) {
124  float t = noise_4d(fscale * p);
125  float sum2 = sum + t * amp;
126  sum /= maxamp;
127  sum2 /= maxamp + amp;
128  return (1.0f - rmd) * sum + rmd * sum2;
129  }
130  else {
131  return sum / maxamp;
132  }
133 }
134 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
static T sum(const btAlignedObjectArray< T > &items)
#define ccl_device_noinline
#define CCL_NAMESPACE_END
#define floorf(x)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
ccl_device_noinline float fractal_noise_4d(float4 p, float octaves, float roughness)
ccl_device_noinline float fractal_noise_2d(float2 p, float octaves, float roughness)
ccl_device_noinline float fractal_noise_3d(float3 p, float octaves, float roughness)
CCL_NAMESPACE_BEGIN ccl_device_noinline float fractal_noise_1d(float p, float octaves, float roughness)
ccl_device_inline float noise_2d(float2 p)
Definition: svm_noise.h:717
ccl_device_inline float noise_3d(float3 p)
Definition: svm_noise.h:727
ccl_device_inline float noise_4d(float4 p)
Definition: svm_noise.h:737
ccl_device_inline float noise_1d(float p)
Definition: svm_noise.h:707
ccl_device_inline int float_to_int(float f)
Definition: util_math.h:321
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util_math.h:283