Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It almost depends of what you are meaning.</p> <p>Branching in a shader program affect performances in GPU terms: if your vertex arrays are very long, I would avoid branching; instead use preprocessor and link multiple different programs.</p> <p>Having a single-complex-huge shader program boost performance in CPU terms: each <em>glUseProgram</em> takes time, and you may want to call it only once (al least less).</p> <p>Are the CPU advantages greater than the GPU advantages? Answering to this question answer your question.</p> <p>...</p> <p>Personally I go with preprocessor and I avoid branching for fundamental purposes. Each shader program has well-defined interfaces, and different objects implements them; attaching different objects complete the program implementation.</p> <p>Implementing a #include directive helps a lot. Common declarations are included in different objects, and only statically accessed attributes and uniforms are effectively linked into the program.</p> <p>This is an example of a shader program of mine:</p> <pre><code>#include &lt;/Derm/Shaders/IProjectVertex&gt; #include &lt;/Derm/Shaders/Compatibility&gt; #include &lt;/Derm/Shaders/Standard/ShaderInputs&gt; #include &lt;/Derm/Shaders/Standard/IColorVertex&gt; // --- Vertex shader outputs // This shader output interface BEGIN_OUTPUT_BLOCK(FragmentShaderVaryings) // Processed vertex color vec4 ds_Color; // Processed vertex texture coordinate END_OUTPUT_BLOCK() // Vertex shader entry point void main() { // Compute transformed vertex position gl_Position = ProjectVertexPosition(ds_VertexPosition); #if defined(DS_COLOR_PER_VERTEX) // Support vertex color ds_Color = ComputeVertexColor(); #endif // Support vertex texturing #if defined(DS_TEXTURE) ds_TexCoords = ds_VertexTexCoord; #endif } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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