One VertexShader output to multiple FragmentShaders?

With WebGL2, we can let one FragmentShader output multiple textures ( MRT ). But this needs write all the codes in one FragmentShader.

If I do need seperate the FragmentShader codes to multiple files, for reasons such as modulization or port other’s project to three.js. Can I run VertexShader just once and then output it’s variables(varyings) to multiple FragmentShaders?
For example, base.vert output vertexPosition to base.frag and position.frag?

No. A shader program is a combination of a single vertex and fragment shader. Meaning you need two programs (base.vert + base.frag and base.vert + position.frag).

1 Like

OK, Thanks!

I saw files named geometry-buffer-0.frag etc, may the project also render the vertex result informations to textures then used elsewhere.

Suppose i got 2 programs,how can i set the render order?like program2 render first ,then render program1

You can’t define this on program level. You can only control the render order of 3D objects via Object3D.renderOrder.

1 Like

Thanks!man