Welcome, Guest
Username Password: Remember me

TOPIC: Documentation for developing Lightworks effects (Post # 1 contains summary links)

Documentation for developing Lightworks effects 3 years, 5 months ago #144463

  • khaver
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 3510
  • 3 years, 5 months ago
jwrl, your template is a very good idea. Would you mind if I use it for creating new fx files in my UserFX Manager?
Work Comp: Retired!
Home Comp: Newer! Bigger! Faster!
Send me a tip: paypal.me/4khaver

Documentation for developing Lightworks effects 3 years, 5 months ago #144486

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12887
  • 3 years, 5 months ago
No!!! All that is private, copyright, and I challenge you to lawyers at ten paces at dawn!

Of course you can. If it hadn't been for your early articles I would never have been motivated to get into this. You're more than welcome to use anything that you see here or in any of my other posted effects.

And that goes for anyone else interested enough to dabble.

By the way, when I get some free time I plan on getting into Python. Should I get reasonably competent, would you be interested in me trying to port one of your AuotIt programs to Python, thus making it cross-platform? This is of course pure speculation at this stage and may never happen, but it is something I would like to try.
Last Edit: 3 years, 5 months ago by jwrl.

Documentation for developing Lightworks effects 3 years, 5 months ago #144496

  • khaver
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 3510
  • 3 years, 5 months ago
Thanks for the template use.

Let me know when you're ready to get into Python and I'll send you my Autoit source code.
Work Comp: Retired!
Home Comp: Newer! Bigger! Faster!
Send me a tip: paypal.me/4khaver

Documentation for developing Lightworks effects 3 years, 5 months ago #144505

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12887
  • 3 years, 5 months ago
Will do. At the moment I'm re-learning Brief, which used to be my go-to programmer's editor back in the MS-DOS days.

Documentation for developing Lightworks effects 3 years, 5 months ago #144526

  • geomcd1949
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 722
  • 3 years, 5 months ago
If the United Nations operated with the same level and spirit of cooperation shown in this Forum, the world would be a beautiful place!
North Carolina, USA
Ubuntu 20.04 LTS
2x2.7 GHz E5-2680
500GB SSD and1TB HDD
64 GB DDR3 10600
Quadro K4200
~X-Keys Pro 68 key USB Jog/Shuttle controller
*Galaxy S7 with Filmic Pro*
*JVC GY-HM150*

Documentation for developing Lightworks effects 3 years, 4 months ago #144706

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4454
  • 3 years, 4 months ago
jwrl wrote:
I have saved a template file for creating effects.

Thank you!
I think this template could also be helpful to structure our documentation.


Inputs:
An example of a test effect:
//--------------------------------------------------------------//
// Inputs
//--------------------------------------------------------------//

texture In1;
texture In2;

texture OutputFromPassOne : RenderColorTarget;  

The result for the effect "Sampler test2" then looks as follows:
This image is hidden for guests. Please log in or register to see it.

"texture OutputFromPassOne" ... is not visible in the routing because the video signal (texture) comes from a pixel shader within it effect.
This is set by ": RenderColorTarget".
From which pixel shader this internal texture comes, we programmed in the "Techniques" section (more on this later in another posts "Techniques").

In order to use these inputs, we have to create the corresponding samplers.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1; || Windows 10, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || shared RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 4 months ago by schrauber.

Documentation for developing Lightworks effects 3 years, 4 months ago #144707

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4454
  • 3 years, 4 months ago
Samplers:

A code example to create samplers for the three previously programmed inputs:
EDIT:
//--------------------------------------------------------------//
// Samplers
//--------------------------------------------------------------//

sampler In1Sampler = sampler_state
{
   Texture = <In1>;
   AddressU = Border;
   AddressV = Border;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;
};


sampler In2Sampler = sampler_state
{
   Texture = <In2>;
   AddressU = Border;
   AddressV = Border;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;
};


sampler RenderedSampler = sampler_state
{
   Texture = <OutputFromPassOne>;
   AddressU = Border;
   AddressV = Border;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;
};




Sampler settings:

If your effect moves the original position of the pixels (eg zooming), then it can happen:

- that the calculation results in pixel positions outside the source textures (outside the normal range from 0 to 1).

- that pixel positions have been calculated that are not at the center of a pixel.

There are several ways the sampler should proceed in these cases.
This image is hidden for guests. Please log in or register to see it.



Here are some examples with different sampler settings.
A zoom-out effect has been used because this pixel position is used outside the texture, which makes the results of the sampler settings visible.
This test effect was used: Sampler-test2-2.zip
This effect uses only one input, but different samplers.



As a comparison basis, initially without effect:
This image is hidden for guests. Please log in or register to see it.




Now with effect, and different sampler settings:

Border:
sampler BorderSampler = sampler_state
{
   Texture = <In1>;
   AddressU = Border;
   AddressV = Border;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;
};
The result.
This image is hidden for guests. Please log in or register to see it.

Note that the zoom out does not happen in the sampler, but was programmed in the program section "Shaders" ( see the effect file)

If the pixel you are looking for is outside the range of 0 to 1, then the Border setting causes the black color to be used.
float4 (0.0,0.0,0.0,0.0)

Because the alpha channel is 0.0, these pixels could easily be replaced in subsequent calculations. Example:
:pinch: Warning: Spoiler!


Filter = Linear:
This causes the sampler to mix adjacent pixels when looking for a position between the centers of those pixels.



Clamp:
For more information click on "Spoiler"
:pinch: Warning: Spoiler!


Horizontal Border and vertical Clamp:
:pinch: Warning: Spoiler!


Mirror:
:pinch: Warning: Spoiler!

Wrap:
:pinch: Warning: Spoiler!
Attachments:
  • Attachment This attachment is hidden for guests. Please log in or register to see it.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1; || Windows 10, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || shared RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 4 months ago by schrauber.

Documentation for developing Lightworks effects 3 years, 4 months ago #144742

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12887
  • 3 years, 4 months ago
You beat me to it, schrauber! I was preparing a document with examples. Then I saw yours! Yours is more complete than mine was going to be anyway, although the one thing that I covered and that you missed was what the default conditions are when no explicit declaration of addressing or filtering is made.

The declaration "sampler VidSampler = sampler_state { Texture = <Video>; }" can have two different results depending on the type of texture used for "Video". If the texture is a simple input the default state appears to be "Clamp/Linear". If it's a RenderColorTarget, the default appears to be "Wrap/Linear". I used that characteristic in a recent effect to optionally display multiple versions of the result.

That's the way that it works in Windows, anyway. I don't know whether the same applies to the Linux/Mac environment. If in doubt, declare.

[EDIT] The settings for MinFilter in Cg can be Linear, LinearMipMapLinear, LinearMipMapNearest, Nearest, and Point. I believe that only Linear, Nearest and Point are supported by the Lightworks compiler. Those are also the only allowed settings for MagFilter, but Nearest cannot be used with MipFilter. The "safest" setting is Linear. I'll set up a test later today to confirm the actions of Nearest and Point.
Last Edit: 2 years, 11 months ago by jwrl.

Documentation for developing Lightworks effects 3 years, 4 months ago #144748

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12887
  • 3 years, 4 months ago
One more thing: when declaring a shader the form below can be used with multiple inputs.

float4 ps_main (float2 xy1 : TEXCOORD1, float2 xy2 : TEXCOORD2) : COLOR

In this case xy1.xy will apply to the first texture declared, and xy2 the second. In schrauber's example above, that would be In1 and In2 respectively. It isn't essential that you do that though, unless you have a very good reason to do so. The form below will usually work just as well.

float4 ps_main (float2 uv : TEXCOORD1) : COLOR

With that declaration uv.xy could be used to access both In1 and In2.

Finally, you can also pass parameters other than texture coordinates to your shaders. Here's an example from my SuperBlur effect. This does five passes through the same shader, each time with different parameters.

float4 ps_main (float2 uv : TEXCOORD1, uniform sampler blurSampler, uniform float blurRadius) : COLOR
Last Edit: 1 year, 7 months ago by jwrl.

Documentation for developing Lightworks effects 3 years, 4 months ago #144749

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4454
  • 3 years, 4 months ago
jwrl wrote:
... what the default conditions are when no explicit declaration of addressing or filtering is made.

I also noticed that it is partly random on my computer, depending on which settings were used in previous effects or passages.
The safest seems to always declare the settings for each sampler, even if many effects work only with unchanged pixel positions.

jwrl wrote:
The settings for MinFilter in Cg can be Linear, LinearMipMapLinear, LinearMipMapNearest, Nearest, and Point. I believe that only Linear, Nearest and Point are supported by the Lightworks compiler. Those are also the only allowed settings for MagFilter, but Nearest cannot be used with MipFilter. The "safest" setting is Linear. I'll set up a test later today to confirm the actions of Nearest and Point.

Yes, we should also write something for the different filter settings.
I have some knowledge gaps.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1; || Windows 10, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || shared RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 4 months ago by schrauber.

Documentation for developing Lightworks effects 3 years, 4 months ago #144760

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4454
  • 3 years, 4 months ago
jwrl wrote:
float4 ps_main (float2 uv : TEXCOORD) : COLOR

Interesting, I've now tried and it seems to work.
I have tested it for the time being only with one input, whether the texture works in principle.
Is this something other than TEXCOORD0 which also creates a texture without input?
However, I noticed with TEXCOORD0 some inaccuracies with horizontal lines.

jwrl wrote:
With that declaration uv.xy could be used to access both In1 and In2.
Do you mean uv.x or uv.y to manipulate one-dimensional variable shares?
The meaning of uv.xy I do not understand.

My suggestion would be that textures and their assignment to the inputs, under the heading "shaders" thematize.

jwrl wrote:
...
float4 ps_main (float2 uv : TEXCOORD1, uniform sampler blurSampler, uniform float blurRadius) : COLOR
Yes, something that we should address under the heading "Techniques" again ...

Now I must sleep .. before the sun rises here.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1; || Windows 10, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || shared RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 4 months ago by schrauber.

Documentation for developing Lightworks effects 3 years, 4 months ago #144765

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12887
  • 3 years, 4 months ago
schrauber wrote:
I noticed with TEXCOORD0 some inaccuracies with horizontal lines.

One of the developers answered a question from khaver about the use of TEXCOORD0 which I couldn't find. I think that it's used for special purposes in Lightworks effects. I've looked for the reference and can't find it. Until I know what it does I'm inclined not to use it. I either use TEXCOORD or TEXCOORD1 and up. I believe that TEXCOORD just uses the default.

schrauber wrote:
Do you mean uv.x or uv.y to manipulate one-dimensional variable shares?
The meaning of uv.xy I do not understand.

In this context uv and uv.xy are identical. You can play all sorts of tricks by doing things like float2 xy = uv.yx, which will rotate the image through 90 degrees. You can also do things like Input.rgb = Input.aaa, in which case the alpha channel will be shown as a monochrome image. That could also be written Input = Input.aaaa and achieve the same result.

There are two ways that subscripts work with floats in Cg. You can use either rgba notation or xyzw notation. In the case of uv.xy above you could also use uv.rg with identical results. What you cannot do is change the notation with which you refer to a variable. See the example below.

   float4 In1 = 1.0;
   float4 In2 = 0.0;

   In2.w = 1.0;
   In1.rgb = In2.rgb     // This will fail!!!  Do not use

   float4 In1 = 1.0;
   float4 In2 = 0.0;

   In2.w = 1.0;
   In1.rgb = In2.xyz     // This will work


Having the xyzw form available is useful when you're dealing with non-rgba media - HSL, HSV and the like, for example.

Documentation for developing Lightworks effects 3 years, 4 months ago #144791

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4454
  • 3 years, 4 months ago
jwrl wrote:
...Having the xyzw form available is useful when you're dealing with non-rgba media - HSL, HSV and the like, for example.
Ok, so far I had understood .xy or .xyz only as position vectors.
Thank you.

Back to Sampler settings:
jwrl wrote:
... although the one thing that I covered and that you missed was what the default conditions are when no explicit declaration of addressing or filtering is made ....
... If in doubt, declare.

I have edited my post.
The first simplified code example with incomplete Sampler declaration I have replaced for security (default: Border, Linear).
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1; || Windows 10, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || shared RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 4 months ago by schrauber.

Documentation for developing Lightworks effects 3 years, 4 months ago #144833

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4454
  • 3 years, 4 months ago
Test, Filer settings and Texture settings:

jwrl wrote:
One of the developers answered a question from khaver about the use of TEXCOORD0 which I couldn't find. I think that it's used for special purposes in Lightworks effects. I've looked for the reference and can't find it. Until I know what it does I'm inclined not to use it. I either use TEXCOORD or TEXCOORD1 and up. I believe that TEXCOORD just uses the default.

I have created a test effect, which does not do other than render the input 50 times, but different textures and filters are adjustable.
This attachment is hidden for guests. Please log in or register to see it.

When using TEXCOORD1, this can be achieved with all 4 filter settings without noticeable losses.

TEXCOORD and TEXCOORD0 appear to be identical.
Both textures add up the inaccuracies (3 filter settings).
When using the GaussianQuad filter, the problem does not occur.

If necessary, further filters could be added to the effect for testing.
Attachments:
  • Attachment This image is hidden for guests. Please log in or register to see it.
  • Attachment This image is hidden for guests. Please log in or register to see it.
  • Attachment This image is hidden for guests. Please log in or register to see it.
  • Attachment This image is hidden for guests. Please log in or register to see it.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1; || Windows 10, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || shared RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 4 months ago by schrauber.

Documentation for developing Lightworks effects 3 years, 4 months ago #144834

  • Great White
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 1792
  • 3 years, 4 months ago
One of the developers answered a question from khaver about the use of TEXCOORD0 which I couldn't find

See here
Lightworks Development
Time to create page: 0.65 seconds
Scroll To Top