Skip to content

Commit

Permalink
Merge pull request #202 from gizmo98/linear-interpolation
Browse files Browse the repository at this point in the history
Add horizontal and vertical linear interpolation shaders
  • Loading branch information
hizzlekizzle committed May 13, 2023
2 parents 03a7e4b + c774a24 commit cbfd04f
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 0 deletions.
5 changes: 5 additions & 0 deletions interpolation/horizontal-linear.glslp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shaders = "1"
shader0 = "shaders/horizontal-linear.glsl"
filter_linear0 = "true"
scale_type0 = viewport

110 changes: 110 additions & 0 deletions interpolation/shaders/horizontal-linear.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* gizmo98 horizontal-linear shader
* Copyright (C) 2023 gizmo98
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* version 0.1, 10.05.2023
* ---------------------------------------------------------------------------------------
* - initial commit
*
* https://github.com/gizmo98/gizmo-crt-shader
*
* This shader uses texture AA shader code in vertical direction and linear interpolation in
* horizontal direction with only one texel fetch.
*
* uses parts of texture anti-aliasing shader from Ikaros https://www.shadertoy.com/view/ldsSRX
*/

#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;

uniform mat4 MVPMatrix;
uniform COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;

void main()
{
gl_Position = VertexCoord.x * MVPMatrix[0] + VertexCoord.y * MVPMatrix[1] + VertexCoord.z * MVPMatrix[2] + VertexCoord.w * MVPMatrix[3];
TEX0.xy = TexCoord.xy;
}

#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 COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
uniform sampler2D Texture;
COMPAT_VARYING vec4 TEX0;

vec2 saturateA(in vec2 x)
{
return clamp(x, 0.0, 1.0);
}

vec2 magnify(in vec2 uv, in vec2 res)
{
uv *= res;
return (saturateA(fract(uv) / saturateA(fwidth(uv))) + floor(uv) - 0.5) / res.xy;
}
vec4 textureAA(in vec2 uv){
uv.y = magnify(uv,TextureSize.xy).y;
return COMPAT_TEXTURE( Texture, uv );

}

void main()
{
FragColor = textureAA(TEX0.xy);
}
#endif
109 changes: 109 additions & 0 deletions interpolation/shaders/vertical-linear.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* gizmo98 vertical-linear shader
* Copyright (C) 2023 gizmo98
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* version 0.1, 10.05.2023
* ---------------------------------------------------------------------------------------
* - initial commit
*
* https://github.com/gizmo98/gizmo-crt-shader
*
* This shader uses texture AA shader code in horizontal direction and linear interpolation in
* vertical direction with only one texel fetch.
*
* uses parts of texture anti-aliasing shader from Ikaros https://www.shadertoy.com/view/ldsSRX
*/

#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;

uniform mat4 MVPMatrix;
uniform COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;

void main()
{
gl_Position = VertexCoord.x * MVPMatrix[0] + VertexCoord.y * MVPMatrix[1] + VertexCoord.z * MVPMatrix[2] + VertexCoord.w * MVPMatrix[3];
TEX0.xy = TexCoord.xy;
}

#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 COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
uniform sampler2D Texture;
COMPAT_VARYING vec4 TEX0;

vec2 saturateA(in vec2 x)
{
return clamp(x, 0.0, 1.0);
}

vec2 magnify(in vec2 uv, in vec2 res)
{
uv *= res;
return (saturateA(fract(uv) / saturateA(fwidth(uv))) + floor(uv) - 0.5) / res.xy;
}
vec4 textureAA(in vec2 uv){
uv.x = magnify(uv,TextureSize.xy).x;
return COMPAT_TEXTURE( Texture, uv );
}

void main()
{
FragColor = textureAA(TEX0.xy);
}
#endif
5 changes: 5 additions & 0 deletions interpolation/vertical-linear.glslp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shaders = "1"
shader0 = "shaders/vertical-linear.glsl"
filter_linear0 = "true"
scale_type0 = viewport

0 comments on commit cbfd04f

Please sign in to comment.