mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Change all the post processing shaders to the new system.
Removes the README.txt file in favour of a new wiki page I'm going to generate.
This commit is contained in:
@ -1,48 +1,39 @@
|
||||
// textures
|
||||
SAMPLER_BINDING(8) uniform sampler2D samp8;
|
||||
SAMPLER_BINDING(9) uniform sampler2D samp9;
|
||||
|
||||
const int char_width = 8;
|
||||
const int char_height = 13;
|
||||
const int char_count = 95;
|
||||
const int char_pixels = char_width*char_height;
|
||||
const vec2 char_dim = vec2(char_width, char_height);
|
||||
const vec2 font_scale = vec2(1.0/float(char_width)/float(char_count), 1.0/float(char_height));
|
||||
|
||||
out vec4 ocol0;
|
||||
in vec2 uv0;
|
||||
|
||||
uniform vec4 resolution;
|
||||
const float2 char_dim = float2(char_width, char_height);
|
||||
const float2 font_scale = float2(1.0/float(char_width)/float(char_count), 1.0/float(char_height));
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 char_pos = floor(uv0*resolution.xy/char_dim);
|
||||
vec2 pixel_offset = floor(uv0*resolution.xy) - char_pos*char_dim;
|
||||
float2 char_pos = floor(GetCoordinates()*GetResolution()/char_dim);
|
||||
float2 pixel_offset = floor(GetCoordinates()*GetResolution()) - char_pos*char_dim;
|
||||
|
||||
// just a big number
|
||||
float mindiff = float(char_width*char_height) * 100.0;
|
||||
|
||||
float minc = 0.0;
|
||||
vec4 mina = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 minb = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 mina = float4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 minb = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
for (int i=0; i<char_count; i++)
|
||||
{
|
||||
vec4 ff = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 f = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 ft = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 t = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
vec4 tt = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 ff = float4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 f = float4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 ft = float4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 t = float4(0.0, 0.0, 0.0, 0.0);
|
||||
float4 tt = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
for (int x=0; x<char_width; x++)
|
||||
{
|
||||
for (int y=0; y<char_height; y++)
|
||||
{
|
||||
vec2 tex_pos = char_pos*char_dim + vec2(x,y) + 0.5;
|
||||
vec4 tex = texture(samp9, tex_pos * resolution.zw);
|
||||
float2 tex_pos = char_pos*char_dim + float2(x,y) + 0.5;
|
||||
float4 tex = SampleLocation(tex_pos * GetInvResolution());
|
||||
|
||||
vec2 font_pos = vec2(x+i*char_width, y) + 0.5;
|
||||
vec4 font = texture(samp8, font_pos * font_scale);
|
||||
float2 font_pos = float2(x+i*char_width, y) + 0.5;
|
||||
float4 font = SampleFontLocation(font_pos * font_scale);
|
||||
|
||||
// generates sum of texture and font and their squares
|
||||
ff += font*font;
|
||||
@ -63,7 +54,7 @@ void main()
|
||||
|
||||
// In the next steps, "a" is the font color, "b" is the background color, "f" is the font value at this pixel, "t" is the texture value
|
||||
|
||||
// So the square error of one pixel is:
|
||||
// So the square error of one pixel is:
|
||||
// e = ( t - a⋅f - b⋅(1-f) ) ^ 2
|
||||
|
||||
// In longer:
|
||||
@ -78,11 +69,11 @@ void main()
|
||||
|
||||
// So, both equations must be zero at minimum and there is only one solution.
|
||||
|
||||
vec4 a = (f*ft - ff*t + f*t - ft*float(char_pixels)) / (f*f - ff*float(char_pixels));
|
||||
vec4 b = (f*ft - ff*t) / (f*f - ff*float(char_pixels));
|
||||
float4 a = (f*ft - ff*t + f*t - ft*float(char_pixels)) / (f*f - ff*float(char_pixels));
|
||||
float4 b = (f*ft - ff*t) / (f*f - ff*float(char_pixels));
|
||||
|
||||
vec4 diff = a*a*ff + 2.0*a*b*f - 2.0*a*b*ff - 2.0*a*ft + b*b *(-2.0*f + ff + float(char_pixels)) + 2.0*b*ft - 2.0*b*t + tt;
|
||||
float diff_f = dot(diff, vec4(1.0, 1.0, 1.0, 1.0));
|
||||
float4 diff = a*a*ff + 2.0*a*b*f - 2.0*a*b*ff - 2.0*a*ft + b*b *(-2.0*f + ff + float(char_pixels)) + 2.0*b*ft - 2.0*b*t + tt;
|
||||
float diff_f = dot(diff, float4(1.0, 1.0, 1.0, 1.0));
|
||||
|
||||
if (diff_f < mindiff)
|
||||
{
|
||||
@ -93,8 +84,8 @@ void main()
|
||||
}
|
||||
}
|
||||
|
||||
vec2 font_pos_res = vec2(minc * float(char_width), 0.0) + pixel_offset + 0.5;
|
||||
float2 font_pos_res = float2(minc * float(char_width), 0.0) + pixel_offset + 0.5;
|
||||
|
||||
vec4 col = texture(samp8, font_pos_res * font_scale);
|
||||
ocol0 = mina * col + minb * (vec4(1.0,1.0,1.0,1.0) - col);
|
||||
float4 col = SampleFontLocation(font_pos_res * font_scale);
|
||||
SetOutput(mina * col + minb * (float4(1.0,1.0,1.0,1.0) - col));
|
||||
}
|
||||
|
Reference in New Issue
Block a user