Code_for_developing_Lightworks_effects

Here we collect code to create Lightworks.fx effects.

View project on GitHub

Cross-platform compatibility

  1. In the “Techniques” section, use the default code: “… compile PROFILE …”

    Starting with Lightworks 14.5 the operating system can be identified at compile time. This allows the profile to be set to explicitly suit the operating system used.


  1. Great White wrote:

    For reference, the shader compiler on Linux :

    • Does not like variables that are declared as ‘const’
    • Prefers ‘fmod’ instead of ‘%’

    jwrl wrote:

    The reference to Linux in Great White’s answer can also be taken to include OS-X.


  1. Application of variables into Cg standard functions:
    Example: lerp (a, b, w); Quote Nvidia’s Cg reference manual, page 729:

    a and b are either both scalars or both vectors of the same length.

    If you do not there will be cross-platform problems. The way that the Windows compiler and the Mac/Linux compilers handle this type of implicit variable conversion differs and you can get unpredictable results if you rely on it.
    For an example and the solution, see lwks.com post #146013.


  1. Avoid nested and incomplete comment delimiters.
    The following erroneous example contains 3 opening comment delimiters, but only 2 closing comment delimiters:
    /* Comment 1 /* Comment 2 */ /* Comment 3 */
    This is not compiled on Linux and OSX systems. On Windows systems, the second, superfluous delimiter is simply ignored.
    The following versions will fail on all systems.
    /* Comment 1 */ /* Comment 2 */ /* Comment 3
    /* Comment 1 */ /* Comment 2 */ Comment 3 */

  1. Only one sampler should be created per texture.
    While it’s possible to overload sampler declarations in Windows it isn’t on the other two platforms supported by Lightworks, and doing so will break your effect in them.

  1. Sampler settings:
    The sampler addressing mode Clamp should not be used because this behaves differently on Linux/Mac systems to the way that it does on Windows systems. For Linux/Mac you should use ClampToEdge instead, and starting with Lightworks 14.5 the Windows compiler has been modified so that you can use it there too. This makes that addressing mode fully cross-platform on 14.5 and up.

    Obviously this will not work on versions of Lightworks prior to 14.5. For those cases separate Windows versions using Clamp addressing instead of ClampToEdge must be created for the effect to compile.


  1. Sampler selection by if(…. else:
    You cannot assign a value to a sampler inside a function or shader in Linux/Mac code.
    This refers to the selection of the sampler to be used, not the parameters.
    Instead, use separate tex2D(… calls for the relevant samper.
    For details, see lwks.com post # 152430.

  1. Avoid function calls outside of shaders.
    Example:
    Avoid defining global variables in this way: float _rt3 = 1.0 / sqrt( 3.0 );

    Use the result of the calculation instead: float _rt3 = 0.57735;
    Or if you don’t need a variable: #define RT3 0.57735