- Edited
I'd like to share a very useful script I wrote for my projects. This script uses the shader compile trick to compile material shaders ahead of time to prevent hiccups or hitching that occurs when shaders are compiled during gameplay. The shader compile problem and solution are explained in the video here:
The attached script automates implementing the solution explained in the video.
Instructions:
For each material, add one MeshInstance or Particles object that uses the material to a group called "materials". You can add nodes to a group by selecting the node and clicking the "Node" tab in the top right corner. Adding multiple nodes with the same material to the group is fine but will waste resources.
Add a node as a direct child of the camera node.
Assign the attached script: shaderCompile.gd script to the node.
This script assumes the existence of a top-level node called "World" which all scene objects reside in. Change this name as necessary for your project.
There's two variables to play with. existFrames is the number of frames which go by until the quad mesh is hidden. Set this to a number between 1 and 5. verticalDisplacement is the vertical distance of the quad mesh from the camera. Try tweaking both variables if you notice hiccups still occur.
Feedback is welcome.