This section covers creating custom visual effect processes and nodes.
See score::gfx and Gfx namespace documentation beforehand.
Creating a custom node
To create a custom node, one must inherit from score::gfx::Node and score::gfx::NodeRenderer. A good example is score::gfx::TexgenNode which generates a texture on the CPU from a C++ function.
The process is as follows :
- Define the material of the node in a struct:
The struct must respect GLSL std140 rules; sometimes additional explicit padding is needed even with pragma pack.
- Add matching ports in the constructor:
- Write the shaders for your node (see ShaderConventions).
For instance, for the above definition, the material_t UBO would look like this:
A sampler would also be created:
- Create a renderer class which inherits from score::gfx::GenericNodeRenderer (to use the score conventions which simplify the most common things) or score::gfx::NodeRenderer (to have a complete control on resources, pipelines, etc).
See score::gfx::ImagesNode and score::gfx::TexgenNode for simple examples using the "pre-made" classes, and score::gfx::ISFNode or score::gfx::VideoNode for more complex example which do implement everything.
Once that is done, the only remaining thing is to create a score process which will allow the node to be used in the score.
Shader conventions
If one inherits from the base classes score::gfx::Node and score::gfx::NodeRenderer, there is no restriction: shaders can have whatever UBOs, samplers, attributes, ... that the node author wishes. Of course the mesh used must be compatible with the shader attributes.
On the other hand, one may opt-in to the conventions of score, which allows to use the simplified score::gfx::buildPipeline and score::gfx::DefaultShaderMaterial utilities.
In that case, vertex shaders shall follow this template:
Fragment shaders shall follow this template:
Video decoders
If one wants to add support for GPU decoding of some video frame data, the it is sufficient to inherit from score::gfx::GPUVideoDecoder.
The available decoders are then listed in VideoNodeRenderer::createGpuDecoder() ; the AVFormat / fourcc is used to create the correct decoder for the input format.
See for instance score::gfx::YUV420Decoder for an example of GPU decoding of tri-planar YUV420 video.