godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.22k stars 20.23k forks source link

Game stutters each time new material appears on camera #18265

Closed ghost closed 6 years ago

ghost commented 6 years ago

59b8166 Antergos x86_64

OpenGL ES 3.0 Renderer: Mesa DRI Intel(R) Haswell

$ lspci
00:02.0 VGA compatible controller: Intel Corporation 4th Generation Core Processor Family Integrated Graphics Controller (rev 06)
01:00.0 3D controller: NVIDIA Corporation GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M] (rev a1)

Issue description:

Expected: camera to rotate smoothly Happened: Game stutters each time new material appears on camera (only for the first time)

GIF recording is kinda misleading. Video here: https://youtu.be/EKV-0EJcJUM as you can see the 2nd time the camera rotates it's smoother.

(Number shown is frame count, not frame rate :P)

peek 2018-04-18 11-15

Steps to reproduce:

  1. add several MeshInstances with QuadMesh
  2. assign a unique ShaderMaterial for each one
  3. change the view so that it appears on screen one at a time

Minimal reproduction project:

issue.zip

Edit: how it looks in the profiler. It takes roughly a second to render that frame. image

Megalomaniak commented 6 years ago

This is likely shader compilation. GLSL/HLSL shaders are runtime compiled.

Heres an interesting answer on stack overflow

akien-mga commented 6 years ago

Duplicate of/related to #17263.

DEF7 commented 6 years ago

This also happens with particle systems when they first spawn, I imagine for the same or similar reasons. Isn't this perfectly fixable with preload() called in _ready()? Or will Godot only actually load/compile a material's shader when it actually is expected to use it for rendering? I can see this making more sense in a large game where it needs to unload/reload textures/shaders dynamically, but only if it were to do so quietly and smoothly in a threaded fashion without blocking the main update cycle.

Zireael07 commented 6 years ago

Particle systems are mentioned in the linked issue, #17263

ghost commented 6 years ago

Duplicate of #13954