Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #693 from Sonicadvance1/PP-shaders-improvement
Improved system for post processing shaders.
  • Loading branch information
Sonicadvance1 committed Aug 13, 2014
2 parents e4e4490 + 287758f commit f2a1dd9
Show file tree
Hide file tree
Showing 65 changed files with 1,387 additions and 585 deletions.
13 changes: 3 additions & 10 deletions Data/Sys/Shaders/16bit.glsl
@@ -1,10 +1,3 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;

void main()
{
//Change this number to increase the pixel size.
Expand All @@ -14,9 +7,9 @@ void main()
float green = 0.0;
float blue = 0.0;

vec2 pos = floor(uv0 * resolution.xy / pixelSize) * pixelSize * resolution.zw;
float2 pos = floor(GetCoordinates() * GetResolution() / pixelSize) * pixelSize * GetInvResolution();

vec4 c0 = texture(samp9, pos);
float4 c0 = SampleLocation(pos);

if (c0.r < 0.1)
red = 0.1;
Expand Down Expand Up @@ -57,5 +50,5 @@ void main()
else
green = 1.0;

ocol0 = vec4(red, green, blue, c0.a);
SetOutput(float4(red, green, blue, c0.a));
}
13 changes: 3 additions & 10 deletions Data/Sys/Shaders/32bit.glsl
@@ -1,10 +1,3 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;

void main()
{
//Change this number to increase the pixel size.
Expand All @@ -14,9 +7,9 @@ void main()
float green = 0.0;
float blue = 0.0;

vec2 pos = floor(uv0 * resolution.xy / pixelSize) * pixelSize * resolution.zw;
float2 pos = floor(GetCoordinates() * GetResolution() / pixelSize) * pixelSize * GetInvResolution();

vec4 c0 = texture(samp9, pos);
float4 c0 = SampleLocation(pos);

if (c0.r < 0.06)
red = 0.06;
Expand Down Expand Up @@ -82,5 +75,5 @@ void main()
else
green = 1.0;

ocol0 = vec4(red, green, blue, c0.a);
SetOutput(float4(red, green, blue, c0.a));
}
54 changes: 24 additions & 30 deletions Data/Sys/Shaders/FXAA.glsl
Expand Up @@ -12,62 +12,56 @@

// 0. You just DO WHAT THE FUCK YOU WANT TO.

SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;
#define FXAA_REDUCE_MIN (1.0/ 128.0)
#define FXAA_REDUCE_MUL (1.0 / 8.0)
#define FXAA_SPAN_MAX 8.0
vec4 applyFXAA(vec2 fragCoord, sampler2D tex)

