mirror of
https://github.com/libretro/glsl-shaders.git
synced 2024-11-23 07:40:29 +00:00
add nedi shaders
This commit is contained in:
parent
cc79eebc62
commit
671c8ae251
32
nedi/fast-bilateral-nedi.glslp
Normal file
32
nedi/fast-bilateral-nedi.glslp
Normal file
@ -0,0 +1,32 @@
|
||||
shaders = "5"
|
||||
shader0 = ../denoisers/shaders/fast-bilateral.glsl
|
||||
filter_linear0 = false
|
||||
scale_type_0 = source
|
||||
shader1 = "shaders/nedi-pass0.glsl"
|
||||
filter_linear1 = false
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
float_framebuffer1 = "false"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "2.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
shader2 = "shaders/nedi-pass1.glsl"
|
||||
filter_linear2 = false
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
float_framebuffer2 = "false"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "1.000000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "2.000000"
|
||||
shader3 = "shaders/nedi-pass2.glsl"
|
||||
filter_linear3 = false
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
float_framebuffer3 = "false"
|
||||
scale_type_x3 = "source"
|
||||
scale_x3 = "1.000000"
|
||||
scale_type_y3 = "source"
|
||||
scale_y3 = "1.000000"
|
||||
shader4 = "shaders/nedi-jinc.glsl"
|
||||
filter_linear4 = false
|
||||
wrap_mode4 = "clamp_to_border"
|
||||
float_framebuffer4 = "false"
|
29
nedi/nedi.glslp
Normal file
29
nedi/nedi.glslp
Normal file
@ -0,0 +1,29 @@
|
||||
shaders = "4"
|
||||
shader0 = "shaders/nedi-pass0.glsl"
|
||||
filter_linear0 = false
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
float_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "2.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
shader1 = "shaders/nedi-pass1.glsl"
|
||||
filter_linear1 = false
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
float_framebuffer1 = "false"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "1.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "2.000000"
|
||||
shader2 = "shaders/nedi-pass2.glsl"
|
||||
filter_linear2 = false
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
float_framebuffer2 = "false"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "1.000000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "1.000000"
|
||||
shader3 = "shaders/nedi-jinc.glsl"
|
||||
filter_linear3 = false
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
float_framebuffer3 = "false"
|
265
nedi/shaders/nedi-jinc.glsl
Normal file
265
nedi/shaders/nedi-jinc.glsl
Normal file
@ -0,0 +1,265 @@
|
||||
#version 120
|
||||
|
||||
/*
|
||||
Hyllian's jinc windowed-jinc 2-lobe with anti-ringing Shader
|
||||
|
||||
Copyright (C) 2011-2016 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
This is an approximation of Jinc(x)*Jinc(x*r1/r2) for x < 2.5,
|
||||
where r1 and r2 are the first two zeros of jinc function.
|
||||
For a jinc 2-lobe best approximation, use A=0.5 and B=0.825.
|
||||
*/
|
||||
|
||||
// A=0.5, B=0.825 is the best jinc approximation for x<2.5. if B=1.0, it's a lanczos filter.
|
||||
// Increase A to get more blur. Decrease it to get a sharper picture.
|
||||
// B = 0.825 to get rid of dithering. Increase B to get a fine sharpness, though dithering returns.
|
||||
|
||||
// Compatibility #ifdefs needed for parameters
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
// Parameter lines go here:
|
||||
#pragma parameter JINC2_WINDOW_SINC "Window Sinc Param" 0.42 0.0 1.0 0.01
|
||||
#pragma parameter JINC2_SINC "Sinc Param" 0.92 0.0 1.0 0.01
|
||||
#pragma parameter JINC2_AR_STRENGTH "Anti-ringing Strength" 0.8 0.0 1.0 0.1
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
// All parameter floats need to have COMPAT_PRECISION in front of them
|
||||
uniform COMPAT_PRECISION float JINC2_WINDOW_SINC;
|
||||
uniform COMPAT_PRECISION float JINC2_SINC;
|
||||
uniform COMPAT_PRECISION float JINC2_AR_STRENGTH;
|
||||
#else
|
||||
#define JINC2_WINDOW_SINC 0.42
|
||||
#define JINC2_SINC 0.92
|
||||
#define JINC2_AR_STRENGTH 0.8
|
||||
#endif
|
||||
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
#define lerp(a,b,c) mix(a,b,c)
|
||||
#define mul(a,b) (b*a)
|
||||
#define fmod(c) mod(c)
|
||||
#define frac(c) fract(c)
|
||||
#define tex2D(a,b) COMPAT_TEXTURE(a,b)
|
||||
#define float2 vec2
|
||||
#define float3 vec3
|
||||
#define float4 vec4
|
||||
#define int2 ivec2
|
||||
#define int3 ivec3
|
||||
#define int4 ivec4
|
||||
#define bool2 bvec2
|
||||
#define bool3 bvec3
|
||||
#define bool4 bvec4
|
||||
#define float2x2 mat2x2
|
||||
#define float3x3 mat3x3
|
||||
#define float4x4 mat4x4
|
||||
#define float4x3 mat4x3
|
||||
|
||||
#define halfpi 1.5707963267948966192313216916398
|
||||
#define pi 3.1415926535897932384626433832795
|
||||
#define wa (JINC2_WINDOW_SINC*pi)
|
||||
#define wb (JINC2_SINC*pi)
|
||||
|
||||
const float3 Y = float3(0.299, 0.587, 0.114);
|
||||
|
||||
float df(float A, float B)
|
||||
{
|
||||
return abs(A-B);
|
||||
}
|
||||
|
||||
// Calculates the distance between two points
|
||||
float d(float2 pt1, float2 pt2)
|
||||
{
|
||||
float2 v = pt2 - pt1;
|
||||
return sqrt(dot(v,v));
|
||||
}
|
||||
|
||||
float3 min4(float3 a, float3 b, float3 c, float3 d)
|
||||
{
|
||||
return min(a, min(b, min(c, d)));
|
||||
}
|
||||
|
||||
float3 max4(float3 a, float3 b, float3 c, float3 d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
float4 resampler(float4 x)
|
||||
{
|
||||
float4 res;
|
||||
|
||||
res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(wa*wb) : sin(x*wa)*sin(x*wb)/(x*x);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy * 1.0001;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
#define texture(c, d) COMPAT_TEXTURE(c, d)
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
float3 color;
|
||||
float4x4 weights;
|
||||
|
||||
float2 dx = float2(1.0, 0.0);
|
||||
float2 dy = float2(0.0, 1.0);
|
||||
|
||||
float2 pc = vTexCoord*SourceSize.xy;
|
||||
|
||||
float2 tc = (floor(pc-float2(0.4999,0.4999))+float2(0.4999,0.4999));
|
||||
|
||||
weights[0] = resampler(float4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy)));
|
||||
weights[1] = resampler(float4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx )));
|
||||
weights[2] = resampler(float4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy)));
|
||||
weights[3] = resampler(float4(d(pc, tc -dx+2.0*dy), d(pc, tc +2.0*dy), d(pc, tc +dx+2.0*dy), d(pc, tc+2.0*dx+2.0*dy)));
|
||||
|
||||
//weights[0][0] = weights[0][3] = weights[3][0] = weights[3][3] = 0.0;
|
||||
|
||||
dx = dx * SourceSize.zw;
|
||||
dy = dy * SourceSize.zw;
|
||||
tc = tc * SourceSize.zw;
|
||||
|
||||
// reading the texels
|
||||
|
||||
float3 c00 = tex2D(Source, tc -dx -dy).xyz;
|
||||
float3 c10 = tex2D(Source, tc -dy).xyz;
|
||||
float3 c20 = tex2D(Source, tc +dx -dy).xyz;
|
||||
float3 c30 = tex2D(Source, tc+2.0*dx -dy).xyz;
|
||||
float3 c01 = tex2D(Source, tc -dx ).xyz;
|
||||
float3 c11 = tex2D(Source, tc ).xyz;
|
||||
float3 c21 = tex2D(Source, tc +dx ).xyz;
|
||||
float3 c31 = tex2D(Source, tc+2.0*dx ).xyz;
|
||||
float3 c02 = tex2D(Source, tc -dx +dy).xyz;
|
||||
float3 c12 = tex2D(Source, tc +dy).xyz;
|
||||
float3 c22 = tex2D(Source, tc +dx +dy).xyz;
|
||||
float3 c32 = tex2D(Source, tc+2.0*dx +dy).xyz;
|
||||
float3 c03 = tex2D(Source, tc -dx+2.0*dy).xyz;
|
||||
float3 c13 = tex2D(Source, tc +2.0*dy).xyz;
|
||||
float3 c23 = tex2D(Source, tc +dx+2.0*dy).xyz;
|
||||
float3 c33 = tex2D(Source, tc+2.0*dx+2.0*dy).xyz;
|
||||
|
||||
|
||||
|
||||
color = mul(weights[0], float4x3(c00, c10, c20, c30));
|
||||
color+= mul(weights[1], float4x3(c01, c11, c21, c31));
|
||||
color+= mul(weights[2], float4x3(c02, c12, c22, c32));
|
||||
color+= mul(weights[3], float4x3(c03, c13, c23, c33));
|
||||
color = color/(dot(mul(weights, float4(1.0)), float4(1.0)));
|
||||
|
||||
|
||||
|
||||
// Anti-ringing
|
||||
// Get min/max samples
|
||||
|
||||
float3 min_sample = min4(c11, c21, c12, c22);
|
||||
float3 max_sample = max4(c11, c21, c12, c22);
|
||||
|
||||
float3 aux = color;
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
color = mix(aux, color, JINC2_AR_STRENGTH);
|
||||
|
||||
// final sum and weight normalization
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
#endif
|
241
nedi/shaders/nedi-pass0.glsl
Normal file
241
nedi/shaders/nedi-pass0.glsl
Normal file
@ -0,0 +1,241 @@
|
||||
#version 150
|
||||
|
||||
/*
|
||||
NEDI Shader - pass0
|
||||
|
||||
// This file is a part of MPDN Extensions.
|
||||
// https://github.com/zachsaw/MPDN_Extensions
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3.0 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library.
|
||||
//
|
||||
|
||||
Sources ported from this discussion thread:
|
||||
|
||||
http://forum.doom9.org/showthread.php?t=170727
|
||||
|
||||
Ported by Hyllian - 2015.
|
||||
*/
|
||||
|
||||
// Compatibility #ifdefs needed for parameters
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
#define lerp(c) mix(c)
|
||||
#define mul(a,b) (b*a)
|
||||
#define fmod(c) mod(c)
|
||||
#define frac(c) fract(c)
|
||||
#define tex2D(a,b) COMPAT_TEXTURE(a,b)
|
||||
#define float2 vec2
|
||||
#define float3 vec3
|
||||
#define float4 vec4
|
||||
#define int2 ivec2
|
||||
#define int3 ivec3
|
||||
#define int4 ivec4
|
||||
#define bool2 bvec2
|
||||
#define bool3 bvec3
|
||||
#define bool4 bvec4
|
||||
#define float2x2 mat2x2
|
||||
#define float2x3 mat2x3
|
||||
#define float3x3 mat3x3
|
||||
#define float4x4 mat4x4
|
||||
#define float4x2 mat4x2
|
||||
|
||||
#define NEDI_WEIGHT 4.0
|
||||
#define NEDI_N 24.0
|
||||
#define NEDI_E 0.0
|
||||
#define NEDI_OFFSET 0.0
|
||||
|
||||
#define ITERATIONS 3
|
||||
#define WGT 2
|
||||
|
||||
#define width (SourceSize.x)
|
||||
#define height (SourceSize.y)
|
||||
|
||||
#define px (0.49999 / (SourceSize.x))
|
||||
#define py (0.49999 / (SourceSize.y))
|
||||
|
||||
#define offset NEDI_OFFSET
|
||||
//#define offset 0.0
|
||||
|
||||
#define Value(xy) (tex2D(Source,tex+float2(px,py)*(xy)).rgb)//-float4(0.0,0.4999,0.4999,0.0))
|
||||
|
||||
#define Get(xy) (dot(Value(xy),float3(.2126, .7152, .0722))+offset)
|
||||
#define Get4(xy) (float2(Get(xy+WGT*dir[0])+Get(xy+WGT*dir[1]),Get(xy+WGT*dir[2])+Get(xy+WGT*dir[3])))
|
||||
|
||||
#define sqr(x) (dot(x,x))
|
||||
#define I (float2x2(1.,0.,0.,1.))
|
||||
|
||||
//Cramer's method
|
||||
float2 solve(float2x2 A,float2 b)
|
||||
{
|
||||
return float2(determinant(float2x2(b,A[1])),determinant(float2x2(A[0],b)))/determinant(A);
|
||||
}
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy * 1.0001;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
#define texture(c, d) COMPAT_TEXTURE(c, d)
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
float2 tex = vTexCoord + float2(0.0, 0.25*SourceSize.w);
|
||||
|
||||
float4 c0 = tex2D(Source,tex);
|
||||
|
||||
//Skip pixels on wrong grid
|
||||
if (frac(tex.x*width)<0.49999)
|
||||
{
|
||||
FragColor = c0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
wind[1] wind[2]
|
||||
-3
|
||||
-2 dir wind[0] 2 1
|
||||
-1 4 4 4 4
|
||||
0 1 2 1 2
|
||||
1 3 3 3 3
|
||||
2 1 2
|
||||
3
|
||||
*/
|
||||
/*
|
||||
wind[1] wind[2]
|
||||
-3 3 3
|
||||
-2 dir wind[0]
|
||||
-1 0 3 0 3 0 1
|
||||
0
|
||||
1 2 1 2 1 1 0
|
||||
2
|
||||
3 2 2
|
||||
*/
|
||||
|
||||
//Define window and directions - original
|
||||
float2 dir[4] = {{-1.,-1.},{1.,1.},{-1.,1.},{1.,-1.}};
|
||||
float4x2 wind[4] = {{{-1.,-1.},{1.,1.},{-1.,1.},{1.,-1.}},{{-3.,-1.},{3.,1.},{-1.,3.},{1.,-3.}},{{-3.,1.},{3.,-1.},{1.,3.},{-1.,-3.}},{{-3.,-3.},{ 3.,3.},{-3., 3.},{3.,-3.}}};
|
||||
|
||||
//Initialization
|
||||
float2x2 R = float2x2(0.0);
|
||||
float2 r = float2(0.0);
|
||||
|
||||
float m[4] = {NEDI_WEIGHT, 1.0, 1.0, 1.0};
|
||||
|
||||
//Calculate (local) autocorrelation coefficients
|
||||
for (int k = 0; k<ITERATIONS; k+= 1){
|
||||
float4 y = float4(Get(wind[k][0]),Get(wind[k][1]),Get(wind[k][2]),Get(wind[k][3]));
|
||||
float4x2 C = float4x2(Get4(wind[k][0]),Get4(wind[k][1]),Get4(wind[k][2]),Get4(wind[k][3]));
|
||||
R += mul(transpose(C),m[k]*C);
|
||||
r += mul(y,m[k]*C);
|
||||
}
|
||||
|
||||
//Normalize
|
||||
float n = NEDI_N;
|
||||
R /= n; r /= n;
|
||||
|
||||
//Calculate a = R^-1 . r
|
||||
float e = NEDI_E;
|
||||
float2 a = solve(R+e*e*I,r+e*e/2.0);
|
||||
|
||||
//Nomalize 'a' (prevents overshoot)
|
||||
a = .25 + float2(.4999,-.4999)*clamp(a[0]-a[1],-1.0,1.0);
|
||||
|
||||
//Calculate result
|
||||
float2x3 x = float2x3(Value(dir[0])+Value(dir[1]),Value(dir[2])+Value(dir[3])) * float2x2(a,a);
|
||||
float3 c = float3(x[0].xyz);
|
||||
|
||||
FragColor = vec4(c, 1.0);
|
||||
}
|
||||
}
|
||||
#endif
|
240
nedi/shaders/nedi-pass1.glsl
Normal file
240
nedi/shaders/nedi-pass1.glsl
Normal file
@ -0,0 +1,240 @@
|
||||
#version 150
|
||||
|
||||
/*
|
||||
NEDI Shader - pass1
|
||||
|
||||
// This file is a part of MPDN Extensions.
|
||||
// https://github.com/zachsaw/MPDN_Extensions
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3.0 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library.
|
||||
//
|
||||
|
||||
Sources ported from this discussion thread:
|
||||
|
||||
http://forum.doom9.org/showthread.php?t=170727
|
||||
|
||||
Ported by Hyllian - 2015.
|
||||
*/
|
||||
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
#define lerp(c) mix(c)
|
||||
#define mul(a,b) (b*a)
|
||||
#define fmod(c) mod(c)
|
||||
#define frac(c) fract(c)
|
||||
#define tex2D(a,b) COMPAT_TEXTURE(a,b)
|
||||
#define float2 vec2
|
||||
#define float3 vec3
|
||||
#define float4 vec4
|
||||
#define int2 ivec2
|
||||
#define int3 ivec3
|
||||
#define int4 ivec4
|
||||
#define bool2 bvec2
|
||||
#define bool3 bvec3
|
||||
#define bool4 bvec4
|
||||
#define float2x2 mat2x2
|
||||
#define float2x3 mat2x3
|
||||
#define float3x3 mat3x3
|
||||
#define float4x4 mat4x4
|
||||
#define float4x2 mat4x2
|
||||
|
||||
#define s0 Source
|
||||
#define FIX(c) (c * 1.00001)
|
||||
|
||||
#define NEDI_WEIGHT2 4.0
|
||||
#define NEDI_N2 24.0
|
||||
#define NEDI_E2 0.0
|
||||
#define NEDI_OFFSET2 0.0
|
||||
|
||||
#define ITERATIONS 3
|
||||
#define WGT 2
|
||||
|
||||
#define width (SourceSize.x)
|
||||
#define height (SourceSize.y)
|
||||
|
||||
#define px (1.0 * (SourceSize.z))
|
||||
#define py (0.4999 * (SourceSize.w))
|
||||
|
||||
#define offset NEDI_OFFSET2
|
||||
|
||||
#define Value(xy) (tex2D(s0,tex+float2(px,py)*(xy)).rgb)//-float4(0,0.4999,0.4999,0))
|
||||
|
||||
#define Get(xy) (dot(Value(xy),float3(.2126, .7152, .0722))+offset)
|
||||
#define Get4(xy) (float2(Get(xy+WGT*dir[0])+Get(xy+WGT*dir[1]),Get(xy+WGT*dir[2])+Get(xy+WGT*dir[3])))
|
||||
|
||||
#define sqr(x) (dot(x,x))
|
||||
#define I (float2x2(1.,0.,0.,1.))
|
||||
|
||||
//Cramer's method
|
||||
float2 solve(float2x2 A,float2 b)
|
||||
{
|
||||
return float2(determinant(float2x2(b,A[1])),determinant(float2x2(A[0],b)))/determinant(A);
|
||||
}
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
// out variables go here as COMPAT_VARYING whatever
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy * 1.0001;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
#define texture(c, d) COMPAT_TEXTURE(c, d)
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
float2 tex = vTexCoord;
|
||||
|
||||
float4 c0 = tex2D(s0,tex);
|
||||
|
||||
//Skip pixels on wrong grid
|
||||
if ((frac(tex.x*width/2.0)<0.5)&&(frac(tex.y*height)<0.5) || (frac(tex.x*width/2.0)>0.5)&&(frac(tex.y*height)>0.5))
|
||||
{
|
||||
FragColor = c0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//Define window and directions
|
||||
float2 dir[4] = {{-1.,0.},{1.,0.},{0.,1.},{0.,-1.}};
|
||||
float4x2 wind[7] = {{{-1.,0.},{1.,0.},{0.,1.},{0.,-1.}},{{-2.,-1.},{2.,1.},{-1.,2.},{1.,-2.}},{{-3.,-2.},{3.,2.},{-2.,3.},{2.,-3.}},
|
||||
{{-2.,1.},{2.,-1.},{1.,2.},{-1.,-2.}},{{-3.,2.},{3.,-2.},{2.,3.},{-2.,-3.}},
|
||||
{{-4.,-1.},{4.,1.},{-1.,4.},{1.,-4.}},{{-4.,1.},{4.,-1.},{1.,4.},{-1.,-4.}}};
|
||||
|
||||
/*
|
||||
wind[1] wind[2]
|
||||
-3
|
||||
-2 dir wind[0] 2 1
|
||||
-1 4 4 4 4
|
||||
0 1 2 1 2
|
||||
1 3 3 3 3
|
||||
2 1 2
|
||||
3
|
||||
*/
|
||||
|
||||
/*
|
||||
wind[1] wind[2]
|
||||
-3 3 1
|
||||
-2 dir wind[0]
|
||||
-1 1 4 1 3 1 3
|
||||
0
|
||||
1 3 2 2 4 4 2
|
||||
2
|
||||
3 2 4
|
||||
*/
|
||||
|
||||
//Initialization
|
||||
float2x2 R = float2x2(0.0);
|
||||
float2 r = float2(0.0);
|
||||
|
||||
float m[7] = {NEDI_WEIGHT2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
|
||||
|
||||
//Calculate (local) autocorrelation coefficients
|
||||
for (int k = 0; k<ITERATIONS; k+= 1){
|
||||
float4 y = float4(Get(wind[k][0]),Get(wind[k][1]),Get(wind[k][2]),Get(wind[k][3]));
|
||||
float4x2 C = float4x2(Get4(wind[k][0]),Get4(wind[k][1]),Get4(wind[k][2]),Get4(wind[k][3]));
|
||||
R += mul(transpose(C),m[k]*C);
|
||||
r += mul(y,m[k]*C);
|
||||
}
|
||||
|
||||
//Normalize
|
||||
float n = NEDI_N2;
|
||||
R /= n; r /= n;
|
||||
|
||||
//Calculate a = R^-1 . r
|
||||
float e = NEDI_E2;
|
||||
float2 a = solve(R+e*e*I,r+e*e/2.0);
|
||||
|
||||
//Nomalize 'a' (prevents overshoot)
|
||||
a = .25 + float2(.4999,-.4999)*clamp(a[0]-a[1],-1.0,1.0);
|
||||
|
||||
//Calculate result
|
||||
float2x3 x = float2x3(Value(dir[0])+Value(dir[1]),Value(dir[2])+Value(dir[3])) * float2x2(a,a);
|
||||
float3 c = float3(x[0].xyz);
|
||||
|
||||
FragColor = float4(c, 1.0);//+float4(0,0.49999,0.49999,0);
|
||||
}
|
||||
}
|
||||
#endif
|
230
nedi/shaders/nedi-pass2.glsl
Normal file
230
nedi/shaders/nedi-pass2.glsl
Normal file
@ -0,0 +1,230 @@
|
||||
#version 150
|
||||
|
||||
/*
|
||||
NEDI Shader - pass2
|
||||
|
||||
// This file is a part of MPDN Extensions.
|
||||
// https://github.com/zachsaw/MPDN_Extensions
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3.0 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library.
|
||||
//
|
||||
|
||||
Sources ported from this discussion thread:
|
||||
|
||||
http://forum.doom9.org/showthread.php?t=170727
|
||||
|
||||
Ported by Hyllian - 2015.
|
||||
*/
|
||||
|
||||
// Compatibility #ifdefs needed for parameters
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
#define lerp(c) mix(c)
|
||||
#define mul(a,b) (b*a)
|
||||
#define fmod(c) mod(c)
|
||||
#define frac(c) fract(c)
|
||||
#define tex2D(a,b) COMPAT_TEXTURE(a,b)
|
||||
#define float2 vec2
|
||||
#define float3 vec3
|
||||
#define float4 vec4
|
||||
#define int2 ivec2
|
||||
#define int3 ivec3
|
||||
#define int4 ivec4
|
||||
#define bool2 bvec2
|
||||
#define bool3 bvec3
|
||||
#define bool4 bvec4
|
||||
#define float2x2 mat2x2
|
||||
#define float2x3 mat2x3
|
||||
#define float3x3 mat3x3
|
||||
#define float4x4 mat4x4
|
||||
#define float4x2 mat4x2
|
||||
|
||||
#define s0 Source
|
||||
|
||||
#define NEDI_WEIGHT3 2.0
|
||||
#define NEDI_N3 24.0
|
||||
#define NEDI_E3 0.0
|
||||
|
||||
#define ITERATIONS 3
|
||||
#define WGT NEDI_WEIGHT3
|
||||
|
||||
#define width (SourceSize.x)
|
||||
#define height (SourceSize.y)
|
||||
|
||||
#define px (0.49999 * (SourceSize.z))
|
||||
#define py (0.49999 * (SourceSize.w))
|
||||
|
||||
#define offset 0.0
|
||||
|
||||
#define Value(xy) (tex2D(s0,tex+float2(px,py)*(xy)).rgb)//-float4(0,0.5,0.5,0))
|
||||
|
||||
#define Get(xy) (dot(Value(xy),float3(0.299,0.587,0.114))+offset)
|
||||
#define Get4(xy) (float2(Get(xy+WGT*dir[0])+Get(xy+WGT*dir[1]),Get(xy+WGT*dir[2])+Get(xy+WGT*dir[3])))
|
||||
|
||||
#define sqr(x) (dot(x,x))
|
||||
#define I (float2x2(1,0,0,1))
|
||||
|
||||
//Cramer's method
|
||||
float2 solve(float2x2 A,float2 b)
|
||||
{
|
||||
return float2(determinant(float2x2(b,A[1])),determinant(float2x2(A[0],b)))/determinant(A);
|
||||
}
|
||||
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 COLOR;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 COL0;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
vec4 _oPosition1;
|
||||
uniform mat4 MVPMatrix;
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
|
||||
// compatibility #defines
|
||||
#define vTexCoord TEX0.xy
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * VertexCoord;
|
||||
TEX0.xy = TexCoord.xy * 1.0001;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
uniform int FrameDirection;
|
||||
uniform int FrameCount;
|
||||
uniform COMPAT_PRECISION vec2 OutputSize;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION vec2 InputSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
#define texture(c, d) COMPAT_TEXTURE(c, d)
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||||
#define OutSize vec4(OutputSize, 1.0 / OutputSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
float2 tex = vTexCoord - float2(0.4999,0.4999)/SourceSize.xy;
|
||||
|
||||
/*
|
||||
wind[1] wind[2]
|
||||
-3
|
||||
-2 dir wind[0] 2 1
|
||||
-1 4 4 4 4
|
||||
0 1 2 1 2
|
||||
1 3 3 3 3
|
||||
2 1 2
|
||||
3
|
||||
*/
|
||||
/*
|
||||
wind[1] wind[2]
|
||||
-3 3 1
|
||||
-2 dir wind[0]
|
||||
-1 1 4 1 3 1 3
|
||||
0
|
||||
1 3 2 2 4 4 2
|
||||
2
|
||||
3 2 4
|
||||
*/
|
||||
|
||||
//Define window and directions
|
||||
float2 dir[4] = {{-1.,-1.},{1.,1.},{-1.,1.},{1.,-1.}};
|
||||
float4x2 wind[4] = {{{-1.,-1.},{1.,1.},{-1.,1.},{1.,-1.}},{{-3.,-1.},{3.,1.},{-1.,3.},{1.,-3.}},{{-3.,1.},{3.,-1.},{1.,3.},{-1.,-3.}},{{-3.,-3.},{ 3.,3.},{-3., 3.},{3.,-3.}}};
|
||||
|
||||
//Initialization
|
||||
float2x2 R = float2x2(0.0);
|
||||
float2 r = float2(0.0);
|
||||
|
||||
//Calculate (local) autocorrelation coefficients
|
||||
for (int k = 0; k<ITERATIONS; k+= 1){
|
||||
float4 y = float4(Get(wind[k][0]),Get(wind[k][1]),Get(wind[k][2]),Get(wind[k][3]));
|
||||
float4x2 C = float4x2(Get4(wind[k][0]),Get4(wind[k][1]),Get4(wind[k][2]),Get4(wind[k][3]));
|
||||
R += mul(transpose(C),C);
|
||||
r += mul(y,C);
|
||||
}
|
||||
|
||||
//Normalize
|
||||
float n = NEDI_N3;
|
||||
R /= n; r /= n;
|
||||
|
||||
//Calculate a = R^-1 . r
|
||||
float e = NEDI_E3;
|
||||
float2 a = solve(R+e*e*I,r+e*e/2.0);
|
||||
|
||||
//Nomalize 'a' (prevents overshoot)
|
||||
a = .25 + float2(.4999,-.4999)*clamp(a[0]-a[1],-1.0,1.0);
|
||||
|
||||
//Calculate result
|
||||
float2x3 x = float2x3(Value(dir[0])+Value(dir[1]),Value(dir[2])+Value(dir[3])) * float2x2(a,a);
|
||||
float3 c = float3(x[0].xyz);
|
||||
|
||||
// float3 c = Value(dir[0]);
|
||||
|
||||
FragColor = float4(c, 1.0);//+float4(0,0.5,0.5,0);
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user