stegu / webgl-noise Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ashima/webgl-noise
GLSL procedural noise functions compatible with WebGL
License: MIT License
This project forked from ashima/webgl-noise
GLSL procedural noise functions compatible with WebGL
License: MIT License
Hi, first thanks for the great work!
I need periodic 2D noise for a planet texture/heightmap.
My current solution is the following.
Take the UV and do this:
vec4 tile(in vec2 pos) {
return vec4(
offset + cos(pos.x * 2.0 * PI) * inResolution.x / (2.0 * PI),
offset + cos(pos.y * 2.0 * PI) * inResolution.y / (2.0 * PI),
offset + sin(pos.x * 2.0 * PI) * inResolution.x / (2.0 * PI),
offset + sin(pos.y * 2.0 * PI) * inResolution.y / (2.0 * PI)
);
}
The resulting 4D position is the used in 4D simplex noise as position. This leads to sweet tileable noise.
This is how I doing fractal brownian motion for example:
float fbm(in vec4 pos, in int octaves, in float frequency, in float lacunarity, in float persistence) {
frequency /= inResolution.x;
float currentWeight = 1.0;
float totalWeights = 0.0;
float result = 0.0;
for (int i = 0; i < MAX_OCTAVES; i++) {
if (i >= octaves) break;
result += snoise(vec4(pos.x * frequency, pos.y * frequency, pos.z * frequency, pos.w * frequency)) * currentWeight;
totalWeights += currentWeight;
currentWeight *= persistence;
frequency *= lacunarity;
}
return result / totalWeights;
}
But this is 4D noise computation complexity just for 2D noise. :(
I would like to use your periodic 2d simplex noise instead, but I have problems to use it in context of fractal brownian motion, ridgit multi fractals and turbulence.
This is my approach so far:
float fbm2(in vec2 pos, in int octaves, in float frequency, in float lacunarity, in float persistence) {
float currentWeight = 1.0;
float totalWeights = 0.0;
float result = 0.0;
for (int i = 0; i < MAX_OCTAVES; i++) {
if (i >= octaves) break;
result += psnoise((pos)*pow(2.0,float(i)),vec2(2.0,2.0)*pow(2.0, float(i))) * currentWeight;
totalWeights += currentWeight;
currentWeight *= persistence;
frequency *= lacunarity;
}
return result / totalWeights;
}
This works, but completly skips the frequency and lacunarity parameters.
As soon as I take frequency or lacunarity in account (ex. multiply by position like in 4D fbm) its not tileable anymore :(
So my question is: is there a way to use periodic noise and be still able to set arbitrary frequency and lacunarity?
something like:
fbm2(pos, 6, 1.0, 2.13727, 0.507123)
This is how it looks with octaves as frequency and below my approach to use the parameters:
It would be great to have these noise demos on Shadertoy, to make it easier to see them and play with them.
psrdnoise2D.glsl fails to compile (on NVidia at least) because the call to permute() on line 91 contains an implicit cast from 'float' to 'vec3' - adding a single-float overload for permute() and mod289() solves the issue.
It would be helpful to clarify in the readme whether or not the 3D and 4D simplex noise functions use the implementation covered by Perlin's U.S. Patent 6,867,776.
Currently I use the sobel operator to get the normal from the noise values, but I could skip that when I would know how to use the partial derivatives.
How is the normal calculated from dx,dy?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.