Blender
V2.93
intern
cycles
kernel
shaders
node_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
17
#include "vector2.h"
18
#include "vector4.h"
19
20
#define vector3 point
21
22
float
safe_noise
(
float
p)
23
{
24
float
f =
noise
(
"noise"
, p);
25
if
(isinf(f))
26
return
0.5;
27
return
f;
28
}
29
30
float
safe_noise
(vector2 p)
31
{
32
float
f =
noise
(
"noise"
, p.x, p.y);
33
if
(isinf(f))
34
return
0.5;
35
return
f;
36
}
37
38
float
safe_noise
(
vector3
p)
39
{
40
float
f =
noise
(
"noise"
, p);
41
if
(isinf(f))
42
return
0.5;
43
return
f;
44
}
45
46
float
safe_noise
(vector4 p)
47
{
48
float
f =
noise
(
"noise"
,
vector3
(p.x, p.y, p.z), p.w);
49
if
(isinf(f))
50
return
0.5;
51
return
f;
52
}
53
54
float
safe_snoise
(
float
p)
55
{
56
float
f =
noise
(
"snoise"
, p);
57
if
(isinf(f))
58
return
0.0;
59
return
f;
60
}
61
62
float
safe_snoise
(vector2 p)
63
{
64
float
f =
noise
(
"snoise"
, p.x, p.y);
65
if
(isinf(f))
66
return
0.0;
67
return
f;
68
}
69
70
float
safe_snoise
(
vector3
p)
71
{
72
float
f =
noise
(
"snoise"
, p);
73
if
(isinf(f))
74
return
0.0;
75
return
f;
76
}
77
78
float
safe_snoise
(vector4 p)
79
{
80
float
f =
noise
(
"snoise"
,
vector3
(p.x, p.y, p.z), p.w);
81
if
(isinf(f))
82
return
0.0;
83
return
f;
84
}
85
86
/* The fractal_noise functions are all exactly the same except for the input type. */
87
float
fractal_noise
(
float
p,
float
details,
float
roughness
)
88
{
89
float
fscale = 1.0;
90
float
amp = 1.0;
91
float
maxamp = 0.0;
92
float
sum
= 0.0;
93
float
octaves =
clamp
(details, 0.0, 16.0);
94
int
n = (int)octaves;
95
for
(
int
i = 0; i <= n; i++) {
96
float
t
=
safe_noise
(fscale * p);
97
sum
+=
t
* amp;
98
maxamp += amp;
99
amp *=
clamp
(
roughness
, 0.0, 1.0);
100
fscale *= 2.0;
101
}
102
float
rmd = octaves -
floor
(octaves);
103
if
(rmd != 0.0) {
104
float
t
=
safe_noise
(fscale * p);
105
float
sum2 =
sum
+
t
* amp;
106
sum
/= maxamp;
107
sum2 /= maxamp + amp;
108
return
(1.0 - rmd) *
sum
+ rmd * sum2;
109
}
110
else
{
111
return
sum
/ maxamp;
112
}
113
}
114
115
/* The fractal_noise functions are all exactly the same except for the input type. */
116
float
fractal_noise
(vector2 p,
float
details,
float
roughness
)
117
{
118
float
fscale = 1.0;
119
float
amp = 1.0;
120
float
maxamp = 0.0;
121
float
sum
= 0.0;
122
float
octaves =
clamp
(details, 0.0, 16.0);
123
int
n = (int)octaves;
124
for
(
int
i = 0; i <= n; i++) {
125
float
t
=
safe_noise
(fscale * p);
126
sum
+=
t
* amp;
127
maxamp += amp;
128
amp *=
clamp
(
roughness
, 0.0, 1.0);
129
fscale *= 2.0;
130
}
131
float
rmd = octaves -
floor
(octaves);
132
if
(rmd != 0.0) {
133
float
t
=
safe_noise
(fscale * p);
134
float
sum2 =
sum
+
t
* amp;
135
sum
/= maxamp;
136
sum2 /= maxamp + amp;
137
return
(1.0 - rmd) *
sum
+ rmd * sum2;
138
}
139
else
{
140
return
sum
/ maxamp;
141
}
142
}
143
144
/* The fractal_noise functions are all exactly the same except for the input type. */
145
float
fractal_noise
(
vector3
p,
float
details,
float
roughness
)
146
{
147
float
fscale = 1.0;
148
float
amp = 1.0;
149
float
maxamp = 0.0;
150
float
sum
= 0.0;
151
float
octaves =
clamp
(details, 0.0, 16.0);
152
int
n = (int)octaves;
153
for
(
int
i = 0; i <= n; i++) {
154
float
t
=
safe_noise
(fscale * p);
155
sum
+=
t
* amp;
156
maxamp += amp;
157
amp *=
clamp
(
roughness
, 0.0, 1.0);
158
fscale *= 2.0;
159
}
160
float
rmd = octaves -
floor
(octaves);
161
if
(rmd != 0.0) {
162
float
t
=
safe_noise
(fscale * p);
163
float
sum2 =
sum
+
t
* amp;
164
sum
/= maxamp;
165
sum2 /= maxamp + amp;
166
return
(1.0 - rmd) *
sum
+ rmd * sum2;
167
}
168
else
{
169
return
sum
/ maxamp;
170
}
171
}
172
173
/* The fractal_noise functions are all exactly the same except for the input type. */
174
float
fractal_noise
(vector4 p,
float
details,
float
roughness
)
175
{
176
float
fscale = 1.0;
177
float
amp = 1.0;
178
float
maxamp = 0.0;
179
float
sum
= 0.0;
180
float
octaves =
clamp
(details, 0.0, 16.0);
181
int
n = (int)octaves;
182
for
(
int
i = 0; i <= n; i++) {
183
float
t
=
safe_noise
(fscale * p);
184
sum
+=
t
* amp;
185
maxamp += amp;
186
amp *=
clamp
(
roughness
, 0.0, 1.0);
187
fscale *= 2.0;
188
}
189
float
rmd = octaves -
floor
(octaves);
190
if
(rmd != 0.0) {
191
float
t
=
safe_noise
(fscale * p);
192
float
sum2 =
sum
+
t
* amp;
193
sum
/= maxamp;
194
sum2 /= maxamp + amp;
195
return
(1.0 - rmd) *
sum
+ rmd * sum2;
196
}
197
else
{
198
return
sum
/ maxamp;
199
}
200
}
201
202
#undef vector3
t
_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
Definition:
GPU_legacy_stubs.h:439
sum
static T sum(const btAlignedObjectArray< T > &items)
Definition:
btSoftBodyHelpers.cpp:94
vector3
Definition:
util_types_vector3.h:27
usdtokens::roughness
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
fractal_noise
float fractal_noise(float p, float details, float roughness)
Definition:
node_noise.h:87
vector3
#define vector3
Definition:
node_noise.h:20
safe_snoise
float safe_snoise(float p)
Definition:
node_noise.h:54
safe_noise
float safe_noise(float p)
Definition:
node_noise.h:22
noise
static float noise(int n)
Definition:
node_texture_bricks.c:50
clamp
ccl_device_inline int clamp(int a, int mn, int mx)
Definition:
util_math.h:283
floor
ccl_device_inline float2 floor(const float2 &a)
Definition:
util_math_float2.h:260
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1