Skip to content

Commit

Permalink
Released v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryx93 committed Dec 2, 2015
1 parent 40aac25 commit 1437368
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 210 deletions.
86 changes: 41 additions & 45 deletions README.md
@@ -1,93 +1,89 @@
# AviSynth Shader v1.2.2
# AviSynth Shader v1.3

<a href="https://github.com/mysteryx93/AviSynthShader/releases">Download here >></a>

This plugin allows running HLSL pixel shaders within AviSynth. This gives access to various HLSL filters that haven't been programmed in AviSynth.

This implementation allows running several shaders in a row. Shader() returns a clip containing commands, and each subsequent to Shader() adds a line to that command chain clip. You must call ExecuteShader() to execute the chain of commands. You must also call ConvertToFloat() before and ConvertFromFloat() at the end.
This implementation allows running several shaders in a row. Shader() returns a clip containing commands, and each subsequent to Shader() adds a line to that command chain clip. You must call ExecuteShader() to execute the chain of commands. You must also call ConvertToShader() before and ConvertFromShader() at the end.

The following example will run Diff1 and Diff2 on the clip before returning a Merge of both results. (these shader names are fictive, you have to use real shaders!)

ConvertToFloat()
input
Shader("Diff1.cso", output=2)
Shader("Diff2.cso", output=3)
Shader("Merge.cso", clip1=2, clip2=3, output=1)
ShaderExecute(input)
ConvertFromFloat()
ConvertToShader()
Input
Shader("Diff1.cso", Output=2)
Shader("Diff2.cso", Output=3)
Shader("Merge.cso", Clip1=2, Clip2=3, Output=1)
ShaderExecute(last, Input, PrecisionIn=1, Precision=3, PrecisionOut=1)
ConvertFromShader()

## Syntax:

#### ConvertToFloat(input, convertYuv, precision)
#### ConvertToShader(Input, Precision)

Converts a YV12, YV24 or RGB32 clip into a wider frame containing UINT16 or half-float data. Clips must be converted in such a way before running any shader.

16-bit-per-channel half-float data isn't natively supported by AviSynth. It is stored in a RGB32 container with a Width that is twice larger. When using Clip.Width, you must divine by 2 to get the accurate width.

Arguments:

convertYuv: True to convert RGB data to YUV on the CPU. If false, YUV data will be copied as-is and can then be converted with a shader. Default=false.
Precision: 1 to convert into BYTE, 2 to convert into UINT16, 3 to convert into half-float. Default=1 (conversion can be done on the GPU)

precision: 1 to convert into BYTE, 2 to convert into UINT16, 3 to convert into half-float. Default=2

#### ConvertFromFloat(input, format, convertYuv, precision)
#### ConvertFromShader(Input, Format, Precision)

Convert a half-float clip into a standard YV12, YV24 or RGB32 clip.

Arguments:

format: The video format to convert to. Valid formats are YV12, YV24 and RGB32. Default=YV12.

convertYuv: True to convert YUV data to RGB on the CPU. If false, you already ran a shader to convert to YUV and the data will be copied as-is. Default=false.
Format: The video format to convert to. Valid formats are YV12, YV24 and RGB32. Default=YV12.

precision: 1 to convert into BYTE, 2 to convert into UINT16, 3 to convert into half-float. Default=2
Precision: 1 to convert into BYTE, 2 to convert into UINT16, 3 to convert into half-float. Default=1

#### Shader(input, path, entryPoint, shaderModel, param1-param9, clip1-clip9, width, height)
#### Shader(Input, Path, EntryPoint, ShaderModel, Param1-Param9, Clip1-Clip9, Output, Width, Height)

Runs a HLSL pixel shader on specified clip. You can either run a compiled .cso file or compile a .hlsl file.

Arguments:

input: The first input clip.
Input: The first input clip.

path: The path to the HLSL pixel shader file to run.
Path: The path to the HLSL pixel shader file to run.

entryPoint: If compiling HLSL source code, specified the code entry point.
EntryPoint: If compiling HLSL source code, specified the code entry point.

shaderModel: If compiling HLSL source code, specified the shader model. Usually PS_2_0 or PS_3_0
ShaderModel: If compiling HLSL source code, specified the shader model. Usually PS_2_0 or PS_3_0

param0-param8: Sets each of the shader parameters.
Param0-Param8: Sets each of the shader parameters.
Ex: "float4 p4 : register(c4);" will be set with Param4="1,1,1,1f"

