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

[WebGL2] A simple scene takes 45 seconds to load #21957

Closed
ikelaiah opened this issue Sep 10, 2018 · 36 comments
Closed

[WebGL2] A simple scene takes 45 seconds to load #21957

ikelaiah opened this issue Sep 10, 2018 · 36 comments

Comments

@ikelaiah
Copy link

ikelaiah commented Sep 10, 2018

Godot version:
3.0.6 64-bit

OS/device including version:
Windows 10 64-bit
HP Folio 9480m, i5 4th gen, 8GB RAM, HD4400.
Firefox - 62.

Issue description:
A simple scene containing a low poly Mars with 2k color texture; it takes 45 seconds to load.
2018-09-11 08_33_03-mars demo basic

Steps to reproduce:

  1. Download and open my project file
  2. Export as HTML
  3. Execute the main HTML file
  4. Wait... takes about 45 seconds to load.

Minimal reproduction project:
I attached the project file here.
mars-basic.zip

@ghost
Copy link

ghost commented Sep 10, 2018

Can confirm, took about 45 seconds here as well, very odd that it's so exact.

@ikelaiah
Copy link
Author

I did another test by opening the project in Godot 3.1 alpha, exported to HTML5, and I waited for 45 seconds as well before I see the planet.
Perhaps I've done something amiss.

@Calinou
Copy link
Member

Calinou commented Sep 11, 2018

Does it load faster if you create a WorldEnvironment and set an empty Environment (with no sky)? Perhaps the slowness is caused by panorama generation.

Also, try replacing the planet texture with a single color to see if it's related to texture loading.

@ikelaiah
Copy link
Author

A WorldEnvironment and set an empty Environment (with no sky - solid colour) loads in 2 seconds.
A WorldEnvironment and set an empty Environment (with no sky - solid colour) with the planet using spatial material coloured white, loads in 45 seconds.
A WorldEnvironment and set an empty Environment (with no sky - solid colour) with the planet without using spatial material, loads in 45 seconds.

@ikelaiah
Copy link
Author

A WorldEnvironment and set an empty Environment (with no sky - solid colour) with a spherical mesh instance without using spatial material, loads in 45-50 seconds.

@Zireael07
Copy link
Contributor

So the mesh accounts for ~40 seconds of those 45? What happens if you place a different mesh, e.g. a simple cube?

@ikelaiah
Copy link
Author

Removed the new SphereMesh and replaced it with a new CubeMesh (no spatial material). ~45 secs.

@muiroc
Copy link
Contributor

muiroc commented Sep 11, 2018

Last month I was invenstigating webgl performance and I'm pretty sure it is libangle taking forever to link some shaders

with firefox try typing "about:config" in the url bar then search for "webgl.disable-angle" and set it to true, then reload the page

of course its not a solution, it's only to check if it is the same issue

edit:
attached the test (non godot) project, maybe it could be useful, (tested only firefox)
opening index.html should take a long time to load, (there will be some debug info in the console)
you can edit main.js to load your own shaders
godot_shaders_webgl_perf.zip

to obtain the shader source i used a custom build, the text was printed to the console when it took too much to compile/link, if you do the same be aware when copying the text that similar lines gets collapsed into one (for example multiple endifs directives)

@ikelaiah
Copy link
Author

@muiroc Wow! I did exactly as you said, the loading time is only 3s.

However, I'm getting WebGL context lost everytime I scale the browser window.

@muiroc
Copy link
Contributor

muiroc commented Sep 11, 2018

I see, in my case (3.1) fullscreen works with firefox 62, but hdr rendering is not working, Chrome loses context before finishing loading (weird since both uses angle? dunno)

Are you getting some interesting errors in the console? in chrome i had some max varying vectors and framebuffer incomplete error messages in the console before the context loss

the equivalent of "webgl.disable-angle" in Chrome is to create a shortcut and add the --use-gl=desktop command line option

another factor in laptops is if the browser is using the integrated or dedicated video card (optimus)...

