Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
SkShaders Namespace Reference

Classes

class  MatrixRec
 

Functions

SK_API sk_sp< SkShaderMakeFractalNoise (SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
 
SK_API sk_sp< SkShaderMakeTurbulence (SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
 

Function Documentation

◆ MakeFractalNoise()

sk_sp< SkShader > SkShaders::MakeFractalNoise ( SkScalar  baseFrequencyX,
SkScalar  baseFrequencyY,
int  numOctaves,
SkScalar  seed,
const SkISize tileSize = nullptr 
)

This will construct Perlin noise of the given type (Fractal Noise or Turbulence).

Both base frequencies (X and Y) have a usual range of (0..1) and must be non-negative.

The number of octaves provided should be fairly small, with a limit of 255 enforced. Each octave doubles the frequency, so 10 octaves would produce noise from baseFrequency * 1, * 2, * 4, ..., * 512, which quickly yields insignificantly small periods and resembles regular unstructured noise rather than Perlin noise.

If tileSize isn't NULL or an empty size, the tileSize parameter will be used to modify the frequencies so that the noise will be tileable for the given tile size. If tileSize is NULL or an empty size, the frequencies will be used as is without modification.

Definition at line 135 of file SkPerlinNoiseShaderImpl.cpp.

139 {
140 if (!valid_input(baseFrequencyX, baseFrequencyY, numOctaves, tileSize, seed)) {
141 return nullptr;
142 }
143
144 if (0 == numOctaves) {
145 // For kFractalNoise, w/o any octaves, the entire shader collapses to:
146 // [0,0,0,0] * 0.5 + 0.5
147 constexpr SkColor4f kTransparentGray = {0.5f, 0.5f, 0.5f, 0.5f};
148
149 return SkShaders::Color(kTransparentGray, /* colorSpace= */ nullptr);
150 }
151
153 baseFrequencyX,
154 baseFrequencyY,
155 numOctaves,
156 seed,
157 tileSize));
158}
static bool valid_input(SkScalar baseX, SkScalar baseY, int numOctaves, const SkISize *tileSize, SkScalar seed)

◆ MakeTurbulence()

sk_sp< SkShader > SkShaders::MakeTurbulence ( SkScalar  baseFrequencyX,
SkScalar  baseFrequencyY,
int  numOctaves,
SkScalar  seed,
const SkISize tileSize = nullptr 
)

Definition at line 160 of file SkPerlinNoiseShaderImpl.cpp.

164 {
165 if (!valid_input(baseFrequencyX, baseFrequencyY, numOctaves, tileSize, seed)) {
166 return nullptr;
167 }
168
169 if (0 == numOctaves) {
170 // For kTurbulence, w/o any octaves, the entire shader collapses to: [0,0,0,0]
171 return SkShaders::Color(SkColors::kTransparent, /* colorSpace= */ nullptr);
172 }
173
175 baseFrequencyX,
176 baseFrequencyY,
177 numOctaves,
178 seed,
179 tileSize));
180}
constexpr SkColor4f kTransparent
Definition SkColor.h:434