End each value with 'f'(float), 'i'(int) or 'b'(bool) to specify its type.
Param0 corresponds to c0, Param1 corresponds to c1, etc.
If setting float or int, you can set a vector or 2, 3 or 4 elements by separating the values with ','.

clip1-clip9: The index of the clips to set into this shader. Input clips are defined when calling ExecuteShader. Clip1 sets 's0' within the shader, while clip2-clip9 set 's1' to 's8'. The order is important.
Clip1-Clip9: The index of the clips to set into this shader. Input clips are defined when calling ExecuteShader. Clip1 sets 's0' within the shader, while clip2-clip9 set 's1' to 's8'. The order is important.
Default for clip1 is 1, for clip2-clip9 is 0 which means no source clip.

output: The clip index where to write the output of this shader, between 1 and 9. Default is 1 which means it will be the output of ExecuteShader. If set to another value, you can use it as the input of another shader. The last shader in the chain must have output=1.
Output: The clip index where to write the output of this shader, between 1 and 9. Default is 1 which means it will be the output of ExecuteShader. If set to another value, you can use it as the input of another shader. The last shader in the chain must have output=1.

width, height: The size of the output texture. Default = same as input texture.
Width, Height: The size of the output texture. Default = same as input texture.

#### ShaderExecute(cmd, clip1-clip9, precision)
#### ExecuteShader(cmd, Clip1-Clip9, Precision)

Executes the chain of commands on specified input clips.

Arguments:

cmd: A clip containing the commands returned by calling Shader.

clip1-clip9: The clips on which to run the shaders.
Clip1-Clip9: The clips on which to run the shaders.

precision: 1 to execute with 8-bit precision, 2 to execute with 16-bit precision, 3 to execute with half-float precision
Precision: 1 to execute with 8-bit precision, 2 to execute with 16-bit precision, 3 to execute with half-float precision. Default=2

precisionIn: 1 if input clips are BYTE, 2 if input clips are UINT16, 3 if input clips are half-float. Default=2
PrecisionIn: 1 if input clips are BYTE, 2 if input clips are UINT16, 3 if input clips are half-float. Default=1

precisionOut: 1 to get an output clip with BYTE, 2 for UINT16, 3 for half-float. Default=2
PrecisionOut: 1 to get an output clip with BYTE, 2 for UINT16, 3 for half-float. Default=1


#### SuperRes(input, passes, strength, softness, upscalecommand, srcMatrix601, convert)
#### SuperRes(Input, Passes, Strength, Softness, Upscalecommand, SrcMatrix601, PrecisionIn)

In Shaders\SuperRes\SuperRes.avsi. Thanks to Shiandow for writing this great code!

Expand All @@ -97,20 +93,20 @@ Supported video formats: YV12, YV24, RGB24 and RGB32.

Arguments:

passes: How many SuperRes passes to run. Default=1.
Passes: How many SuperRes passes to run. Default=1.

strength: How agressively we want to run SuperRes, between 0 and 1. Default=1.
Strength: How agressively we want to run SuperRes, between 0 and 1. Default=1.

softness: How much smoothness we want to add, between 0 and 1. Default=0.
Softness: How much smoothness we want to add, between 0 and 1. Default=0.

upscalecommand: An upscaling command that must contain offset-correction. Ex: """nnedi3_rpow2(2, cshift="Spline16Resize")"""
Upscalecommand: An upscaling command that must contain offset-correction. Ex: """nnedi3_rpow2(2, cshift="Spline16Resize")"""

srcMatrix601: If true, the color matrix will be changed from Rec.601 to Rec.709 while running SuperRes. This avoids having to apply ColorMatrix separately. Default=false.
SrcMatrix601: If true, the color matrix will be changed from Rec.601 to Rec.709 while running SuperRes. This avoids having to apply ColorMatrix separately. Default=false.

convert: Whether to call ConvertToFloat and ConvertFromFloat() within the shader. Set to false if input is already converted. Default=true.
PrecisionIn: 0 to call ConvertToShader and ConvertFromShader within the shader. 1-3 if the source is already converted. Default=0.


#### Super-xBR(input, edgeStrength, weight, thirdPass, convert)
#### Super-xBR(Input, EdgeStrength, Sharpness, ThirdPass, Convert)

In Shaders\Super-xBR\super-xbr.avsi. Thanks to Shiandow for writing this great code!

