aconstlink / natus

[Discontinued] Software Framework for Audio/Visual/Interactive Real-Time Applications
https://aconstlink.de
MIT License
0 stars 0 forks source link

GLSL Interface Blocks #330

Closed aconstlink closed 1 year ago

aconstlink commented 1 year ago

The code generator needs to use interface blocks what was finally required by the geometry shader nsl issue (#327). This is mainly due to the fact that a geometry shader processes primitives and I found it more plausible to use the array version of the named interface block than making every varying an array.

So we have this

// in vertex shader
out vec4 xyz ;
out vec3 st ;

// in geometry shader
in vec4 xyz[] ;
in vec3 st[] ;

versus this

// in vertex shader
out vs_to_gs
{
  vec4 xyz ;
  vec3 st ;
} output ;

// in geometry shader
in vs_to_gs
{
  vec4 xyz ;
  vec3 st ;
} input ;

I find the second version very more pleasing and might be even required in certain situations ( I read in the books ).

Anyways, this also imposes other issues with streamout and passing the freaking position around... Very annoying.

In GLSL the position is passed around by gl_Position which is not very systematic. In HLSL this is handled by bindings which makes is easy to pass the position from shader stage to stage. Nsl also uses binding points and those binding points play well with HLSL but not with GLSL. So this need to be handled also.

aconstlink commented 1 year ago

Many detail work here. Need to distinguish a lot between shader stages. If transform feedback is used, the varying need to be prefixed by the interface blocks' name.

out interface_block_name
{
  vec4 xyz ;
} output ;

output.xyz = ...

Need to be told to GL (glTransformFeedbackVaryings) like so interface_block_name.xyz and not output.xyz in order to capture it. In HLSL and Dx this is handled by the binding so the name of the variables are irrelevant. The hlsl generator already works with hlsl input/output structs anyways...