Skip to content

Commit

Permalink
uv test fix: no polar uv, fbm replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
uuuulala committed Dec 17, 2024
1 parent 4149973 commit c4a4a00
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions packages/shaders/src/shaders/smoke-ring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,47 @@ export const smokeRingFragmentShader = `
#define TWO_PI 6.28318530718
#define PI 3.14159265358979323846
float rand(vec2 n) {
return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float noise(vec2 n) {
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}
float fbm(vec2 n) {
float total = 0.0, amplitude = .4;
for (int i = 0; i < 12; i++) {
total += noise(n) * amplitude;
n *= 1.8;
amplitude *= 0.6;
}
return total;
}
float random (in vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
// Based on Morgan McGuire @morgan3d
// https://www.shadertoy.com/view/4dS3Wd
float noise (in vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
// Four corners in 2D of a tile
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
#define OCTAVES 10
float fbm (in vec2 st) {
// Initial values
float value = 0.0;
float amplitude = .5;
float frequency = 0.;
//
// Loop of octaves
for (int i = 0; i < OCTAVES; i++) {
value += amplitude * noise(st);
st *= 2.;
amplitude *= .5;
}
return value;
}
void main() {
Expand All @@ -65,6 +89,6 @@ export const smokeRingFragmentShader = `
float noise_left = fbm(uv + vec2(0., t));
gl_FragColor = vec4(vec3(noise_left, noise_left, 0.), 1.);
gl_FragColor = vec4(vec3(noise_left, 0., 0.), 1.);
}
`;

0 comments on commit c4a4a00

Please sign in to comment.