-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Closed
Labels
Milestone
Description
Description
I ported the ashima snoise3 using wgslFn, it works well on chrome but bug in the parsing on safari mac / iOS ( wkwebview / chrome / safari / etc.. )
import { code, wgslFn } from "three/tsl"
export default wgslFn( `fn snoise(v: vec3<f32>) -> f32 {
let C: vec2<f32> = vec2<f32>(0.16666667, 0.33333334);
let D: vec4<f32> = vec4<f32>(0., 0.5, 1., 2.);
var i: vec3<f32> = floor(C.y * (v.x + v.y + v.z) + v);
let x0: vec3<f32> = C.x * (i.x + i.y + i.z) + (v - i);
let g: vec3<f32> = step(x0.yzx, x0);
let l: vec3<f32> = (1. - g).zxy;
let i1: vec3<f32> = min(g, l);
let i2: vec3<f32> = max(g, l);
let x1: vec3<f32> = x0 - i1 + C.x;
let x2: vec3<f32> = x0 - i2 + C.y;
let x3: vec3<f32> = x0 - D.yyy;
i = ((i) % (289.));
let p: vec4<f32> = permute(permute(permute(i.z + vec4<f32>(0., i1.z, i2.z, 1.)) + i.y + vec4<f32>(0., i1.y, i2.y, 1.)) + i.x + vec4<f32>(0., i1.x, i2.x, 1.));
let ns: vec3<f32> = 0.14285715 * D.wyz - D.xzx;
let j: vec4<f32> = -49. * floor(p * ns.z * ns.z) + p;
let x_: vec4<f32> = floor(j * ns.z);
let x: vec4<f32> = x_ * ns.x + ns.yyyy;
let y: vec4<f32> = floor(j - 7. * x_) * ns.x + ns.yyyy;
let h: vec4<f32> = 1. - abs(x) - abs(y);
let b0: vec4<f32> = vec4<f32>(x.xy, y.xy);
let b1: vec4<f32> = vec4<f32>(x.zw, y.zw);
let sh: vec4<f32> = -step(h, vec4<f32>(0.));
let a0: vec4<f32> = b0.xzyw + (floor(b0) * 2. + 1.).xzyw * sh.xxyy;
let a1: vec4<f32> = b1.xzyw + (floor(b1) * 2. + 1.).xzyw * sh.zzww;
var p0: vec3<f32> = vec3<f32>(a0.xy, h.x);
var p1: vec3<f32> = vec3<f32>(a0.zw, h.y);
var p2: vec3<f32> = vec3<f32>(a1.xy, h.z);
var p3: vec3<f32> = vec3<f32>(a1.zw, h.w);
let norm: vec4<f32> = inverseSqrt(vec4<f32>(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 = p0 * (norm.x);
p1 = p1 * (norm.y);
p2 = p2 * (norm.z);
p3 = p3 * (norm.w);
let m: vec4<f32> = max(vec4(0.6) - vec4<f32>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), vec4(0.));
return 0.5 + 12. * dot(m * m * m, vec4<f32>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}
`, [
code( `fn permute(x: vec4<f32>) -> vec4<f32> {
return (((x * 34. + 1.) * x) % (289.));
} ` )
] )
I then port it using pure tsl and it worked but i think there is something to double check here.
Reproduction steps
- try this snoise on safari/ios
Code
X
Live example
X
Screenshots
X
Version
r173
Device
Mobile
Browser
No response
OS
No response