hq2x shader using modernised syntax

This commit is contained in:
minjaesong
2023-07-22 03:41:09 +09:00
parent 91d94d2dab
commit cdfc86398c
3 changed files with 11 additions and 13 deletions

View File

@@ -47,7 +47,7 @@ class Hq2x : Disposable {
program = compileShader(
Gdx.files.classpath("shaders/hq2x.vert"),
Gdx.files.classpath("shaders/hq2x.frag"),
"#define SCALE ${scaleFactor}.0")
"")
lutTexture = Texture(Gdx.files.classpath("shaders/hq${scaleFactor}x.png"))

View File

@@ -1,6 +1,8 @@
#version 150
// This float value should be defined from the compiling code.
// #define SCALE [2, 3, 4].0
#define SCALE 2.0
#ifdef GL_ES
#define PRECISION mediump
precision PRECISION float;
@@ -13,12 +15,14 @@ uniform sampler2D u_texture;
uniform sampler2D u_lut;
uniform vec2 u_textureSize;
varying vec4 v_texCoord[4];
in vec4 v_texCoord[4];
const mat3 YUV_MATRIX = mat3(0.299, 0.587, 0.114, -0.169, -0.331, 0.5, 0.5, -0.419, -0.081);
const vec3 YUV_THRESHOLD = vec3(48.0/255.0, 7.0/255.0, 6.0/255.0);
const vec3 YUV_OFFSET = vec3(0, 0.5, 0.5);
out vec4 fragColor;
bool diff(vec3 yuv1, vec3 yuv2) {
return any(greaterThan(abs((yuv1 + YUV_OFFSET) - (yuv2 + YUV_OFFSET)), YUV_THRESHOLD));
}
@@ -79,5 +83,5 @@ void main() {
float sum = dot(weights, vec4(1));
vec3 res = (pixels * (weights / sum)).rgb;
gl_FragColor.rgb = res;
fragColor.rgb = res;
}

View File

@@ -1,17 +1,11 @@
#ifdef GL_ES
#define PRECISION mediump
precision PRECISION float;
precision PRECISION int;
#else
#define PRECISION
#endif
#version 150
attribute vec4 a_position;
attribute vec2 a_texCoord0;
in vec4 a_position;
in vec2 a_texCoord0;
uniform vec2 u_textureSize;
varying vec4 v_texCoord[4];
out vec4 v_texCoord[4];
void main() {
gl_Position = a_position;