Skip to content

Commit

Permalink
Fixed several issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryx93 committed Dec 1, 2015
1 parent 57c6237 commit 40aac25
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 145 deletions.
9 changes: 9 additions & 0 deletions Release/ChangeLog.txt
@@ -1,3 +1,12 @@
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
- Fixed SuperRes when using Softness parameter
- Shader.dll now treats overflow coordinates with 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

Version 1.2.2: November 29th 2015
- For SuperRes, HLSL Bicubic downscaler is broken and has been disabled. Downscaling is now done in AviSynth
- There will be a performance hit and it will take a lot more memory, but the image will be good. Until HLSL Bicubic is fixed.
Expand Down
8 changes: 4 additions & 4 deletions Release/ColorMatrix/ColorMatrix.avsi
Expand Up @@ -6,10 +6,10 @@ 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=2)
input = ConvertToFloat(precision=1)
Shader(srcYuv ? "Yuv601ToGamma.cso" : "GammaToYuv601.cso")
Shader(srcYuv ? "GammaToYuv.cso" : "YuvToGamma.cso")
ExecuteShader(last, input, precision=2, precisionIn=2, precisionOut=1)
ExecuteShader(last, input, precision=2, precisionIn=1, precisionOut=1)
ConvertFromFloat(format=sourceFormat, precision=1)
}

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=2)
input = ConvertToFloat(precision=1)
Shader(srcYuv ? "YuvToGamma.cso" : "GammaToYuv.cso")
Shader(srcYuv ? "GammaToYuv601.cso" : "Yuv601ToGamma.cso")
ExecuteShader(last, input, precision=2, precisionIn=2, precisionOut=1)
ExecuteShader(last, input, precision=2, precisionIn=1, precisionOut=1)
ConvertFromFloat(format=sourceFormat, precision=1)
}
Binary file modified Release/Shader.dll
Binary file not shown.
30 changes: 18 additions & 12 deletions Release/Super-xBR/super-xbr.avsi
@@ -1,31 +1,35 @@
function SuperXBR(clip input, float "edgeStrength", float "weight", bool "thirdPass", bool "convert")
function SuperXBR(clip input, float "edgeStrength", float "sharpness", bool "thirdPass", bool "convert")
{
edgeStrength = default(edgeStrength, 1)
weight = default(weight, 1)
sharpness = default(sharpness, 1)
thirdPass = default(thirdPass, true)
convert = default(convert, true)

Assert(edgeStrength >= 0 && edgeStrength <= 5, "Edge strength must be between 0 and 5")
Assert(weight >= 0 && weight <= 1.5, "Weight must be between 0 and 1.5")
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")

input

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

input = convert ? ConvertToFloat(precision=2) : last
#convertYuv ? Shader("YuvToGamma.cso") : nop
input = convert ? ConvertToFloat(precision=1) : last

input
inputWidth = convert ? width : width / 2
args_string = string(edgeStrength,"%.32f") + "," + string(weight,"%.32f") + "0,0f"
size0_string = string(inputWidth) + "," + string(height)+"," + string(1./InputWidth,"%.32f") + "," + string(1./height,"%.32f")+"f"
size1_string = string(2*inputWidth) + "," + string(2*height) + "," + string(1./(2*inputWidth),"%.32f") + "," + string(1./(2*height),"%.32f")+"f"
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"

# 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*height)
width=2*inputWidth,height=2*inputHeight)