Expand All @@ -120,18 +116,18 @@ Supported video formats: YV12, YV24, RGB24 and RGB32.

Arguments:

edgeStrength: Value between 0 and 5 specifying the strength. Default=1.
EdgeStrength: Value between 0 and 5 specifying the strength. Default=1.

weight: Value between 0 and 1.5 specifying the weight. Default=1.
Sharpness: Value between 0 and 1.5 specifying the weight. Default=1.

thirdPass: Whether to run a 3rd pass. Default=true.
ThirdPass: Whether to run a 3rd pass. Default=true.

convert: Whether to call ConvertToFloat and ConvertFromFloat() within the shader. Set to false if input is already converted. Default=true.
PrecisionIn: 0 to call ConvertToShader and ConvertFromShader within the shader. 1-3 if the source is already converted. Default=0.


#### ColorMatrix601to709(input)

In Shaders\ColorMatrix\ColorMatrix.avsi. Thanks to Shiandow for writing this great code!
In Shaders\ColorMatrix\ColorMatrix.avsi

Converts color matrix from Rec.601 to Rec.709 with 16 bit depth to avoid banding. Source can be YV12, YV24, RGB24 or RGB32.

Expand Down
10 changes: 8 additions & 2 deletions Release/ChangeLog.txt
@@ -1,11 +1,17 @@
Version 1.3: December 1st 2015
- SuperRes distortion problems fixed. Colors should now be accurate.
- Shaders now use PrecisionIn=1 and convert frames to 16-bit on the GPU
- 10% performance increase and lowered memory usage
- Fixed SuperRes when using Softness parameter
- Shader.dll now treats overflow coordinates with CLAMP
- Overflow coordinates now use 'clamp'
- Fixed distortion line at the right and bottom of Super-xBR
- Fixed sub-pixel shift with Super-xBR when ThirdPass=false
- 10% performance increase and lowered memory usage
- Super-xBR 'weight' argument renamed to 'sharpness'
- ConvertToFloat renamed to ConvertToShader, ConvertFromFloat renamed to ConvertFromShader
- ConvertToShader/ConvertFromShader, removed convertYuv argument
- ConvertToShader/ConvertFromShader, precision default is now 1
- All arguments now start with a uppercase letter
- Added PrecisionIn argument to SuperRes and Super-xBR. Set to 0 to call ConvertToShader within the shader; set to 1-3 if it is already converted.

Version 1.2.2: November 29th 2015
- For SuperRes, HLSL Bicubic downscaler is broken and has been disabled. Downscaling is now done in AviSynth
Expand Down
38 changes: 25 additions & 13 deletions Release/ReadMe.txt
@@ -1,53 +1,66 @@
AviSynthShader by Etienne Charland
Provides a bridge between AviSynth and HLSL pixel shaders for high bit depth processing on the GPU.

Ex: NNEDI3+SuperRes
SuperRes(2, .42, 0, """nnedi3_rpow2(2, nns=4, cshift="Spline16Resize", threads=2)""")

Ex: Super-xBR+SuperRes
ConvertToShader(Precision=2)
SuperRes(2, 1, 0, """SuperXBR(PrecisionIn=2)""", PrecisionIn=2)
ConvertFromShader("YV12", Precision=2)

SuperRes(input, passes, strength, softness, upscalecommand, srcMatrix601, convert)


SuperRes(Input, Passes, Strength, Softness, Upscalecommand, SrcMatrix601, PrecisionIn)

In Shaders\SuperRes\SuperRes.avsi. Thanks to Shiandow for writing this great code!

Enhances upscaling quality.

Supported video formats: YV12, YV24, RGB24 and RGB32.

Arguments:

passes: How many SuperRes passes to run. Default=1.
Passes: How many SuperRes passes to run. Default=1.

strength: How agressively we want to run SuperRes, between 0 and 1. Default=1.
Strength: How agressively we want to run SuperRes, between 0 and 1. Default=1.

softness: How much smoothness we want to add, between 0 and 1. Default=0.
Softness: How much smoothness we want to add, between 0 and 1. Default=0.

upscalecommand: An upscaling command that must contain offset-correction. Ex: """nnedi3_rpow2(2, cshift="Spline16Resize")"""
Upscalecommand: An upscaling command that must contain offset-correction. Ex: """nnedi3_rpow2(2, cshift="Spline16Resize")"""