float4 applyFXAA(float2 fragCoord)
{
vec4 color;
vec2 inverseVP = resolution.zw;
vec3 rgbNW = texture(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;
vec3 rgbNE = texture(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;
vec3 rgbSW = texture(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;
vec3 rgbSE = texture(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;
vec3 rgbM = texture(tex, fragCoord * inverseVP).xyz;
vec3 luma = vec3(0.299, 0.587, 0.114);
float4 color;
float2 inverseVP = GetInvResolution();
float3 rgbNW = SampleLocation((fragCoord + float2(-1.0, -1.0)) * inverseVP).xyz;
float3 rgbNE = SampleLocation((fragCoord + float2(1.0, -1.0)) * inverseVP).xyz;
float3 rgbSW = SampleLocation((fragCoord + float2(-1.0, 1.0)) * inverseVP).xyz;
float3 rgbSE = SampleLocation((fragCoord + float2(1.0, 1.0)) * inverseVP).xyz;
float3 rgbM = SampleLocation(fragCoord * inverseVP).xyz;
float3 luma = float3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
vec2 dir;

float2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));

float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);

float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir = min(float2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) * inverseVP;

vec3 rgbA = 0.5 * (
texture(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
texture(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
texture(tex, fragCoord * inverseVP + dir * -0.5).xyz +
texture(tex, fragCoord * inverseVP + dir * 0.5).xyz);
float3 rgbA = 0.5 * (
SampleLocation(fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
SampleLocation(fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
float3 rgbB = rgbA * 0.5 + 0.25 * (
SampleLocation(fragCoord * inverseVP + dir * -0.5).xyz +
SampleLocation(fragCoord * inverseVP + dir * 0.5).xyz);

float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax))
color = vec4(rgbA, 1.0);
color = float4(rgbA, 1.0);
else
color = vec4(rgbB, 1.0);
color = float4(rgbB, 1.0);
return color;
}

void main()
{
ocol0 = applyFXAA(uv0 * resolution.xy, samp9);
SetOutput(applyFXAA(GetCoordinates() * GetResolution()));
}
18 changes: 0 additions & 18 deletions Data/Sys/Shaders/README.txt

This file was deleted.

9 changes: 2 additions & 7 deletions Data/Sys/Shaders/acidmetal.glsl
@@ -1,11 +1,6 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

void main()
{
vec4 c0 = texture(samp9, uv0);
float4 c0 = Sample();
float red = 0.0;
float blue = 0.0;

Expand All @@ -17,5 +12,5 @@ void main()

float green = max(c0.r + c0.b, c0.g);

ocol0 = vec4(red, green, blue, 1.0);
SetOutput(float4(red, green, blue, 1.0));
}
9 changes: 1 addition & 8 deletions Data/Sys/Shaders/acidtrip.glsl
@@ -1,11 +1,4 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;

void main()
{
ocol0 = (texture(samp9, uv0+resolution.zw) - texture(samp9, uv0-resolution.zw)) * 8.0;
SetOutput((SampleOffset(int2(1, 1)) - SampleOffset(int2(-1, -1))) * 8.0);
}
13 changes: 3 additions & 10 deletions Data/Sys/Shaders/acidtrip2.glsl
@@ -1,13 +1,6 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;

void main()
{
vec4 a = texture(samp9, uv0+resolution.zw);
vec4 b = texture(samp9, uv0-resolution.zw);
ocol0 = ( a*a*1.3 - b ) * 8.0;
float4 a = SampleOffset(int2( 1, 1));
float4 b = SampleOffset(int2(-1, -1));
SetOutput(( a*a*1.3 - b ) * 8.0);
}
55 changes: 23 additions & 32 deletions Data/Sys/Shaders/asciiart.glsl
@@ -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;
Expand All @@ -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:
Expand All @@ -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)
{
Expand All @@ -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));
}
21 changes: 7 additions & 14 deletions Data/Sys/Shaders/auto_toon.glsl
@@ -1,22 +1,15 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;

void main()
{
vec4 to_gray = vec4(0.3,0.59,0.11,0);
float4 to_gray = float4(0.3,0.59,0.11,0);

float x1 = dot(to_gray, texture(samp9, uv0+vec2(1,1)*resolution.zw));
float x0 = dot(to_gray, texture(samp9, uv0+vec2(-1,-1)*resolution.zw));
float x3 = dot(to_gray, texture(samp9, uv0+vec2(1,-1)*resolution.zw));
float x2 = dot(to_gray, texture(samp9, uv0+vec2(-1,1)*resolution.zw));
float x1 = dot(to_gray, SampleOffset(int2( 1, 1)));
float x0 = dot(to_gray, SampleOffset(int2(-1,-1)));
float x3 = dot(to_gray, SampleOffset(int2( 1,-1)));
float x2 = dot(to_gray, SampleOffset(int2(-1, 1)));

float edge = (x1 - x0) * (x1 - x0) + (x3 - x2) * (x3 - x2);

float4 color = texture(samp9, uv0).rgba;
float4 color = Sample();

ocol0 = color - vec4(edge, edge, edge, edge) * 12.0;
SetOutput(color - float4(edge, edge, edge, edge) * 12.0);
}
22 changes: 7 additions & 15 deletions Data/Sys/Shaders/auto_toon2.glsl
@@ -1,23 +1,15 @@
SAMPLER_BINDING(9) uniform sampler2D samp9;

out vec4 ocol0;
in vec2 uv0;

uniform vec4 resolution;

void main()
{

//Changethis to increase the number of colors.
int numColors =8;

float4 to_gray = float4(0.3,0.59,0.11,0);
float x1 = dot(to_gray, texture(samp9, uv0+vec2(1,1)*resolution.zw));
float x0 = dot(to_gray, texture(samp9, uv0+vec2(-1,-1)*resolution.zw));
float x3 = dot(to_gray, texture(samp9, uv0+vec2(1,-1)*resolution.zw));
float x2 = dot(to_gray, texture(samp9, uv0+vec2(-1,1)*resolution.zw));
float x1 = dot(to_gray, SampleOffset(int2( 1, 1)));
float x0 = dot(to_gray, SampleOffset(int2(-1,-1)));
float x3 = dot(to_gray, SampleOffset(int2( 1,-1)));
float x2 = dot(to_gray, SampleOffset(int2(-1, 1)));
float edge = (x1 - x0) * (x1 - x0) + (x3 - x2) * (x3 - x2);
float4 color = texture(samp9, uv0).rgba;
float4 color = Sample();

float4 c0 = color - float4(edge, edge, edge, edge) * 12.0;

Expand Down Expand Up @@ -66,7 +58,7 @@ void main()
blue = 0.95;
else
blue = colorN ;

bb = true;
}

Expand All @@ -92,5 +84,5 @@ void main()
break;
}

ocol0 = float4(red, green, blue, c0.a);
SetOutput(float4(red, green, blue, c0.a));
}

0 comments on commit f2a1dd9

Please sign in to comment.