iOS 上 ThreeJS 多纹理与 ShaderMaterial 问题

发布于 2025-01-16 02:41:39 字数 805 浏览 1 评论 0原文

我需要 Threejs 中着色器的帮助。 我有一架飞机,必须混合 10 种不同的纹理;现在我使用 ShaderMaterial 并传递接下来用于组合的所有纹理。这是我的片段着色器代码,

vec3 CFull = texture2D(tFull, vUv).rgb;
vec3 CIndustria = texture2D(tIndustria, vUv ).rgb;
vec3 CCave = texture2D(tCave, vUv).rgb;
vec3 CRifiuti = texture2D(tRifiuti, vUv).rgb;
vec3 CEdile = texture2D(tEdile, vUv).rgb;
vec3 CEventi = texture2D(tEventi, vUv).rgb;
vec3 CMarine = texture2D(tMarine, vUv).rgb;
vec3 COil = texture2D(tOil, vUv).rgb;
vec3 CStrade = texture2D(tStrade, vUv).rgb;
vec3 CVerde = texture2D(tVerde, vUv).rgb; 

c = CFull * CIndustria * CCave * CRifiuti * CEdile * CEventi * CMarine * COil * CStrade * CVerde;
gl_FragColor = vec4(c, 1.0); 

它在 Android 或桌面上运行良好,但在 iOS 中不起作用。 如果我只使用 4/5 纹理,它也可以在 iOS 中使用...

也许它不起作用,因为太重了? 您有任何优化我的代码的建议吗? (或其他解决方案)

I need an help with shaders in Threejs.
I've a plane where i must have a mixing between 10 different texture; now I use ShaderMaterial and I pass all textures that next are used for combining. Here my Fragment Shader code

vec3 CFull = texture2D(tFull, vUv).rgb;
vec3 CIndustria = texture2D(tIndustria, vUv ).rgb;
vec3 CCave = texture2D(tCave, vUv).rgb;
vec3 CRifiuti = texture2D(tRifiuti, vUv).rgb;
vec3 CEdile = texture2D(tEdile, vUv).rgb;
vec3 CEventi = texture2D(tEventi, vUv).rgb;
vec3 CMarine = texture2D(tMarine, vUv).rgb;
vec3 COil = texture2D(tOil, vUv).rgb;
vec3 CStrade = texture2D(tStrade, vUv).rgb;
vec3 CVerde = texture2D(tVerde, vUv).rgb; 

c = CFull * CIndustria * CCave * CRifiuti * CEdile * CEventi * CMarine * COil * CStrade * CVerde;
gl_FragColor = vec4(c, 1.0); 

It works well on Android or desktop but in iOS not work.
If i use only 4/5 texture it works also in iOS...

Maybe it doesn't work because is too heavy?
Do you have any tips to optimize my code? (or other solutions)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2025-01-23 02:41:39

WebGL 规范要求浏览器至少支持 8 个组合纹理单元。我假设您的 iOS 设备满足 8 台的最低要求,但您要求 10 台。

您可以访问 webglreport.com在您的 iOS 设备上,查找“纹理 > 最大组合纹理图像单元”以查看其最大支持量。例如,我的台式机最多允许 32 个,但我的 iPhone 的限制更低。

的只是将它们相乘,则可以使用 2D 上下文,将它们混合在一起,然后使用 THREE.CanvasTexture将分层画布转换为可在 Three.js 中使用的单个纹理

WebGL spec requires the browser to support at least 8 combined texture units. I presume your iOS device meets that minimum requirement of 8, but you're requesting 10.

You can visit webglreport.com on your iOS device and look for "Textures > Max Combined Texture Image Units" to see what its maximum support is. For example, my desktop allows up to 32, but my iPhone's limit is lower.

enter image description here

If all you're doing to the textures is multiplying them together, you could use a 2D <canvas> context, blend them together there, then use THREE.CanvasTexture to convert the layered canvas into a single texture you can use in Three.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文