srcMatrix601: If true, the color matrix will be changed from Rec.601 to Rec.709 while running SuperRes. This avoids having to apply ColorMatrix separately. Default=false.
SrcMatrix601: If true, the color matrix will be changed from Rec.601 to Rec.709 while running SuperRes. This avoids having to apply ColorMatrix separately. Default=false.

convert: Whether to call ConvertToFloat and ConvertFromFloat() within the shader. Set to false if input is already converted. Default=true.
PrecisionIn: 0 to call ConvertToShader and ConvertFromShader within the shader. 1-3 if the source is already converted. Default=0.




Super-xBR(Input, EdgeStrength, Sharpness, ThirdPass, Convert)

Super-xBR(input, edgeStrength, weight, thirdPass, convert)
In Shaders\Super-xBR\super-xbr.avsi. Thanks to Shiandow for writing this great code!

Doubles the size of the image. Produces a sharp result, but with severe ringing.

Supported video formats: YV12, YV24, RGB24 and RGB32.

Arguments:

edgeStrength: Value between 0 and 5 specifying the strength. Default=1.
EdgeStrength: Value between 0 and 5 specifying the strength. Default=1.

weight: Value between 0 and 1.5 specifying the weight. Default=1.
Sharpness: Value between 0 and 1.5 specifying the weight. Default=1.

thirdPass: Whether to run a 3rd pass. Default=true.
ThirdPass: Whether to run a 3rd pass. Default=true.

convert: Whether to call ConvertToFloat and ConvertFromFloat() within the shader. Set to false if input is already converted. Default=true.
PrecisionIn: 0 to call ConvertToShader and ConvertFromShader within the shader. 1-3 if the source is already converted. Default=0.




ColorMatrix601to709(input)

In Shaders\ColorMatrix\ColorMatrix.avsi

Converts color matrix from Rec.601 to Rec.709 with 16 bit depth to avoid banding. Source can be YV12, YV24, RGB24 or RGB32.


Expand All @@ -60,7 +73,6 @@ Converts color matrix from Rec.709 to Rec.601 with 16 bit depth to avoid banding




Shaders are written by Shiandow and are available here
https://github.com/zachsaw/MPDN_Extensions/

Expand Down
Binary file modified Release/Shader.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions Shaders/ColorMatrix/ColorMatrix.avsi
Expand Up @@ -6,11 +6,11 @@ function ColorMatrix601to709(clip input)
sourceFormat = IsYV12 ? "YV12" : IsYV24 ? "YV24" : IsRGB24 ? "RGB24" : IsRGB32 ? "RGB32" : ""
Assert(sourceFormat != "", chr(10) + "Source must be YV12, YV24, RGB24 or RGB32" + chr(10))

input = ConvertToFloat(precision=1)
input = ConvertToShader(precision=1)
Shader(srcYuv ? "Yuv601ToGamma.cso" : "GammaToYuv601.cso")
Shader(srcYuv ? "GammaToYuv.cso" : "YuvToGamma.cso")
ExecuteShader(last, input, precision=2, precisionIn=1, precisionOut=1)
ConvertFromFloat(format=sourceFormat, precision=1)
ConvertFromShader(format=sourceFormat, precision=1)
}

function ColorMatrix709to601(clip input)
Expand All @@ -20,9 +20,9 @@ function ColorMatrix709to601(clip input)
sourceFormat = IsYV12 ? "YV12" : IsYV24 ? "YV24" : IsRGB24 ? "RGB24" : IsRGB32 ? "RGB32" : ""
Assert(sourceFormat != "", chr(10) + "Source must be YV12, YV24, RGB24 or RGB32" + chr(10))

