forked from jaildesigner-jailgames/jaildoctors_dilemma
postfx subpixel
This commit is contained in:
@@ -31,9 +31,10 @@ out vec4 FragColor;
|
|||||||
// Uniforms
|
// Uniforms
|
||||||
uniform sampler2D Texture;
|
uniform sampler2D Texture;
|
||||||
uniform vec2 TextureSize;
|
uniform vec2 TextureSize;
|
||||||
uniform float uVignette; // 0 = sin viñeta, 1 = máxima
|
uniform float uVignette; // 0 = sin viñeta, 1 = máxima
|
||||||
uniform float uScanlines; // 0 = desactivadas, 1 = plenas
|
uniform float uScanlines; // 0 = desactivadas, 1 = plenas
|
||||||
uniform float uChroma; // 0 = sin aberración, 1 = máxima
|
uniform float uChroma; // 0 = sin aberración, 1 = máxima
|
||||||
|
uniform float uOutputHeight; // altura del viewport en pixels de pantalla
|
||||||
|
|
||||||
#if defined(CURVATURE)
|
#if defined(CURVATURE)
|
||||||
vec2 Distort(vec2 coord)
|
vec2 Distort(vec2 coord)
|
||||||
@@ -103,8 +104,20 @@ void main()
|
|||||||
#else
|
#else
|
||||||
float tempY = floor(texcoordInPixels.y) + 0.5;
|
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||||
float yCoord = tempY / TextureSize.y;
|
float yCoord = tempY / TextureSize.y;
|
||||||
|
|
||||||
|
// Scanline en espacio de pantalla (subpíxel)
|
||||||
|
float scaleY = uOutputHeight / TextureSize.y;
|
||||||
|
float screenY = vTexCoord.y * uOutputHeight;
|
||||||
|
float posInRow = mod(screenY, scaleY);
|
||||||
|
float scanLineDY = posInRow / scaleY - 0.5;
|
||||||
|
float localFilterWidth = 1.0 / scaleY;
|
||||||
|
float scanLineWeight = CalcScanLineWeight(scanLineDY);
|
||||||
|
scanLineWeight += CalcScanLineWeight(scanLineDY - localFilterWidth);
|
||||||
|
scanLineWeight += CalcScanLineWeight(scanLineDY + localFilterWidth);
|
||||||
|
scanLineWeight *= 0.3333333;
|
||||||
|
|
||||||
|
// Phosphor blur en espacio textura (sin cambios)
|
||||||
float dy = texcoordInPixels.y - tempY;
|
float dy = texcoordInPixels.y - tempY;
|
||||||
float scanLineWeight = CalcScanLine(dy);
|
|
||||||
float signY = sign(dy);
|
float signY = sign(dy);
|
||||||
dy = dy * dy;
|
dy = dy * dy;
|
||||||
dy = dy * dy;
|
dy = dy * dy;
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ out vec4 FragColor;
|
|||||||
// Uniforms
|
// Uniforms
|
||||||
uniform sampler2D Texture;
|
uniform sampler2D Texture;
|
||||||
uniform vec2 TextureSize;
|
uniform vec2 TextureSize;
|
||||||
uniform float uVignette; // 0 = sin viñeta, 1 = máxima
|
uniform float uVignette; // 0 = sin viñeta, 1 = máxima
|
||||||
uniform float uScanlines; // 0 = desactivadas, 1 = plenas
|
uniform float uScanlines; // 0 = desactivadas, 1 = plenas
|
||||||
uniform float uChroma; // 0 = sin aberración, 1 = máxima
|
uniform float uChroma; // 0 = sin aberración, 1 = máxima
|
||||||
|
uniform float uOutputHeight; // altura del viewport en pixels de pantalla
|
||||||
|
|
||||||
#if defined(CURVATURE)
|
#if defined(CURVATURE)
|
||||||
vec2 Distort(vec2 coord)
|
vec2 Distort(vec2 coord)
|
||||||
@@ -106,8 +107,20 @@ void main()
|
|||||||
#else
|
#else
|
||||||
float tempY = floor(texcoordInPixels.y) + 0.5;
|
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||||
float yCoord = tempY / TextureSize.y;
|
float yCoord = tempY / TextureSize.y;
|
||||||
|
|
||||||
|
// Scanline en espacio de pantalla (subpíxel)
|
||||||
|
float scaleY = uOutputHeight / TextureSize.y;
|
||||||
|
float screenY = vTexCoord.y * uOutputHeight;
|
||||||
|
float posInRow = mod(screenY, scaleY);
|
||||||
|
float scanLineDY = posInRow / scaleY - 0.5;
|
||||||
|
float localFilterWidth = 1.0 / scaleY;
|
||||||
|
float scanLineWeight = CalcScanLineWeight(scanLineDY);
|
||||||
|
scanLineWeight += CalcScanLineWeight(scanLineDY - localFilterWidth);
|
||||||
|
scanLineWeight += CalcScanLineWeight(scanLineDY + localFilterWidth);
|
||||||
|
scanLineWeight *= 0.3333333;
|
||||||
|
|
||||||
|
// Phosphor blur en espacio textura (sin cambios)
|
||||||
float dy = texcoordInPixels.y - tempY;
|
float dy = texcoordInPixels.y - tempY;
|
||||||
float scanLineWeight = CalcScanLine(dy);
|
|
||||||
float signY = sign(dy);
|
float signY = sign(dy);
|
||||||
dy = dy * dy;
|
dy = dy * dy;
|
||||||
dy = dy * dy;
|
dy = dy * dy;
|
||||||
|
|||||||
@@ -338,9 +338,10 @@ auto OpenGLShader::init(SDL_Window* window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Uniforms PostFX
|
// Uniforms PostFX
|
||||||
vignette_location_ = glGetUniformLocation(program_id_, "uVignette");
|
vignette_location_ = glGetUniformLocation(program_id_, "uVignette");
|
||||||
scanlines_location_ = glGetUniformLocation(program_id_, "uScanlines");
|
scanlines_location_ = glGetUniformLocation(program_id_, "uScanlines");
|
||||||
chroma_location_ = glGetUniformLocation(program_id_, "uChroma");
|
chroma_location_ = glGetUniformLocation(program_id_, "uChroma");
|
||||||
|
output_height_location_ = glGetUniformLocation(program_id_, "uOutputHeight");
|
||||||
if (vignette_location_ != -1) { glUniform1f(vignette_location_, postfx_vignette_); }
|
if (vignette_location_ != -1) { glUniform1f(vignette_location_, postfx_vignette_); }
|
||||||
if (scanlines_location_ != -1) { glUniform1f(scanlines_location_, postfx_scanlines_); }
|
if (scanlines_location_ != -1) { glUniform1f(scanlines_location_, postfx_scanlines_); }
|
||||||
if (chroma_location_ != -1) { glUniform1f(chroma_location_, postfx_chroma_); }
|
if (chroma_location_ != -1) { glUniform1f(chroma_location_, postfx_chroma_); }
|
||||||
@@ -446,6 +447,10 @@ void OpenGLShader::render() {
|
|||||||
glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
|
glViewport(viewport_x, viewport_y, viewport_w, viewport_h);
|
||||||
checkGLError("glViewport");
|
checkGLError("glViewport");
|
||||||
|
|
||||||
|
if (output_height_location_ != -1) {
|
||||||
|
glUniform1f(output_height_location_, static_cast<float>(viewport_h));
|
||||||
|
}
|
||||||
|
|
||||||
// Dibujar quad usando VAO
|
// Dibujar quad usando VAO
|
||||||
glBindVertexArray(vao_);
|
glBindVertexArray(vao_);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class OpenGLShader : public ShaderBackend {
|
|||||||
GLint vignette_location_ = -1;
|
GLint vignette_location_ = -1;
|
||||||
GLint scanlines_location_ = -1;
|
GLint scanlines_location_ = -1;
|
||||||
GLint chroma_location_ = -1;
|
GLint chroma_location_ = -1;
|
||||||
|
GLint output_height_location_ = -1;
|
||||||
|
|
||||||
// Valores cacheados de PostFX
|
// Valores cacheados de PostFX
|
||||||
float postfx_vignette_ = 0.6F;
|
float postfx_vignette_ = 0.6F;
|
||||||
|
|||||||
@@ -61,7 +61,12 @@ fragment float4 postfx_fs(PostVOut in [[stage_in]],
|
|||||||
color.b = scene.sample(samp, in.uv - float2( ca, 0.0)).b;
|
color.b = scene.sample(samp, in.uv - float2( ca, 0.0)).b;
|
||||||
color.a = scene.sample(samp, in.uv).a;
|
color.a = scene.sample(samp, in.uv).a;
|
||||||
|
|
||||||
float scan = 0.85 + 0.15 * sin(in.uv.y * 3.14159265 * u.screen_height);
|
float texHeight = float(scene.get_height());
|
||||||
|
float scaleY = u.screen_height / texHeight;
|
||||||
|
float screenY = in.uv.y * u.screen_height;
|
||||||
|
float posInRow = fmod(screenY, scaleY);
|
||||||
|
float scanLineDY = posInRow / scaleY - 0.5;
|
||||||
|
float scan = max(1.0 - scanLineDY * scanLineDY * 6.0, 0.12) * 3.5;
|
||||||
color.rgb *= mix(1.0, scan, u.scanline_strength);
|
color.rgb *= mix(1.0, scan, u.scanline_strength);
|
||||||
|
|
||||||
float2 d = in.uv - float2(0.5, 0.5);
|
float2 d = in.uv - float2(0.5, 0.5);
|
||||||
@@ -312,6 +317,8 @@ void SDL3GPUShader::render() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uniforms_.screen_height = static_cast<float>(sh);
|
||||||
|
|
||||||
// ---- Render pass: PostFX → swapchain ----
|
// ---- Render pass: PostFX → swapchain ----
|
||||||
SDL_GPUColorTargetInfo color_target = {};
|
SDL_GPUColorTargetInfo color_target = {};
|
||||||
color_target.texture = swapchain;
|
color_target.texture = swapchain;
|
||||||
|
|||||||
Reference in New Issue
Block a user