自定义着色器材质需要永久初始化? [英] Custom shader material taking forever to initialize?

查看:75
本文介绍了自定义着色器材质需要永久初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在three.js中进行了raymarched项目一年多了,并且随着复杂性的增加,初始化时间也增加了.现在,在浏览器中加载项目可能需要40秒钟以上的时间,但是加载后的运行速度为+ 60fps.我已经通过性能测试找到了罪魁祸首,并且似乎挂在了三库中的InitMaterial函数上.有人对导致此挂断的原因有任何想法吗?我个人认为这可能是由于我们在着色器中使用的制服数量过多,因为其中有很多制服.

I've been working on a raymarched project in three.js for a little over a year now and as the complexity has increased so has the initialization time. It can now take over 40 seconds to load the project in browser however once loaded runs at +60fps. I've tracked down the culprit function through performance tests and it seems to get hung up on the InitMaterial function within three's library. Does anyone have any idea as to what could be causing this hangup? Personally I believe it could be due to the amount of uniforms we use in the shader as there are quite a few of them.

您可以在此处找到有问题的代码.请注意,globalsinclude.glsl是制服列表所在的位置.

You can find the code in question here. Note that the globalsinclude.glsl is where the list of uniforms is.

推荐答案

这通常是Windows上DirectX的问题.我怀疑如果您在Linux或Mac上尝试使用同一页面,或者在Windows上使用--use-angle=gl启动Chrome,则会看到时间的减少.

This is a problem in general with DirectX on Windows. I suspect if you try the same page on Linux or Mac or start Chrome with --use-angle=gl on Windows you'll see the time drop.

例如,您可以尝试这个可笑的着色器.在OpenGL上编译大约需要3秒钟,但是在DirectX中,浏览器可能会确定它花费的时间太长并重置GPU进程.

As an example you can try this ridiculous shader. It takes about 3 seconds to compile on OpenGL but in DirectX the browser will likely decide it's taking too long and reset the GPU process.

对于这个问题,浏览器无能为力,因为它主要在Microsoft法庭上进行.微软为本地游戏设计了DirectX.本机游戏可以离线编译着色器. Web无法做到这一点,因为它们是传递给驱动程序的不透明二进制文件,并且可能充满漏洞.

There isn't much a browser can do about that issue as it's mostly in Microsoft's court. Microsoft designed DirectX for native games. Native games can compile shaders offline. The Web can't do that because they are opaque binaries passed to the driver and could be full of exploits.

已经有关于将异步着色器编译功能添加到WebGL的讨论.着色器仍将花费40秒进行编译,只是不会阻塞页面.在这一点上虽然不太可能发生.

There's been talk about adding asynchronous shader compilation functions to WebGL. The shader would still take 40 seconds to compile it just wouldn't block the page. At this point though that's unlikely to happen.

我唯一可以建议的就是简化着色器.如果您有循环,可以将它们拆开,看看是否有帮助.

The only thing I can suggest is simplify your shaders. If you have loops maybe unwrap them and see if that helps.

这篇关于自定义着色器材质需要永久初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