bsnes/pixelshaders/Pixellate/fragment

37 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

Update to bsnes v060 release. This is a long-term stable release. A full changelog will be available at the forum link below later in the day. Also, please note that I have merged all of the various distributions into two packages. The Windows binary package now contains both the profile-optimized (fast) build, and the debugger build. The source code package now contains sources for bsnes, snesreader, snesfilter and supergameboy. Changelog: - added Direct3D HLSL pixel shader support [mudlord] - fixed a signal issue that caused loading games to take 1-2 seconds longer in v059 - 21fx API revised to its final form, S-MSU (public documentation pending) - worked around QTBUG-7188 to fix multi-file 7-zip file listbox to update when scrolling - added scale max - normal, wide, and wide zoom modes to fullscreen mode - added overscan cropping tool (needed for wide zoom mode; useful for developers simulating games on a real TV) - added "go up one folder" button to file load dialog - added group (un)assignment to the input settings window - now honors input.allowInvalidInput setting; defaults to false [Jonas Quinn] - cheat code editor grays out empty slots - cheat code editor adds "clear selected" button to quickly erase multiple cheat codes - to load folders as game images, folders must end in .sfc, .bs, .st, .gb now - debugger: added S-CPU (H)DMA registers; S-SMP registers; S-DSP registers to properties list - snesfilter: HQ2x filter is now multi-threaded (scales infinitely: the more cores you have, the less overhead required) - pixelshaders: added screen curvature shader to simulate curved CRT tubes - source: lots of code cleanup, as always
2010-02-09 00:58:03 +00:00
//Pixellate shader
//license: GPL
//author: Fes
uniform sampler2D rubyTexture;
uniform vec2 rubyTextureSize;
void main() {
vec2 texelSize = 1.0 / rubyTextureSize;
vec2 range;
range.x = dFdx(gl_TexCoord[0].x) / 2.0 * 0.99;
range.y = dFdy(gl_TexCoord[0].y) / 2.0 * 0.99;
float left = gl_TexCoord[0].x - range.x;
float top = gl_TexCoord[0].y + range.y;
float right = gl_TexCoord[0].x + range.x;
float bottom = gl_TexCoord[0].y - range.y;
vec4 topLeftColor = texture2D(rubyTexture, (floor(vec2(left, top) / texelSize) + 0.5) * texelSize);
vec4 bottomRightColor = texture2D(rubyTexture, (floor(vec2(right, bottom) / texelSize) + 0.5) * texelSize);
vec4 bottomLeftColor = texture2D(rubyTexture, (floor(vec2(left, bottom) / texelSize) + 0.5) * texelSize);
vec4 topRightColor = texture2D(rubyTexture, (floor(vec2(right, top) / texelSize) + 0.5) * texelSize);
vec2 border = clamp(round(gl_TexCoord[0] / texelSize) * texelSize, vec2(left, bottom), vec2(right, top));
float totalArea = 4.0 * range.x * range.y;
vec4 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;
gl_FragColor = averageColor;
}