Passing data through tessellation shaders to the fragment shader

前端 未结 1 1947
半阙折子戏
半阙折子戏 2021-02-08 17:14

I\'m a bit confused about how the shader pipeline works with regards to passing data through each stage.

What I\'m trying to do is pass color data that is loaded in the

1条回答
  •  野性不改
    2021-02-08 18:03

    This is not surprising, TCS inputs/outputs must be in the form:

    in  vec4 vs_color  [];
    out vec4 tcs_color [];
    

    or in input/output blocks that also take the form of unbounded arrays:

    in CustomVertex {
      vec4 color;
    } custom_vs [];
    
    out CustomVertex {
      vec4 color;
    } custom_tcs [];
    

    For a little bit of context, this is what a TCS / geometry shader sees as the output from vertex shaders:

    in gl_PerVertex
    {
      vec4  gl_Position;
      float gl_PointSize;
      float gl_ClipDistance [];
    } gl_in [];
    

    To keep things as simple as possible, I will avoid using interface blocks.

    Instead, I will introduce the concept of per-patch inputs and outputs, because they will further simplify your shaders considering the color is constant across the entire tessellated surface...

    Modified Tessellation Control Shader:

          in  vec4 vs_color [];
    patch out vec4 patch_color;
    
    ...
    
      patch_color = vs_color [gl_InvocationID];
    

    Modified Tessellation Evaluation Shader:

    patch in  vec4 patch_color;
          out vec4 tes_color;
    
    ...
    
      tes_color = patch_color;
    

    With these changes, you should have a working pass-through and a slightly better understanding of how the TCS and TES stages work.

    0 讨论(0)
提交回复
热议问题