Shader("super-xbr-pass1.cso",\
param2=args_string,\
Expand All @@ -36,7 +40,9 @@ function SuperXBR(clip input, float "edgeStrength", float "weight", bool "thirdP
param3=size1_string) : nop

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

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

convert ? ConvertFromFloat(format=sourceFormat,precision=1) : last
!thirdPass ? spline36resize(width, height, -.5, -.5, width, height) : last
}
51 changes: 24 additions & 27 deletions Release/SuperRes/SuperRes.avsi
Expand Up @@ -6,46 +6,43 @@ function SuperRes(clip input, int "passes", float "strength", float "softness",
convert = default(convert, true)
srcMatrix601 = default(srcMatrix601, false)

Assert((passes > 0 && passes <= 3) ? true : false, chr(10) + "Passes must be between 1 and 3" + chr(10))
Assert((strength >= 0 && strength <= 1) ? true : false, chr(10) + "Strength must be between 0 and 1" + chr(10))
Assert((softness >= 0 && softness <= 1) ? true : false, chr(10) + "Softness must be between 0 and 1" + chr(10))
Assert(Defined(upscalecommand), chr(10) + "You must specify upscalecommand" + chr(10))
Assert((passes > 0 && passes <= 3) ? true : false, "Passes must be between 1 and 3")
Assert((strength >= 0 && strength <= 1) ? true : false, "Strength must be between 0 and 1")
Assert((softness >= 0 && softness <= 1) ? true : false, "Softness must be between 0 and 1")
Assert(Defined(upscalecommand), "You must specify upscalecommand")

input

convertYuv = convert && !IsRGB()
sourceFormat = IsYV12 ? "YV12" : IsYV24 ? "YV24" : IsRGB24 ? "RGB24" : IsRGB32 ? "RGB32" : ""
Assert(sourceFormat != "", chr(10) + "Source must be YV12, YV24, RGB24 or RGB32" + chr(10))

original = convert ? ConvertToFloat() : last
original = convert ? ConvertToFloat(precision=1) : last
Eval(upscalecommand)
input = convert ? ConvertToFloat() : last
input.Shader(convertYuv && srcMatrix601 ? "Yuv601ToLinear.cso" : convertYuv ? "YuvToLinear.cso" : "GammaToLinear.cso").ExecuteShader(input)
SuperResPass(last, original, strength, softness, 1, passes, convertYuv, srcMatrix601)
passes > 1 ? SuperResPass(last, original, strength, softness, 2, passes, convertYuv, srcMatrix601) : nop
passes > 2 ? SuperResPass(last, original, strength, softness, 3, passes, convertYuv, srcMatrix601) : nop

convert ? ConvertFromFloat(format=sourceFormat) : last
input = convert ? ConvertToFloat(precision=1) : last
input.Shader(convertYuv && srcMatrix601 ? "Yuv601ToLinear.cso" : convertYuv ? "YuvToLinear.cso" : "GammaToLinear.cso")
SuperResPass(last, input, original, strength, softness, 1, passes, convertYuv, srcMatrix601)
passes > 1 ? SuperResPass(input, original, strength, softness, 2, passes, convertYuv, srcMatrix601) : nop
passes > 2 ? SuperResPass(input, original, strength, softness, 3, passes, convertYuv, srcMatrix601) : nop
!convert && srcMatrix601 ? Shader("Yuv601ToGamma.cso").Shader("GammaToYuv.cso") : last

ExecuteShader(last, input, original, precision=3, precisionIn=convert?1:2, precisionOut=convert?1:2)
convert ? ConvertFromFloat(format=sourceFormat, precision=1) : last
}