btw I didn't investigate further because I've got an ANCIENT geforce 635m with old drivers so i didn't really expect much from it (even if it works in desktop gl)

instead i was waiting to see what happens with the gles2 backend (im using very light 3d, and can get away with vertex lighting (which even in 3.1 compiles kind of fast on angle and crappy hardware like mine (apart frome the default material which is a complex spatial and still takes 45 secs so it would be nice to override... ok enough parentheses)))

Also, while i'm using firefox, considering the browsers marketshare, chrome should be the reference target

@ikelaiah
Copy link
Author

Initially I was aiming for Chrome, but Chrome lost WebGL context even before the loading was completed. Like you, I also ended up with bunch of errors on Chrome and that's why I ended up with Firefox as it shows something... after 45 seconds.

HD4400 is the only thing I have on this laptop, so yeah, unable to test with a dedicated graphics card.

I agree. Considering the browsers marketshare, Chrome should be the reference target.

@leonkrause
Copy link
Contributor

This has been an issue ever since 3.0 with WebGL 2 on Windows, in fact we have numerous issues describing such long freezes: #16050 #19089 #19093

For 3.1 I hope we can switch the default to WebGL 1, where shader compilation is less of an issue.

Until then you can manually change to WebGL 1 in the project settings, set rendering/quality/driver/driver_name to GLES2 (i.e. WebGL 1). You can use the Override for... button at the top to set this only for web export.

Leaving this open for visibility.

@ikelaiah
Copy link
Author

I did a test, same project file using Godot 3 Alpha 1 and exported using GLES2. Nothing come up on browser but I received plenty of errors.

I attached screenshots here. I hope you'll find this useful.

2018-09-17 10_04_39-mars demo
2018-09-17 10_05_04-mars demo
2018-09-17 10_05_25-mars demo
2018-09-17 10_07_44-mars demo

@muiroc
Copy link
Contributor

muiroc commented Sep 23, 2018

Just for the record, about GLES3 and Angle, this looks related to #14902 as setting the MAX_LIGHT_DATA_STRUCTS and MAX_REFLECTION_DATA_STRUCTS to, for example 8, allows the shader to link in about 500ms, and works also in Chrome

this is an export of the original repro case (with 397b01d)
mars-basic_exp_web_mod.zip

for now this only modifies the shader text (in index.js, check _glShaderSource at line 10474)

NOTE if in the console there are two numbers and an assertion please reload, dunno what that is, happens since I updated emsdk, even in other non godot projects (with assertions says something about FS iirc)

Another note: in my case, starting Chrome with the "--use-gl=desktop" option actually would start it in software rendering mode! You can check this and other interesting info typing "chrome://gpu" in the address bar

@ikelaiah
Copy link
Author

Confirming @muiroc findings.

The modified build loads. Initially two numbers and an assertion came up in the console.
After reloaded, the Mars appeared in 4 seconds. 45s to 4s? That's a great improvement from end-users point of view.

Thanks.

@Gliderz
Copy link

Gliderz commented Oct 30, 2018

Hello, I have the same issue here:

-A scene with 5 meshs, 3 materials, 5 textures files and 1 environnement map.
-Export as HTML
-takes about 45 seconds to load.
-I make a tons of test with 1/2 mesh, with/without material, with/without textures files, with/without environnement map..
-try in Godot 3.0.6 and Godot 3.1 alpha
-always 45 seconds to load. (no errors in debug mode)

