Skip to content

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

Merged
merged 4 commits into from
Apr 20, 2017
Merged

Conversation

gero3
Copy link
Contributor

@gero3 gero3 commented Mar 8, 2017

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.

@@ -1036,6 +1036,47 @@ function WebGLRenderer( parameters ) {
return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );

}

this.compileMaterials = function(scene, camera){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just compile?

Copy link
Contributor Author

@gero3 gero3 Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been changed.

@mrdoob
Copy link
Owner

mrdoob commented Mar 10, 2017

Also, would it be possible to do a simpler example? The function itself looks great btw!

@gero3
Copy link
Contributor Author

gero3 commented Mar 10, 2017

The example is simplified and I've also added documentation.

@WestLangley
Copy link
Collaborator

WestLangley commented Mar 10, 2017

Is it a problem that

renderer.info.programs.length

produces different results depending on pre-load vs. no-pre-load?

@gero3
Copy link
Contributor Author

gero3 commented Mar 10, 2017

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.

@brianchirls
Copy link
Contributor

Looks like this would solve #9887. Thanks for working on it.

@Astrak
Copy link
Contributor

Astrak commented Mar 11, 2017

Indeed my issue was a duplicate, I close it. Thank you for your work on this.

@gero3
Copy link
Contributor Author

gero3 commented Mar 16, 2017

Any news on this PR??

@mrdoob mrdoob merged commit c6bda65 into mrdoob:dev Apr 20, 2017
@mrdoob
Copy link
Owner

mrdoob commented Apr 20, 2017

Sorry for the delay 😇

@mrdoob
Copy link
Owner

mrdoob commented Apr 20, 2017

Thanks!

@brianchirls
Copy link
Contributor

Thank you, guys! I really need this.

@brianchirls
Copy link
Contributor

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?

@Astrak
Copy link
Contributor

Astrak commented Apr 22, 2017

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.

@gero3 gero3 deleted the preloadShaders branch January 2, 2018 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants