Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wgsl Bug on safari / iOS #30463

Open
Makio64 opened this issue Feb 5, 2025 · 3 comments
Open

Wgsl Bug on safari / iOS #30463

Makio64 opened this issue Feb 5, 2025 · 3 comments

Comments

@Makio64
Copy link
Contributor

Makio64 commented Feb 5, 2025

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.. )

Image Image
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

  1. try this snoise on safari/ios

Code

X

Live example

X

Screenshots

X

Version

r173

Device

Mobile

Browser

No response

OS

No response

@sunag sunag added Needs Investigation TSL Three.js Shading Language labels Feb 5, 2025
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 6, 2025

Live example: https://jsfiddle.net/ndsm7qLf/1/

I was not able to reproduce the issue on macOS 15.3 with Safari 18.3. Maybe the issue is exclusive to iOS? Or maybe you have implemented something different in your app? Does the fiddle work on your devices?

@Makio64
Copy link
Contributor Author

Makio64 commented Feb 6, 2025

@Mugen87 got the same error on your fiddle :

  • macbook m3 pro max 15.1
    --- safari 18.1 -> not working
    --- safari 18.2 tech preview -> working
  • ios
    --- beta 18.2 not working
    --- beta 18.3 not working

cc @mwyrzykowski

@Makio64
Copy link
Contributor Author

Makio64 commented Feb 13, 2025

@Mugen87 I confirm it works on macOs 15.3

@Mugen87 Mugen87 added Browser Issue and removed Needs Investigation TSL Three.js Shading Language labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants