Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you mean to run several shaders in a single render pass, like so (example pulled from thin air):</p> <ol> <li>Vertex color</li> <li>Texture</li> <li>Lighting</li> <li>Shadow</li> </ol> <p>...each stage attached to a single <code>WebGLProgram</code> object, and each stage with its own <code>main()</code> function, then no, GLSL doesn't work this way.</p> <p>GLSL works more like C/C++, where you have a single global <code>main()</code> function that acts as your program's entry point, and any arbitrary number of libraries attached to it. The four examples above could each be a separate "library," compiled on its own but linked together into a single program, and invoked by a single <code>main()</code> function, but they may not each define their own <code>main()</code> function, because such definitions in GLSL are shared across the entire program.</p> <p>This unfortunately requires you to write separate <code>main()</code> functions (at a minimum) for every shader you intend to use, which leads to a <em>lot</em> of redundant programming, even if you plan to reuse the libraries themselves. That's why I ended up writing a glorified string mangler to manage my GLSL libraries for <a href="http://blog.jaxgl.com/what-is-jax" rel="nofollow">Jax</a>; I'm not sure how useful the code will be outside of my framework, but you are certainly free to take a look at it, and make use of anything you find helpful. The relevant files are:</p> <ul> <li><a href="https://github.com/sinisterchipmunk/jax/blob/b64d3c92bc2da27898e448f1ad38d683ed0b5e82/lib/assets/javascripts/jax/shader.js.coffee" rel="nofollow">lib/assets/javascripts/jax/shader.js.coffee</a></li> <li><a href="https://github.com/sinisterchipmunk/jax/blob/b64d3c92bc2da27898e448f1ad38d683ed0b5e82/lib/assets/javascripts/jax/shader/program.js.coffee" rel="nofollow">lib/assets/javascripts/jax/shader/program.js.coffee</a></li> <li><a href="https://github.com/sinisterchipmunk/jax/blob/b64d3c92bc2da27898e448f1ad38d683ed0b5e82/spec/javascripts/jax/shader_spec.js.coffee" rel="nofollow">spec/javascripts/jax/shader_spec.js.coffee</a> (tests and usage examples)</li> <li><a href="https://github.com/sinisterchipmunk/jax/blob/b64d3c92bc2da27898e448f1ad38d683ed0b5e82/spec/javascripts/jax/shader/program_spec.js.coffee" rel="nofollow">spec/javascripts/jax/shader/program_spec.js.coffee</a> (more tests and usage examples)</li> </ul> <p>Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload