Custom Types
If you want to make something but don’t see how to do it with only what noiz provides, you may need to make a custom noise type. This page covers some ideas for how to do that.
-
Custom modifiers: If you want to change or morph the output of a noise function(s) in a custom way, you’ll want to make a
NoiseFunction. If your modifier is math based, you can ignore the suppliedNoiseRng. If you are passing it to other noise functions, consider callingNoiseRng::re_seed, which will prevent repetition between the noise functions. -
Custom noise algorithms: If you want to make a unique algorithm, that will be a
NoiseFunction. To drive randomness, use the suppliedNoiseRngpaired with types that areNoiseRngInputs. To make that output meaningful, useAnyValueFromBitsor other functions inrng. If you are dividing floats that may be zero, see alsoforce_float_non_zero. Consider also differentiating the function analytically with calculus. Note also that many noise algorithms should be made generic over aPartitionerwhen possible. -
Custom shapes: If you want to create uniquely shaped noise, you’ll need a custom
Partitioner,DomainCell, etc. Depending on how you want it to be used, there’s a variety of traits you may wish to implement. See thecellsmodule for more information. -
Custom curves: Noiz is powered by
bevy_math, so you can use and createCurves of your own. If you want this to be usable in the context of derivatives, make sure to implementSampleDerivative. -
Custom layers: If you want to modify an input across a
LayeredNoise’s layers, you’ll need to make a custom noise layer. See thelayeringmodule for examples of this. -
Custom layer configuring: If you want more than
Normed,NormedByDerivativeandPersistence, see thelayeringmodule. Also note that depending on what you want, it may be more performant to make a separate layering system. For example, masking in noiz could be implemented as layering, but is faster throughMasked, etc. -
Custom inputs: If you want to use custom noise inputs, use
RawNoiseinstead ofNoise. You may build more abstractions from there if you wish. -
Custom outputs: If you want to do something that can’t be represented as a
NoiseFunctionand want full control, useSampleable::sample_raw, which provides access to the entropy for that sample.
Regardless of what you’re making, keep these ideas in mind:
- Be careful when working with
WithGradientvalues; remember the chain rule. - Always
#[inline]your functions. This will make theNoise-level functions very fast. The caller can decide whether to inline the final noise function or not.