AviSynthShader

From Avisynth wiki
Revision as of 04:20, 21 February 2023 by Reel.Deal (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Abstract
Author mysteryx93
Version v1.6.5
Download AviSynthShader-1.6.5.zip
Category Multipurpose
License
Discussion Doom9 Forum

Contents

Description

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

Requirements


Syntax and Parameters

Shader.dll

Plugin containing ConvertToShader(), ConvertFromShader(), Shader(), and ExecuteShader() functions.

ConvertToShader

Converts a 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.

ConvertToShader (clip, int "Precision", bool "lsb", bool "planar", int "opt")


clip   =
Input clip.


int  Precision = 1
Precision:
  • 0 to convert to Y8
  • 1 to convert into BYTE (default)
  • 2 to convert into UINT16
  • 3 to convert into half-float


bool  lsb = false
Whether to convert from DitherTools' Stack16 format. Only YV12 and YV24 are supported. Default=false


bool  planar = false
True to convert into YV24 planar data to reduce memory transfers. If you assign such a clip to Clip1, the shader will receive the 3 planes as Clip1, Clip2 and Clip3. Default=false


int  opt = -1
Optimization path:
  • In AviSynth 2.6, 0 for only C++, 1 for SSE2, 2 for AVX(only used with Precision=3), -1 to auto-detect.
  • In AviSynth+, -1 to use the AviSynth+ code path, other values to use legacy code paths.
  • Default=-1




ConvertFromShader

Convert a half-float clip into a standard clip.

ConvertFromShader (clip, int "Precision", string "Format", bool "lsb", int "opt")


clip   =
Input clip.


int  Precision = 1
Precision:
  • 0 to convert to Y8
  • 1 to convert into BYTE (default)
  • 2 to convert into UINT16
  • 3 to convert into half-float


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


bool  lsb = false
Whether to convert to DitherTools' Stack16 format. Only YV12 and YV24 are supported. Default=false


int  opt = -1
Optimization path:
  • In AviSynth 2.6, 0 for only C++, 1 for SSE2, 2 for AVX(only used with Precision=3), -1 to auto-detect.
  • In AviSynth+, -1 to use the AviSynth+ code path, other values to use legacy code paths.
  • Default=-1



Shader

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

"Shader (clip, string "Path", string "EntryPoint", string "ShaderModel", string "Param0", ..., string "Param8", clip "Clip1", ..., clip "Clip9", int "Output", int "Width", int "Height", int "Precision", string "Defines")


clip   =
The first input clip.


string  Path = ""
The path to the HLSL pixel shader file to run. If not specified, Clip1 will be copied to Output.


string  EntryPoint = "main"
If compiling HLSL source code, specify the code entry point.


string  ShaderModel = "ps_3_0"
If compiling HLSL source code, specify the shader model. Usually PS_2_0 or PS_3_0


string  Param0 = ""
.....
string  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 ','.
If not specified, Param0 = Width,Height and Param1 = 1/Width, 1/Height by default.


clip  Clip1 = 1
.....
clip  Clip9 = 0
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.


int  Output = 1
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.


int  Width =
int  Height =
The size of the output texture. Default = same as input texture.


int  Precision = -1
While processing precision is set with ExecuteShader, this allows processing certain shaders with a different precision.


string  Defines = ""
List of pre-compilation constants to set for HLSL files, separated by ';'. Ex: "Kb=0.114;Kr=0.299;"



ExecuteShader

Executes the chain of commands on specified input clips.

"ExecuteShader(clip, clip "Clip1-9", int "Clip1Precision", ..., int "Clip9Precision", int "Precision", int "OutputPrecision", bool "PlanarOut", int "Engines", bool "Resource")


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


clip  Clip1 =
.....
clip  Clip9 =
Clip1-Clip9: The clips on which to run the shaders.


int  Clip1Precision =
.....
int  Clip9Precision =
Clip1Precision-Clip9Precision:
  • 1 if input clips is BYTE
  • 2 if UINT16
  • 3 if half-float.
  • Default=1 or the value of the previous clip


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


int  OutputPrecision = 1
OutputPrecision:
  • 1 to convert into BYTE (default)
  • 2 to convert into UINT16
  • 3 to convert into half-float


bool  PlanarOut = true
True to transfer data from the GPU back to the CPU as planar data to reduce memory transfers.
Reading back from the GPU is a serious bottleneck and this generally gives a nice performance boost. Default=true


int  Engines = 1
Engines count.


bool  Resource = false
Resource (don't search for file)


Examples

TODO

Changelog

Version      Date            Changes
v1.6.5 2018/05/13 - Fixed crash on NVidia cards when PlanarOut=true


External Links

  • GitHub - Source code repository.




Back to External Filters

Personal tools