function SuperResPass(clip cmd, clip input, clip original, float strength, float softness, int pass, int passes, bool convertYuv, bool srcMatrix601)
{
downsample = input.ConvertFromFloat(format="RGB24")
downsample = downsample.BicubicResize(original.Width / 2, original.Height)
downsample = downsample.ConvertToFloat()

# Bicubic HLSL is broken
# cmd.Shader("Bicubic.cso", output=3, \
# param0=string(original.Width / 2) + "," + string(original.Height) + "," + string(1./(original.Width / 2),"%.32f") + "," + string(1./original.Height,"%.32f") + "f",\
# param1=string(input.Width / 2) + "," + string(input.Height) + "," + string(1./(input.Width / 2),"%.32f") + "," + string(1./input.Height,"%.32f") + "f",\
# param2=string(1/3.,"%.32f") + "," + string(1/3.,"%.32f") + "f",\
# width=original.Width / 2, height=original.Height)
input
Shader(convertYuv && srcMatrix601 ? "SuperResDiff601.cso" : convertYuv ? "SuperResDiff709.cso" : "SuperResDiff.cso", clip1=2, clip2=3, output=4)
cmd.Shader("Bicubic.cso", output=3, \
param0=string(original.Width) + "," + string(original.Height) + "," + string(1./original.Width,"%.32f") + "," + string(1./original.Height,"%.32f") + "f",\
param1=string(input.Width) + "," + string(input.Height) + "," + string(1./input.Width,"%.32f") + "," + string(1./input.Height,"%.32f") + "f",\
param2=string(1/3.,"%.32f") + "," + string(1/3.,"%.32f") + "f",\
width=original.Width, height=original.Height)

Shader(convertYuv && srcMatrix601 ? "SuperResDiff601.cso" : convertYuv ? "SuperResDiff709.cso" : "SuperResDiff.cso", clip1=3, clip2=2, output=4)

Shader(pass==passes ? (convertYuv ? "SuperResFinal709.cso" : "SuperResFinal.cso") : "SuperRes.cso", clip1=1, clip2=4, output=1, \
param2=string(original.Width/2) + "," + string(original.Height) + "," + string(1./(original.Width/2),"%.32f") + "," + string(1./original.Height,"%.32f") + "f", \
param0=string(input.Width) + "," + string(input.Height) + "f", \
param1=string(1./input.Width, "%.32f") + "," + string(1./input.Height, "%.32f") + "f", \
param2=string(original.Width) + "," + string(original.Height) + "," + string(1./(original.Width),"%.32f") + "," + string(1./original.Height,"%.32f") + "f", \
Param3=string(strength,"%.32f") + "," + string(softness,"%.32f") + "," + string(pass) + "," + string(passes) + "f")

ExecuteShader(last, input, downsample, original)
}
8 changes: 4 additions & 4 deletions Shaders/ColorMatrix/ColorMatrix.avsi
Expand Up @@ -6,10 +6,10 @@ 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=2)
input = ConvertToFloat(precision=1)
Shader(srcYuv ? "Yuv601ToGamma.cso" : "GammaToYuv601.cso")
Shader(srcYuv ? "GammaToYuv.cso" : "YuvToGamma.cso")
ExecuteShader(last, input, precision=2, precisionIn=2, precisionOut=1)
ExecuteShader(last, input, precision=2, precisionIn=1, precisionOut=1)
ConvertFromFloat(format=sourceFormat, precision=1)
}

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=2)
input = ConvertToFloat(precision=1)
Shader(srcYuv ? "YuvToGamma.cso" : "GammaToYuv.cso")
Shader(srcYuv ? "GammaToYuv601.cso" : "Yuv601ToGamma.cso")
ExecuteShader(last, input, precision=2, precisionIn=2, precisionOut=1)
ExecuteShader(last, input, precision=2, precisionIn=1, precisionOut=1)
ConvertFromFloat(format=sourceFormat, precision=1)
}
12 changes: 7 additions & 5 deletions Shaders/Super-xBR/super-xbr.avsi
Expand Up @@ -7,17 +7,17 @@ function SuperXBR(clip input, float "edgeStrength", float "sharpness", bool "thi

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")

input

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

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

input
#inputWidth = convert ? width : width / 2
inputWidth = width / 2
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"
Expand All @@ -40,7 +40,9 @@ function SuperXBR(clip input, float "edgeStrength", float "sharpness", bool "thi
param3=size1_string) : nop

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

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

!thirdPass ? spline36resize(width, height, -.5, -.5, width, height) : last
}
2 changes: 1 addition & 1 deletion Shaders/SuperRes/CompileHLSL.bat
Expand Up @@ -18,4 +18,4 @@

"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\fxc.exe" /T ps_3_0 /Fo "GammaToLinear.cso" "src\Common\GammaToLinear.hlsl"

REM "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\fxc.exe" /T ps_3_0 /Fo "Bicubic.cso" "src\SuperRes\Bicubic.hlsl"
REM "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\fxc.exe" /T ps_3_0 /Fo "Bicubic.cso" "src\SuperRes\Bicubic.hlsl"
51 changes: 24 additions & 27 deletions Shaders/SuperRes/SuperRes.avsi
Expand Up @@ -6,46 +6,43 @@ function SuperRes(clip input, int "passes", float "strength", float "softness",
convert = default(convert, true)
srcMatrix601 = default(srcMatrix601, false)

Assert((passes > 0 && passes <= 3) ? true : false, chr(10) + "Passes must be between 1 and 3" + chr(10))
Assert((strength >= 0 && strength <= 1) ? true : false, chr(10) + "Strength must be between 0 and 1" + chr(10))
Assert((softness >= 0 && softness <= 1) ? true : false, chr(10) + "Softness must be between 0 and 1" + chr(10))
Assert(Defined(upscalecommand), chr(10) + "You must specify upscalecommand" + chr(10))
Assert((passes > 0 && passes <= 3) ? true : false, "Passes must be between 1 and 3")
Assert((strength >= 0 && strength <= 1) ? true : false, "Strength must be between 0 and 1")
Assert((softness >= 0 && softness <= 1) ? true : false, "Softness must be between 0 and 1")
Assert(Defined(upscalecommand), "You must specify upscalecommand")

input

convertYuv = convert && !IsRGB()
sourceFormat = IsYV12 ? "YV12" : IsYV24 ? "YV24" : IsRGB24 ? "RGB24" : IsRGB32 ? "RGB32" : ""
Assert(sourceFormat != "", chr(10) + "Source must be YV12, YV24, RGB24 or RGB32" + chr(10))

original = convert ? ConvertToFloat() : last
original = convert ? ConvertToFloat(precision=1) : last
Eval(upscalecommand)
input = convert ? ConvertToFloat() : last
input.Shader(convertYuv && srcMatrix601 ? "Yuv601ToLinear.cso" : convertYuv ? "YuvToLinear.cso" : "GammaToLinear.cso").ExecuteShader(input)
SuperResPass(last, original, strength, softness, 1, passes, convert, convertYuv, srcMatrix601)
passes > 1 ? SuperResPass(last, original, strength, softness, 2, passes, convert, convertYuv, srcMatrix601) : nop
passes > 2 ? SuperResPass(last, original, strength, softness, 3, passes, convert, convertYuv, srcMatrix601) : nop

input = convert ? ConvertToFloat(precision=1) : last
input.Shader(convertYuv && srcMatrix601 ? "Yuv601ToLinear.cso" : convertYuv ? "YuvToLinear.cso" : "GammaToLinear.cso")
SuperResPass(last, input, original, strength, softness, 1, passes, convertYuv, srcMatrix601)
passes > 1 ? SuperResPass(input, original, strength, softness, 2, passes, convertYuv, srcMatrix601) : nop
passes > 2 ? SuperResPass(input, original, strength, softness, 3, passes, convertYuv, srcMatrix601) : nop
!convert && srcMatrix601 ? Shader("Yuv601ToGamma.cso").Shader("GammaToYuv.cso") : last

ExecuteShader(last, input, original, precision=3, precisionIn=convert?1:2, precisionOut=convert?1:2)
convert ? ConvertFromFloat(format=sourceFormat, precision=1) : last
}

