Welcome, Guest
Username Password: Remember me

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

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179821

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
My solution:
Use the Mirror Sampler setting and place the interpolation point 0.5 tex outside the texture.
Instead of this code in the function:
float2 xy = abs (uv - 0.5.xx);


replace with this code:
float2 xy = abs (uv - 0.5.xx) - ((1.0 / FRAME) / 2.0);
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: 2 years, 2 months ago by schrauber.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179822

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
With very strong minimization, and the sample setting Mirror, internal multiple reflections are calculated internally
This can multiply the GPU load.
By limiting the possible range of the foreground sampler position, I was able to prevent this (low GPU load).
Instead of this code in the function:
float4 retval = tex2D (Vsample, uv);


replace with this code:
float4 retval = tex2D (Vsample, clamp(uv, -0.1, 1.1));
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: 2 years, 2 months ago by schrauber.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179823

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
Suggestion No.3:

So far, the edge interpolation at Scale <15% did not work or did not work well.
With this code change the edge interpolation from sale <1% to> 90% worked perfectly in my test.

I replaced this code ...
float2 alpha = min (1.0.xx, (0.5.xx - xy) * FRAME);


.. by this code:
float2 alpha = min (1.0.xx, (0.5.xx - xy) * (FRAME / scale));


The whole function:
float4 fn_tex2D_4 (sampler Vsample, float scale, float2 uv)
{
   float2 xy = abs (uv - 0.5.xx) - ((1.0/FRAME)/2.0);

   if ((xy.x > 0.5 ) || (xy.y > 0.5 )) return EMPTY;

   float2 alpha = min (1.0.xx, (0.5.xx - xy) * (FRAME / scale));

   float4 retval = tex2D (Vsample, clamp(uv, -0.1, 1.1));

   retval.a = min (retval.a, min (alpha.x, alpha.y));

   return retval;
}



The shader must pass the value of scale to the function:
float4 ps_main_4 (float2 uv : TEXCOORD1) : COLOR
{
   float scale = 1.0 / max (Amount * 2.0, 0.00000001);
   float2 xy = ((uv - 0.5.xx) * scale) + 0.5.xx;

   xy += float2 (0.5 - CentreX, CentreY - 0.5) * scale;

   float4 retval = fn_tex2D_4 (s_Input, scale, xy);

   return lerp (BGND, retval, retval.a);
}


The effect with the 3 previous mirror code, and the code I edited for comparison:
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: 2 years, 2 months ago by schrauber.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179824

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12881
  • 2 years, 2 months ago
Interesting. I'll have to try that later. My concern is that it's adding complexity, which I would like to try and avoid if at all possible. What does it do to the GPU performance?

There must be a fix that doesn't deliberately enter illegal territory, but doesn't suffer from the soft edge-pixel issue at 100% scale, surely. My secret goal is to try and avoid shader address compatibility issues with cross-platform code. I would like to be able to just use shader defaults and get the same result on old and new Lightworks, on any platform.

Oh, well. I can dream.

[EDIT] But you're quite right, and I should have checked what happened over the scale range. At the moment I can't check it until this evening (my time) in about 6 or 7 hour's time.
Last Edit: 2 years, 2 months ago by jwrl.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179869

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
jwrl wrote:
My concern is that it's adding complexity, which I would like to try and avoid if at all possible.

I think this code extension only makes sense for some effects (if compatibility is guaranteed). Maybe optimizations are still possible?

jwrl wrote:
What does it do to the GPU performance?

I had difficulty recognizing any differences in the GPU load at all. This may be different when used in more complex effects when overall complexity approaches the limit of PROFILE ps_2_b (Windows).

On the other hand, the code could also be used for adjustable edge softness.

:pinch: Warning: Spoiler!


But settable edge softness is not the current topic.
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: 2 years, 2 months ago by schrauber.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179899

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12881
  • 2 years, 2 months ago
