-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
Initial version of the shader preloader #10960
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
Conversation
src/renderers/WebGLRenderer.js
Outdated
@@ -1036,6 +1036,47 @@ function WebGLRenderer( parameters ) { | |||
return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] ); | |||
|
|||
} | |||
|
|||
this.compileMaterials = function(scene, camera){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just compile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been changed.
Also, would it be possible to do a simpler example? The function itself looks great btw! |
The example is simplified and I've also added documentation. |
Is it a problem that
produces different results depending on pre-load vs. no-pre-load? |
The only reason there is a difference, is because some objects are outside the view. And for those objects the material doesn't get generated directly in without preload. Preload loads all objects in the scene, even if they are invisible on the first frame. |
Looks like this would solve #9887. Thanks for working on it. |
Indeed my issue was a duplicate, I close it. Thank you for your work on this. |
Any news on this PR?? |
Sorry for the delay 😇 |
Thanks! |
Thank you, guys! I really need this. |
A question on this for best practice and possible future improvement: As I understand it, the reason compiling shaders is janky is that it requires reading back info from the GPU, which causes a delay for sync. If you compile multiple shaders consecutively, will it have to block for multiple frames to wait for each one? Might it make more sense to batch compile all of them and then batch all the status reads together? |
Yes no render can happen if the shaders have not all compiled. You can go visit some pages at shadertoy.com that has a lot of big shaders : unless you have one of the best graphic cards, pages will freeze for a while before display. I was in need of that compile method to create an asset wrapper library, you can see the compiling step on the codepen demo. |
This is a initial version of a shader precompiler. The shaders can be precompiled with ´renderer.compileMaterials´. And the arguments are scene and camera. I've also added a small example to make check the difference between preloaded shaders and not.
This can be a solution for #10958.