function SuperResPass(clip cmd, clip input, clip original, float strength, float softness, int pass, int passes, bool convert, bool convertYuv, bool srcMatrix601)
function SuperResPass(clip cmd, clip input, clip original, float strength, float softness, int pass, int passes, bool convertYuv, bool srcMatrix601)
{
downsample = input.ConvertFromFloat(format="RGB24")
downsample = downsample.BicubicResize(original.Width / 2, original.Height)
downsample = downsample.ConvertToFloat()

# Bicubic HLSL is broken
# cmd.Shader("Bicubic.cso", output=3, \
# param0=string(original.Width / 2) + "," + string(original.Height) + "," + string(1./(original.Width / 2),"%.32f") + "," + string(1./original.Height,"%.32f") + "f",\
# param1=string(input.Width / 2) + "," + string(input.Height) + "," + string(1./(input.Width / 2),"%.32f") + "," + string(1./input.Height,"%.32f") + "f",\
# param2=string(1/3.,"%.32f") + "," + string(1/3.,"%.32f") + "f",\
# width=original.Width / 2, height=original.Height)
input
Shader(convertYuv && srcMatrix601 ? "SuperResDiff601.cso" : convertYuv ? "SuperResDiff709.cso" : "SuperResDiff.cso", clip1=2, clip2=3, output=4)
cmd.Shader("Bicubic.cso", output=3, \
param0=string(original.Width) + "," + string(original.Height) + "," + string(1./original.Width,"%.32f") + "," + string(1./original.Height,"%.32f") + "f",\
param1=string(input.Width) + "," + string(input.Height) + "," + string(1./input.Width,"%.32f") + "," + string(1./input.Height,"%.32f") + "f",\
param2=string(1/3.,"%.32f") + "," + string(1/3.,"%.32f") + "f",\
width=original.Width, height=original.Height)

Shader(convertYuv && srcMatrix601 ? "SuperResDiff601.cso" : convertYuv ? "SuperResDiff709.cso" : "SuperResDiff.cso", clip1=3, clip2=2, output=4)

Shader(pass==passes ? (convertYuv ? "SuperResFinal709.cso" : "SuperResFinal.cso") : "SuperRes.cso", clip1=1, clip2=4, output=1, \
param2=string(original.Width/2) + "," + string(original.Height) + "," + string(1./(original.Width/2),"%.32f") + "," + string(1./original.Height,"%.32f") + "f", \
param0=string(input.Width) + "," + string(input.Height) + "f", \
param1=string(1./input.Width, "%.32f") + "," + string(1./input.Height, "%.32f") + "f", \
param2=string(original.Width) + "," + string(original.Height) + "," + string(1./(original.Width),"%.32f") + "," + string(1./original.Height,"%.32f") + "f", \
Param3=string(strength,"%.32f") + "," + string(softness,"%.32f") + "," + string(pass) + "," + string(passes) + "f")

ExecuteShader(last, input, downsample, original, precisionIn=2, precision=3, precisionOut=(convert&&pass==passes?1:2))
}

0 comments on commit 40aac25

Please sign in to comment.