From daa0e611a675a28f8342bdc38207969ca3ab2f1f Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 13 Nov 2010 01:56:02 +0100 Subject: [PATCH] Pixels, mhhhm --- config.h | 2 +- hqflt/pixellate.cg | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 hqflt/pixellate.cg diff --git a/config.h b/config.h index edeb0f3ab8..841bc00b77 100644 --- a/config.h +++ b/config.h @@ -65,7 +65,7 @@ static const bool vsync = true; static const bool video_smooth = false; // Path to custom Cg shader. If using custom shaders, it is recommended to disable video_smooth and VIDEO_FILTER. -static const char *cg_shader_path = "hqflt/crt.cg"; +static const char *cg_shader_path = "hqflt/pixellate.cg"; // On resize and fullscreen, rendering area will stay 4:3 static const bool force_aspect = true; diff --git a/hqflt/pixellate.cg b/hqflt/pixellate.cg new file mode 100755 index 0000000000..60b490f9bf --- /dev/null +++ b/hqflt/pixellate.cg @@ -0,0 +1,37 @@ +struct output +{ + float4 color : COLOR; +}; + + output main(uniform sampler2D rubyTexture : TEXUNIT0, float2 gl_TexCoord : TEXCOORD0) { + float2 rubyTextureSize = float2(256.0, 224.0); + float2 texelSize = 1.0 / rubyTextureSize; + + float2 range; + range.x = dFdx(gl_TexCoord.x) / 2.0 * 0.99; + range.y = dFdy(gl_TexCoord.y) / 2.0 * 0.99; + + float left = gl_TexCoord.x - range.x; + float top = gl_TexCoord.y + range.y; + float right = gl_TexCoord.x + range.x; + float bottom = gl_TexCoord.y - range.y; + + float4 topLeftColor = tex2D(rubyTexture, (floor(float2(left, top) / texelSize) + 0.5) * texelSize); + float4 bottomRightColor = tex2D(rubyTexture, (floor(float2(right, bottom) / texelSize) + 0.5) * texelSize); + float4 bottomLeftColor = tex2D(rubyTexture, (floor(float2(left, bottom) / texelSize) + 0.5) * texelSize); + float4 topRightColor = tex2D(rubyTexture, (floor(float2(right, top) / texelSize) + 0.5) * texelSize); + + float2 border = clamp(round(gl_TexCoord / texelSize) * texelSize, float2(left, bottom), float2(right, top)); + + float totalArea = 4.0 * range.x * range.y; + + float4 averageColor; + averageColor = ((border.x - left) * (top - border.y) / totalArea) * topLeftColor; + averageColor += ((right - border.x) * (border.y - bottom) / totalArea) * bottomRightColor; + averageColor += ((border.x - left) * (border.y - bottom) / totalArea) * bottomLeftColor; + averageColor += ((right - border.x) * (top - border.y) / totalArea) * topRightColor; + + output OUT; + OUT.color = averageColor; + return OUT; + }