Yes, it looks like it could open up a whole new area of development. Yesterday I had no chance at all to explore this further, but I'll explore it today and see what develops. That softness technique is very similar to what I used in DVE with vignette, by the way.

I'm concerned that we're loading a simple function intended to provide a quick fix with a lot of extra code. Perhaps I should scrap this altogether and see if I can work out a better way to do it. I had previously thought of comparing adjacent pixel addresses, but that is also reasonably complex so I abandoned the idea.

My dream of a simple solution seems to have vanished.
Last Edit: 2 years, 2 months ago by jwrl.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179903

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12881
  • 2 years, 2 months ago
Having had the chance to play with this a little I've decided to abandon my original approach. As it currently stands this depends on mirror addressing to work and can actually make the situation worse if you use alternative addressing.

There has to be a way that a simple tex2D replacement function can solve this problem without adding such a degree of complexity and without requiring anything other than sampler and texcoord input. I'l give it some more thought.

By all means continue work on it if you wish, but I'm going back to first principles. There has to be a better way.
Last Edit: 2 years, 2 months ago by jwrl.

Re: Documentation for developing Lightworks effects 2 years, 2 months ago #179916

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
jwrl wrote:
... As it currently stands this depends on mirror addressing to work and can actually make the situation worse if you use alternative addressing...

The code also works with (from LW14.5 on all platforms):
AddressU  = ClampToEdge;
AddressV  = ClampToEdge;

Then we could do without Clamp in the code.
Of course, there is the backward compatibility problem.
In perhaps 1 to 2 years this will probably be less relevant.

In my experiments with adjustable softness of the edges, I followed the idea that in the effects in which edge interpolation seems necessary, an adjustable softness is a useful functionality. So only one code for two solutions.

If you find better solutions, these are of course welcome.
However, my GPU generally has problems with minimizations (also within the texture).
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: 2 years, 2 months ago by schrauber.

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #179940

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
At this point hugly asked in the thread from which this was moved the following question - jwrl.

hugly wrote:
Is there any Blur effect in the treasure box which doesn't change appearance depending on (preview/export) resolution?

As an example, I looked at the Super Blur.fx effect.
If I replace the variable "_OutputWidth" with a fixed value in line 124, then blurring is no longer relative to the surrounding pixel count, but relative to the entire frame (ie independent of the project resolution).

previous line 124:
float2 xy, radius = float2 (1.0, _OutputAspectRatio) * blurRadius * Size / _OutputWidth;


my test:
float2 xy, radius = float2 (1.0, _OutputAspectRatio) * blurRadius * Size / 1920.0;


If aliasing is to be blurred, which has the project resolution as a cause, then the original method is more meaningful.
A switch would be possible.
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: 2 years, 2 months ago by jwrl.

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #179943

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12881
  • 2 years, 2 months ago
If you really want to make it input resolution dependent you can't just set the width. Line 120 would need to change to something like this.

   float2 xy, radius = blurRadius * Size / float2 (UserWidth, UserHeight);

You would then need to add two new user adjustable parameters called UserWidth and UserHeight. Surely it would just be simpler to set the project to the output format that you require.
Last Edit: 2 years, 2 months ago by jwrl.

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #179944

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
I dont know. I have not dealt with blurring effects in detail so far.
However, the result with my simple change visually fulfilled my expectations.
Here is a comparison of the original effect with my test effect:
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)

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #179949

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12881
  • 2 years, 2 months ago
Of course it did - at 1920 x 1080. If you are working with different media then it will not give the intended result, and programming an effect with a fixed size and variable aspect ratio is not particularly helpful. That's why Editshare haven't done it either.

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #179966

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
jwrl wrote:
If you are working with different media then it will not give the intended result ...
In my tests with different media resolutions, project resolutions and Project aspect ratios, I saw the same result.
Lightworks scales the media resolutions to project resolution before the effect input.