I'm looking for the issue in google and i find this topic. I think it's the same shader loading problem.
I have dowload the mars-basic.zip and the mars-basic_exp_web_mod.zip for try to understand the issue (and the Muiroc'fix), but I'm not sure to understand the part with godot_shaders_webgl_perf.zip. I try to load the html in my web browser but nothing appear...

@muiroc ,Can you tell me more about how you obtain the shader source and how to edit main.js to load your own shaders, please?

Thanks

@muiroc
Copy link
Contributor

muiroc commented Oct 30, 2018

@Gliderz sure,

When Godot loads a shader, it needs to call glShaderSource: that function is defined in "index.js".

If you open it, you will see that its not very readable, since it is stripped of all unnecessary spaces (uglified) so first you need to reformat it (beautify/prettyprint): for example I'm using Visual Studio Code with the Beautify extension, so just open "index.js" then run a command with ctrl+shift+p, type Beautify, enter!

Now you can search for the "_glShaderSource" function (the identifiers are prefixed with an underscore), which will look like this:
(NOTE: don't mistake it with "emscripten_glShaderSource", those are functions returned by getProcAddress)

function _glShaderSource(shader, count, string, length) {
	*stuff*
}

The "shader" parameter is the glsl source code (so, not the godot shading language!).
Before passing it to GLctx (which is the WebGL Context) we can do some interesting things to it, like replacing some values!

function _glShaderSource(shader, count, string, length) {
	var source = GL.getSource(shader, count, string, length);
	source = source.replace(/(#define MAX_LIGHT_DATA_STRUCTS )(\d+)/, "$18")
	source = source.replace(/(#define MAX_REFLECTION_DATA_STRUCTS )(\d+)/, "$18")
	GLctx.shaderSource(GL.shaders[shader], source)
);

(If you need help with regexes (like I do lol) there are some cool online tools)

This is ( if iirc! ) the change used in "mars-basic_exp_web_mod" to speed up the loading, it is just replacing the number on the right of MAX_LIGHT_DATA_STRUCTS and MAX_REFLECTION_DATA_STRUCTS with an "8"

That's it, save, reload page (if using chrome hold the reload button and select the bottom option to fully reload)

WARNING: this is just an HACK that most likely WILL NOT WORK reliably!!!

Lastly to get the text, at first i printed to the console, but it is a MESS and annoying to copy paste, so in the end I just created a hidden DIV and setted its innerhtml to the shader source, but i currently cant find the code snippet!

To identify the original shader, in the godot shader just add an uniform with a name easy to search like "uniform float SHADERNAME_the_actual_shader_name;

To avoid repeating this for every export, as long as you using the same godot build/version, you can even set the index.js file as read-only, (it always gets copied as-is), or just reexport only the pck file

In general the slowdown is caused (for some shaders) by the angle library, which is used by default in Firefox and Chrome on Windows (so, a lot of users...)

godot_shaders_webgl_perf shows nothing on screen, it was just a playground to test shader modification more easily, the output is in the console

Now, I don't know what 3D features are you using, but if it is "kinda low end" it should be better to wait for GLES2 (WebGL1) bugfixing and see what happens, if i understand it correctly there are plans to remove the GLES3 (WebGL2) backend for the web build

@leonkrause leonkrause changed the title A HTML build (a simple scene) takes 45 seconds to load WebGL 2: A simple scene takes 45 seconds to load Nov 19, 2018
@Chaosus Chaosus changed the title WebGL 2: A simple scene takes 45 seconds to load [WebGL2] A simple scene takes 45 seconds to load Dec 27, 2018
@akien-mga akien-mga modified the milestones: 3.1, 3.2 Jan 23, 2019
@ikelaiah
Copy link
Author

ikelaiah commented Mar 4, 2019

Tested with Godot 3.1 Beta 6, using GLES2.
Exported to HTML5 with no issues. The scene loads in 3-4 seconds (using FireFox 65.0.2).

Tested with Godot 3.1 Beta 10, Beta 11, RC1 and Official 3.1 using GLES2.
Exported to HTML5 with no issues. The scene loads in 3-4 seconds (using FireFox 65.0.2).

@ikelaiah
Copy link
Author

It seems the issue has been resolved in Godot 3.1.
We can close this I suppose.

Many thanks to all who helped.

@akien-mga
Copy link
Member

The issue is still valid for GLES3 / WebGL 2 I think. But indeed, using GLES2 / WebGL 1 is the safer option for people planning to make web games.

@LordOdin
Copy link

LordOdin commented Apr 8, 2019

Im having some insane load times on a basic scene with a cube and a few 3D sprites with the same texture

@jknightdoeswork
Copy link

This should help #30898

@clayjohn
Copy link
Member

We are no longer working on the WebGL2 backend due to poor driver support on most systems. We recommend you use the GLES2/WebGL backend instead.

Unfortunately, that means this bug just isn't going to be fixed in GLES3/WebGL2, sorry.

@clayjohn clayjohn removed this from the 3.2 milestone Dec 18, 2019
@gnat
Copy link

gnat commented Dec 18, 2019

Correct me if I'm wrong, but won't drivers eventually catch up? Or is there some other backend beyond GLES3/WebGL2?

I don't feel like gaming on the web is going away anytime soon.

@clayjohn
Copy link
Member

They may. However we are abandoning our GLES3 backend in favour of Vulkan for 4.0. Version 3.2 is the last one to support the GLES3 backend.

Pretty much all hardware still supports WebGL1 significantly better than WebGL2. We were spending too much development effort creating hacks to appease WebGL2 when WebGL1 just works better and is faster anyway.

@nathanfranke
Copy link
Contributor

nathanfranke commented Nov 20, 2020

This won't be fixed in GLES3/WebGL2, but what about GLES2/WebGL1? This bug is most definitely still reproducible in GLES2. See my Flappy Bird Demo: https://flappy.nathan.gq/
I clocked it at 59 seconds from page load to actual gameplay. It takes less than a second to load on desktop. The performance on web is okay, but seems to be only around 30 fps compared to 4000 fps desktop.

Edit: Note that this 59 second delay only seems to be on first page load, or when cache is disabled.

@Calinou
Copy link
Member

Calinou commented Nov 20, 2020

Edit: Note that this 59 second delay only seems to be on first page load, or when cache is disabled.

Which browser are you using? Chromium-based browsers often have better WebGL performance than Firefox, especially on Linux.

@clayjohn
Copy link
Member

@nathanfranke it loads instantly on my phone. Using chrome for android.

@Calinou
Copy link
Member

Calinou commented Nov 20, 2020

It also loads instantly here in Firefox 83 on Linux. It runs at 144 FPS if the window is kept at a small size (this is a general, non-Godot-specific issue with WebGL in Firefox on Linux).

@nathanfranke
Copy link
Contributor

Very peculiar. On both firefox android and chrome android it takes unreasonably long for me.
On PC I had differing load times but at one point it was still this slow on chrome desktop.

@nathanfranke
Copy link
Contributor

Here is an example of the bug occurring on Google Chrome 86.
System info: Manjaro 20.2, GTX 960, NVidia drivers 450xx

https://youtu.be/o6dfgP4LGrQ

@clayjohn
Copy link
Member

@nathanfranke the video shows that the issue is with scene loading not with shader compiling. Shaders aren't compiled until the first frame.

You may want to open a new issue to focus on your particular problem.

@Calinou
Copy link
Member

Calinou commented Jan 10, 2022

To anyone stumbling upon this: can you try building the latest 3.x branch from source (which includes #53411) and see if the issue persists? You'll need to compile both an editor and HTML5 export template. Set the shader caching mode to Asynchronous + Cache in the Project Settings, then export the project to HTML5.

@tavurth
Copy link
Contributor

tavurth commented Jan 10, 2022

This is confirmed in 3.x (current stable @ 3.4.2 also)

https://github.com/tavurth/godot-simple-fps-camera

Pretty much all hardware still supports WebGL1 significantly better than WebGL2. We were spending too much development effort creating hacks to appease WebGL2 when WebGL1 just works better and is faster anyway.

This makes sense, but GLES3 works fine for 2D projects, this only affects 3D projects.

@OptimistPro
Copy link

Hello. I'm using godot 3.4.1 gles2. An empty project takes 45 seconds to load in html5. What could be the problem?

@Calinou
Copy link
Member

Calinou commented Jan 11, 2022

Hello. I'm using godot 3.4.1 gles2. An empty project takes 45 seconds to load in html5. What could be the problem?

This is an unrelated issue. Please open a separate issue with a minimal reproduction project attached.

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