Effect language

    • correspond to a unique shader class
    • ShaderMixinSource mix several , set preprocessor values, define compositions
    • ShaderArraySource are used for arrays of compositionsThis method produces shaders at runtime. However, many platforms don't support HLSL and have no ability to compile shaders at runtime. Additionally, the approach doesn't benefit from the reusability of mixins.

    Many shaders are variations or combinations of pre-existing shaders. For example, some meshes cast shadows, others receive them, and others need skinning. To reuse code, it's a good idea to select which parts to use through conditions (eg "Skinning required"). This is often solved by "uber shaders": monolithic shaders configured by a set of preprocessor parameters.

    Xenko offers the same kind of control, keeping extensibility and reusability in mind. The simple code blocks defined by shader classes can be mixed together by a shader mixer. This process can use more complex logic, described in Xenko Effect (*.xkfx) files.

    An .xkfx file is a small program used to generate shader permutations. It takes a set of parameters (key and value in a collection) and produces a ready to be compiled.

    An example .xkfx file:

    Add a mixin

    The syntax is similar to C#. The following rules are added:

    • When you use parameter keys, add them using . If you don't, keys are treated as variables.

    The parameters behave like any variable. You can read and write their value, compare their values, and set template parameters. Since some parameters store mixins, they can be used for composition and inheritance, too.

    Custom parameters

    Note

    Even if they're defined in the XKFX file, don't forget the statement when you want to use them.

    To add a composition, assign the composition variable to your mixin with the syntax below.

    Partial effects

    You can also break the code into sub-mixins to reuse elsewhere with the syntax below.

    You can use the mixin like any other mixin in the code.