Welcome, Guest
Username Password: Remember me

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

Re: User Effects files (Post #1 has them all) 3 years, 6 months ago #151431

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 6 months ago
I have just tested tex2Dbias (Sampler, float4(pos.xy, 0.0, Zoo_level.w))
With position w the linear filtering can be activated for the MinFilter and MagFilter depending on the zoom.
(Provided they are disabled in the sampler settings.)
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 6 months ago by schrauber. Reason: Incorrect code strikethrough

Re: User Effects files (Post #1 has them all) 3 years, 6 months ago #151437

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 6 months ago
That could be very interesting. I suspect that tex2Dbias (Sampler, float4(pos.xy, Zoom_level.xx)) would also work as well. You are obviously using the float4 tex2Dbias(sampler2D samp, float4 s) version and not the float4 tex2Dbias(sampler2D samp, float4 s, int texelOff) variant.

As I interpret the reference manual, any value in s.z should be ignored. I'm also surprised that using Zoom_level.w works at all, and suspect that it wouldn't work cross platform. If Zoom_level is a float you should use Zoom_level.x. That will be assigned to s.w, while Zoom_level.w will give an ambiguous result at best.
Last Edit: 3 years, 6 months ago by jwrl.

Re: User Effects files (Post #1 has them all) 3 years, 6 months ago #151445

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 6 months ago
You're right.
Sorry, this was not my original code.
Original I used provisional test sliders:
tex2Dbias (BorderSampler, float4 (pos,test1, test2));

This attachment is hidden for guests. Please log in or register to see it.


jwrl wrote:
.... As I interpret the reference manual, any value in s.z should be ignored...

Right, my "test1" slider has no effect.


I used these sampler settings:

sampler BorderSampler = sampler_state
{
   Texture = <Input>;
   AddressU = Border;
   AddressV = Border;
   MinFilter =  Linear;
   MagFilter = None;
   MipFilter = Linear;
};
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 6 months ago by schrauber.

Re: User Effects files (Post #1 has them all) 3 years, 6 months ago #151481

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 6 months ago
jwrl wrote:
If Zoom_level is a float you should use Zoom_level.x.

And of course, while that is correct, it should really just be "If Zoom_level is a float you should just use Zoom_level".

And you have a magfilter setting of none? Interesting. This is starting to look like a good avenue to explore. However, the test you showed was hard to evaluate. It might have been simpler to give an example of an unblurred slow zoom playing. That's where the problems are most apparent.
Last Edit: 3 years, 6 months ago by jwrl.

Re: User Effects files (Post #1 has them all) 3 years, 6 months ago #151487

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 6 months ago
The problem is that the filters are only switched. So no soft change.
I found it interesting, but I have no idea if we can use it.

I am currently testing minification filter in the pixel shader code.
The mixing of 39 samples per output pixel looks good, but drastically increases the GPU load. The quality of course decreases with the dimensions.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 6 months ago by schrauber.

Re: User Effects files (Post #1 has them all) 3 years, 6 months ago #152430

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 6 months ago
In my tracking down of D3D/Cg compiler issues I have discovered some really sneaky problems. The first one: it appears that there is a compatibility issue between the D3D (Windows) and Cg (Mac/Linux) compilers which can break an effect without reporting any form of compiler error. It's a real silent death related to the default state of samplers, which appears to differ markedly.

If you declare a sampler as shown in the following example a multipass effect that relies on the alpha channel being passed between shaders may fail.

sampler FgdSampler = sampler_state { Texture = <Fgd>; };

In the version below the sampler is now fully defined and that problem doesn't arise.

sampler FgdSampler = sampler_state {
   Texture = <Fgd>;
   AddressU  = ClampToEdge;
   AddressV  = ClampToEdge;
   MinFilter = Point;
   MagFilter = Linear;
   MipFilter = Linear;
};

I encountered this in a few effects while checking Linux compatibility, all of which were fixed by making that simple change and doing absolutely nothing else.

A second issue that also caused problems with one effect was that you cannot assign a value to a sampler inside a function or shader in Linux/Mac code. An example of what I mean:

   sampler anything;
   ...
   if (test) anything = some_sampler;
   else anything = another_sampler;
   float4 retval = tex2D (anything, xy);

That will compile and return the pixel at xy using the sampler "some_sampler" as a passed parameter in Windows if "test" is true, but will use "another_sampler" if not. It will not do that in Linux or Mac. It will fail at the compile stage with no clear error message. Instead you would need to do something like the following:

   float4 retval;
   ...
   if (test) retval = tex2D (some_sampler, xy);
   else retval = tex2D (another_sampler, xy);

That form will work on all three platforms.

Fortunately I have only encountered one effect that had that problem, but it took me the best part of a week to work out what was going on. Next time will be much, much faster!

Finally, there is also a difference in the way that the D3D and Cg compilers handle texture coordinates. In Linux if you are generating an image with a shader as opposed to passing an image to that shader you must use TEXCOORD0 and nothing else. I had used TEXCOORD1 on my greyscale test pattern generator and bars would not display but ramps would. Changing TEXCOORD1 to TEXCOORD0 was all that was needed to correct the issue.
Last Edit: 8 months, 2 weeks ago by jwrl.

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

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 3 months ago
Compiling Pixel Shaders, Windows, (Lightworks 14.0):
Great White wrote:
The default shader profile on Windows is ps_2_b ...


Use with caution:
Great White wrote:
You can override this by adding a key a called ShaderProfile in the registry at this location :

HKEY_CURRENT_USER\Software\Lightworks\Configuration

and setting the value to the desired profile (eg. ps_3_0)


hugly wrote:
Just to confirm, on Win7 I've created a string-value "ShadeProfile" with data "ps_3_0". [...]
This image is hidden for guests. Please log in or register to see it.
[...]




In the effect code ("Technique") other shader versions / modules can be defined, so the above-mentioned presets are ignored. Currently, Lightworks support:
Windows only:
ps_2_0
ps_2_b
ps_3_0

(Effects with these code are unsuitable for Linux and Mac)

Cross-platform compatible:
PROFILE


For more details and experiments see: "Compiling Pixel Shaders?"

For details on the code see "Techniques" in the first post.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)

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

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 3 months ago
Just to emphasise schrauber's warning. Use the Windows registry setting with extreme caution. Forcing effects that were stable when compiled with a ps_2_b profile to compile as ps_3_0 may not always work. Already two have been found that will crash when compiled that way, and it's unreasonable to expect support if you're using a setting that was intended for debug purposes.

If a would-be effects developer writes an effect that makes use of this switch the effect won't be included in the library unless they supply separate versions of the code for Windows and Linux/Mac platforms. The Windows version must include an explicit shader profile declaration and can't expect the user to patch the registry. Failure to do that will result in the effect not being included in the effects library, in exactly the same way as if the effect used an HLSL instruction that isn't supported in Cg.

In other words what I'm saying is that for compatibility reasons when developing effects (which is what this thread is about), it's a really good idea not to do it.
Last Edit: 3 years, 3 months ago by jwrl.

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

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 3 months ago
About sanmper settings:

sampler FgSampler = sampler_state
{
   Texture = <Input>;
   AddressU = Mirror;
   AddressV = Mirror;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;
};

This image is hidden for guests. Please log in or register to see it.

jwrl wrote:
The behaviour of mirror addressing differs between Windows and Linux. On Windows the alpha channel is mirrored along with the image. It isn't in Linux - the alpha channel is set to zero in exactly the same way as with the border setting. I think that you can safely assume that it would be the same on the Mac.

I can't think of a simple technique for fixing that problem without doing a second pass just to process the alpha channel.


I think I have found a solution, but it can only test on Windows.
Instead of using the standard system functions for the mirroring, I have programmed this myself in the code of the shader. The mirroring then works independently of the sampler settings.
Here is the shader code for the output:

float posFlip = abs((round(fmod(floor(abs(xy)), 2) + 0.1) * -1.0) + frac(abs(xy)));
return tex2D (FgSampler, posFlip);
xy is the original sampler position.
posFlip is the corrected sampler position


Just for a better understanding here the code with intermediate variable "flipDirection":

float2 posFlip;       
float2 flipDirection; 
      // Status of the direction of the mirroring of the sampler position.
      // flipDirection  0 means: the absolute fractional part of the original value is used.
      // flipDirection -1 means: Reverse direction of the absolute fractional part of the original value is used.    
      //(the range from -2.0 to -1.0   is changed    to 0.0 to 1.0)



flipDirection = floor(abs(xy));                     // Integer part of the shader position.
flipDirection = fmod(flipDirection, 2.0);           // If the division by 2.0 contains a fractional fraction of .5,  then the Reverse direction of the absolute fractional part of the original sampler-value is used.
flipDirection = round(flipDirection + 0.1) * -1.0;  // Rounding to status 0.0 or -1.0
posFlip = abs(flipDirection + frac(abs(xy)));       // Correcting the shader position depending on whether the original samper position contains an odd integer.
return tex2D (FgSampler, posFlip);
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 3 months ago by schrauber.

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

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 3 months ago
I just see that the formula still contains a rounding error that can lead to 1 pixel wide lines at the edges. ...


The normal texture positions should be in the range between 0.0 and 1.000000 ... but the formula calculates with a standard range of 0.0 to 0.9999999 ....

The formula sees the pixel at the edge 1.0 already as a position outside the texture.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 3 months ago by schrauber.

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

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 3 months ago
As usual, an elegant solution. I don't know how important that 0.000...01 error will be in practice. I'll check it in Linux later today.
Last Edit: 3 years, 3 months ago by jwrl.

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

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 3 months ago
Probably I was wrong in the error analysis.
The centers of the outer pixels are not exactly at the positions 0.0 and 1.0. More likely is under Windows:
0.0 + half texel size and
1.0 - half texel size

My problem was that I used the sampler settings "Border". Thus, at the sampler position 0.0 and 1.0, the pixel was linearly interpolated with the border.
With Clamp I do not have the problem:
sampler FgSampler = sampler_state
{
   Texture = <Input>;
   AddressU = Clamp;
   AddressV = Clamp;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;
};


This leads to the question whether the alphan channel, in the clamp setting and area, is preserved under Linux.
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 3 months ago by schrauber.

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

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 3 months ago
schrauber wrote:
This leads to the question whether the alphan channel, in the clamp setting and area, is preserved under Linux.

I'd be amazed if it wasn't. After running your routine what is now happening is tex2D() is just seeing an address which never goes outside the active frame. Since we know that the alpha channel isn't suppressed inside the active frame it will work.

But I'll check.

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

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 13424
  • 3 years, 3 months ago
OK, just checked on Linux. It works. but in Linux even if you change the addressing to "Clamp" you can get half texel errors at the edges under the right conditions. However the alpha channel is definitely preserved.

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

  • schrauber
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 4911
  • 3 years, 3 months ago
Ok, thanks for testing.

The following is a code that works on Windows with the sampler setting "Border" without disturbing lines.
The samper position is clamped between the centers of the outer pixels, instead of the pixel edge. This prevents interpolation with areas outside the texture. For this, half the texel size had to be calculated.
float _OutputAspectRatio;
float _OutputWidth;
#define Output_Height (_OutputWidth/_OutputAspectRatio)
#define TEXEL05   (float2 (1 / _OutputWidth, 1 / Output_Height) / 2.0)      //  Half texel dimensions.



float2 posFlip;       
float2 flipDirection; 


flipDirection = floor(abs(xy));                
flipDirection = fmod(flipDirection, 2.0);	          
flipDirection = round(flipDirection + 0.1) * -1.0; 
posFlip = abs(flipDirection +
          clamp(frac(abs(xy)), TEXEL05, 1.0 -TEXEL05)); 
return tex2D (FgSampler, posFlip);


Disadvantage: More CPU load, and shader complexity
Mainly automatically translated
--------------------------------------------
Software: Lightworks 2020.1.1 & Beta 2021.x; || Windows 10 Home 1909, 64 Bit
Hardware: Intel i5-4440 (3,1 GHz); || RAM: 8 GB; || Intel HD Graphics 4600 (can use max. 2 GB of shared RAM)
Last Edit: 3 years, 3 months ago by schrauber.
Time to create page: 0.44 seconds
Scroll To Top