jwrl wrote:
... and programming an effect with a fixed size and variable aspect ratio is not particularly helpful...
In your SuperBlur.fx, "_OutputWidth" affects the components x and y.
For this reason it has no influence on the aspect ratio of the blur radius. It has the same effect as changing the "Radius" slider (variable name "Size").
I can also remove the division with "_OutputWidth" without replacement, but this would increase the adjustment range of the slider too much.

To make it clear, I've predefined the scale of the slider in this code:
#define SIZE (Size / 1920.0)
float2 xy, radius = float2 (1.0, _OutputAspectRatio) * blurRadius * SIZE;
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: 2 years, 2 months ago by schrauber.

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #180018

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12881
  • 2 years, 2 months ago
First, let's get something out of the way. Lightworks when asked to export at a different size than the project settings clearly doesn't scale _Output values to match. Whether that's a bug or not, who can say?

However with respect, schrauber, you may believe that's what you're seeing, but you genuinely are not. Instead of producing a blur related to pixel size regardless of the project format settings, you are producing a blur related to pixel size only if your project format happens to be 1920 pixels wide, you export at that size and your media matches it.

Don't believe me? Try replacing the calculations that you did to produce a half pixel offset in the edge correction code two days ago with a fixed value and see what you get.

You also clearly don't understand the calculations of output width and height. The variable _OutputHeight which I chose not to use is equal to _OutputWidth divided by _OutputAspectRatio. You can write the formula that I used for calculating a pixel as float2 (1.0 / _OutputWidth, 1.0 / _OutputHeight) or 1.0 / float2 (_OutputWidth, _OutputHeight) or float2 (1.0 / _OutputAspectRatio, 1.0) / _OutputHeight or any of a dozen other ways of expressing it: the result will be exactly the same pixel size that the project is set to.

Your form cannot and will not. It will use a value for a pixel of 1 / 1920 x _OutputAspectRatio / 1920. In a 4x3 project you will get a pixel size of 0.00052083 x 0.00069444, in a 16x9 project it will be 0.00052083 x 0.00092593. That will the case even if the true pixel size is 0.00078125 x 0.00138889 or 0.00208333 x 0.00277778 (1280x720 and 480x360 respectively). You will get a blur factor that is too large for larger frame formats and too small for smaller.

I find that completely unacceptable.
Last Edit: 2 years, 2 months ago by jwrl.

Re: User Effects files (Post #1 has them all) 2 years, 2 months ago #180030

  • schrauber
  • OFFLINE
  • Platinum Boarder
  • Posts: 4452
  • 2 years, 2 months ago
Ok, maybe there is a misunderstanding, which goal I wanted to achieve with the new effect?

Example: I have finished a 720p project containing 4k media.
Reasons may be that I first want to export to 720p, or I want to reduce the GPU load.
At a later date I decide to export in 1080p or 4k.
Previously, I switch to the appropriate project setting.

My goal for a new blur effect is that the blur radius, which used to be 10% of the screen dimensions, still has 10% of the screen dimensions.
jwrl wrote:
... In a 4x3 project you will get a pixel size of 0.00052083 x 0.00069444, in a 16x9 project it will be 0.00052083 x 0.00092593. That will the case even if the true pixel size is 0.00078125 x 0.00138889 or 0.00208333 x 0.00277778 (1280x720 and 480x360 respectively). You will get a blur factor that is too large for larger frame formats and too small for smaller...

On a pixel basis, that's my goal.

Reason:
If I get 10% of the screen dimensions in a 720p project of blur radio, that's 72 pixels in height.
In a 1080p project, 10% of the screen dimensions are 108 pixels in hight.
My goal is to keep the 10% constant, not scale the blur radius to the pixel size.

I want to set a blur radius that is relative to the screen dimensions. You know, the xy positions are scaled in the shader from 0 to 1, so for my purpose I do not have to define a pixel size.

In my code, "_OutputAspectRatio" only has the purpose of keeping the blur radius round.

If you do not want to use these new features in your effects, then I could create a new effect.
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: 2 years, 2 months ago by schrauber.
Time to create page: 0.48 seconds
Scroll To Top