From 83595dfbbcb9e493564d8c0d6418586898581ca3 Mon Sep 17 00:00:00 2001 From: metallic77 <43163462+metallic77@users.noreply.github.com> Date: Thu, 22 Aug 2024 04:13:25 +0300 Subject: [PATCH] add tiny_ntsc shader (#486) * Add files via upload * Add files via upload * Update tiny_ntsc.glsl * Update tiny_ntsc.glsl --- ntsc/shaders/ntsc-simple/kaizer-lp-small.glsl | 117 +++++++++++++ ntsc/shaders/ntsc-simple/tiny_ntsc.glsl | 164 ++++++++++++++++++ ntsc/tiny_ntsc.glslp | 4 + 3 files changed, 285 insertions(+) create mode 100644 ntsc/shaders/ntsc-simple/kaizer-lp-small.glsl create mode 100644 ntsc/shaders/ntsc-simple/tiny_ntsc.glsl create mode 100644 ntsc/tiny_ntsc.glslp diff --git a/ntsc/shaders/ntsc-simple/kaizer-lp-small.glsl b/ntsc/shaders/ntsc-simple/kaizer-lp-small.glsl new file mode 100644 index 0000000..0972be1 --- /dev/null +++ b/ntsc/shaders/ntsc-simple/kaizer-lp-small.glsl @@ -0,0 +1,117 @@ +#version 110 + +/* +kaizer-low-pass DariusG 2023 + +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. +*/ + +#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 COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION 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) + +#ifdef PARAMETER_UNIFORM +uniform COMPAT_PRECISION float WHATEVER; +#else +#define WHATEVER 0.0 +#endif + +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 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; + +// compatibility #defines +#define vTexCoord TEX0.xy +#define Source Texture +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +#ifdef PARAMETER_UNIFORM +uniform COMPAT_PRECISION float compo; +uniform COMPAT_PRECISION float rainbow; + +#else +#define compo 1.0 +#define rainbow 1.0 +#endif + +void main() +{ + vec2 ps = vec2(SourceSize.z,0.0); + vec3 res = COMPAT_TEXTURE(Source,vTexCoord).rgb*0.62; + res += COMPAT_TEXTURE(Source,vTexCoord+ps).rgb*0.39; + res += COMPAT_TEXTURE(Source,vTexCoord+3.0*ps).rgb*-0.1; + res += COMPAT_TEXTURE(Source,vTexCoord+5.0*ps).rgb*0.04; + + FragColor.rgb = res; +} +#endif \ No newline at end of file diff --git a/ntsc/shaders/ntsc-simple/tiny_ntsc.glsl b/ntsc/shaders/ntsc-simple/tiny_ntsc.glsl new file mode 100644 index 0000000..5051f2d --- /dev/null +++ b/ntsc/shaders/ntsc-simple/tiny_ntsc.glsl @@ -0,0 +1,164 @@ +#version 110 + +#pragma parameter comb "Comb Filter" 0.7 0.0 1.0 0.05 +#pragma parameter ln_delay "NES/SNES Line Delay" 1.0 0.0 1.0 1.0 +#pragma parameter sharp_pix "Sharper" 0.0 0.0 1.0 1.0 + +#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 COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION 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) + +#ifdef PARAMETER_UNIFORM +uniform COMPAT_PRECISION float WHATEVER; +#else +#define WHATEVER 0.0 +#endif + +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 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; + +// compatibility #defines +#define vTexCoord TEX0.xy +#define Source Texture +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define OutSize vec4(OutputSize, 1.0 / OutputSize) + +#ifdef PARAMETER_UNIFORM +uniform COMPAT_PRECISION float comb; +uniform COMPAT_PRECISION float ln_delay; +uniform COMPAT_PRECISION float sharp_pix; + +#else +#define comb 0.6 +#define ln_delay 1.0 +#define sharp_pix 0.0 + +#endif + +#define PI 3.14159265358979323846 + +mat3 RGBYUV = mat3(0.299, 0.587, 0.114, + -0.299, -0.587, 0.886, + 0.701, -0.587, -0.114); + +mat3 YUV2RGB = mat3(1.0, 0.0, 1.13983, + 1.0, -0.39465, -0.58060, + 1.0, 2.03211, 0.0); + +// max 170.666 color "dots" per line +#define NTSC_RES 170.6666 + +void main() +{ +float pixsize = 0.75; +if (sharp_pix == 1.0) pixsize = 0.5; +vec2 dxy = vec2(SourceSize.z*pixsize,0.0); +vec2 dy = vec2(0.0,SourceSize.w*0.125); +vec3 final = vec3(0.0); +float sum = 0.0; +int N = 2; +float timer = 0.0; if (InputSize.x < 300.0) timer = mod(float(FrameCount/2),2.0); + +for (int i=0; i