input = ConvertToFloat(precision=1)
input = ConvertToShader(precision=1)
Shader(srcYuv ? "YuvToGamma.cso" : "GammaToYuv.cso")
Shader(srcYuv ? "GammaToYuv601.cso" : "Yuv601ToGamma.cso")
ExecuteShader(last, input, precision=2, precisionIn=1, precisionOut=1)
ConvertFromFloat(format=sourceFormat, precision=1)
ConvertFromShader(format=sourceFormat, precision=1)
}
60 changes: 31 additions & 29 deletions Shaders/Super-xBR/super-xbr.avsi
@@ -1,48 +1,50 @@
function SuperXBR(clip input, float "edgeStrength", float "sharpness", bool "thirdPass", bool "convert")
function SuperXBR(clip Input, float "EdgeStrength", float "Sharpness", bool "ThirdPass", int "PrecisionIn")
{
edgeStrength = default(edgeStrength, 1)
sharpness = default(sharpness, 1)
thirdPass = default(thirdPass, true)
convert = default(convert, true)

Assert(edgeStrength >= 0 && edgeStrength <= 5, "EdgeStrength must be between 0 and 5")
Assert(sharpness >= 0 && sharpness <= 1.5, "Sharpness must be between 0 and 1.5")
Assert(convert || thirdPass, "ThirdPass is required when Convert=false")
EdgeStrength = default(EdgeStrength, 1)
Sharpness = default(Sharpness, 1)
ThirdPass = default(ThirdPass, true)
PrecisionIn = default(PrecisionIn, 0)
convert = PrecisionIn==0

Assert(EdgeStrength >= 0 && EdgeStrength <= 5, "EdgeStrength must be between 0 and 5")
Assert(Sharpness >= 0 && Sharpness <= 1.5, "Sharpness must be between 0 and 1.5")
Assert(convert || ThirdPass, "ThirdPass is required when PrecisionIn > 0")
Assert(PrecisionIn >= 0 && PrecisionIn <= 3, "PrecisionIn must be between 0 and 3")

input
Input

convertYuv = convert && !IsRGB()
#convertYuv = convert && !IsRGB()
sourceFormat = IsYV12() ? "YV12" : IsYV24() ? "YV24" : IsRGB24() ? "RGB24" : "RGB32"

input = convert ? ConvertToFloat(precision=1) : last
Input = convert ? ConvertToShader(Precision=2) : last

input
inputWidth = convert ? width : width / 2
inputHeight = height
args_string = string(edgeStrength,"%.32f") + "," + string(sharpness,"%.32f") + "0,0f"
size0_string = string(inputWidth) + "," + string(inputHeight)+"," + string(1./InputWidth,"%.32f") + "," + string(1./height,"%.32f")+"f"
size1_string = string(2*inputWidth) + "," + string(2*inputHeight) + "," + string(1./(2*inputWidth),"%.32f") + "," + string(1./(2*inputHeight),"%.32f")+"f"
Input
InputWidth = Width / (PrecisionIn==0 || PrecisionIn==1 ? 2 : 2)
InputHeight = Height
args_string = string(EdgeStrength,"%.32f") + "," + string(Sharpness,"%.32f") + ",0,0f"
size0_string = string(InputWidth) + "," + string(InputHeight) + "," + string(1./InputWidth,"%.32f") + "," + string(1./InputHeight,"%.32f") + "f"
size1_string = string(2*InputWidth) + "," + string(2*InputHeight) + "," + string(1./(2*InputWidth),"%.32f") + "," + string(1./(2*InputHeight),"%.32f") + "f"

# It works just as well in YUV colorspace
#convertYuv ? Shader("YuvToGamma.cso") : nop

Shader("super-xbr-pass0.cso",\
param2=args_string,\
param3=size0_string,\
width=2*inputWidth,height=2*inputHeight)
Param2 = args_string,\
Param3 = size0_string,\
Width = 2*InputWidth, Height = 2*InputHeight)

Shader("super-xbr-pass1.cso",\
param2=args_string,\
param3=size1_string)
Param2=args_string,\
Param3=size1_string)

thirdPass ? Shader("super-xbr-pass2.cso",\
param2=args_string,\
param3=size1_string) : nop
ThirdPass ? Shader("super-xbr-pass2.cso",\
Param2=args_string,\
Param3=size1_string) : nop

#convertYuv ? Shader("GammaToYuv.cso") : nop
last.ExecuteShader(input, precision=2, precisionIn=convert?1:2, precisionOut=convert?1:2)
last.ExecuteShader(Input, Precision=2, PrecisionIn=convert?1:PrecisionIn, PrecisionOut=convert?1:PrecisionIn)

convert ? ConvertFromFloat(format=sourceFormat, precision=1) : last
convert ? ConvertFromShader(Format=sourceFormat, Precision=1) : last

!thirdPass ? spline36resize(width, height, -.5, -.5, width, height) : last
!ThirdPass ? spline36resize(2*InputWidth, 2*InputHeight, -.5, -.5, 2*InputWidth, 2*InputHeight) : last
}

0 comments on commit 1437368

Please sign in to comment.