Browse Source

Added some useful postprocessing shaders

Shaders come in two flavours:
- shaders/gl330: OpenGL 3.3+ (Windows, Linux, OSX)
- shaders/gles100:  OpenGL ES 2.0 (Android, RPI, HTML5)
pull/28/head
raysan5 9 years ago
parent
commit
b1a90a7f91
28 changed files with 929 additions and 0 deletions
  1. +19
    -0
      shaders/gl330/base.vs
  2. +42
    -0
      shaders/gl330/bloom.fs
  3. +29
    -0
      shaders/gl330/blur.fs
  4. +44
    -0
      shaders/gl330/cross_hatching.fs
  5. +54
    -0
      shaders/gl330/cross_stitching.fs
  6. +34
    -0
      shaders/gl330/dream_vision.fs
  7. +40
    -0
      shaders/gl330/fisheye.fs
  8. +20
    -0
      shaders/gl330/grayscale.fs
  9. +28
    -0
      shaders/gl330/pixel.fs
  10. +26
    -0
      shaders/gl330/posterization.fs
  11. +27
    -0
      shaders/gl330/predator.fs
  12. +41
    -0
      shaders/gl330/scanlines.fs
  13. +41
    -0
      shaders/gl330/swirl.fs
  14. +19
    -0
      shaders/gl330/template.fs
  15. +21
    -0
      shaders/gles100/base.vs
  16. +42
    -0
      shaders/gles100/bloom.fs
  17. +28
    -0
      shaders/gles100/blur.fs
  18. +44
    -0
      shaders/gles100/cross_hatching.fs
  19. +54
    -0
      shaders/gles100/cross_stitching.fs
  20. +34
    -0
      shaders/gles100/dream_vision.fs
  21. +40
    -0
      shaders/gles100/fisheye.fs
  22. +20
    -0
      shaders/gles100/grayscale.fs
  23. +28
    -0
      shaders/gles100/pixel.fs
  24. +26
    -0
      shaders/gles100/posterization.fs
  25. +27
    -0
      shaders/gles100/predator.fs
  26. +41
    -0
      shaders/gles100/scanlines.fs
  27. +41
    -0
      shaders/gles100/swirl.fs
  28. +19
    -0
      shaders/gles100/template.fs

+ 19
- 0
shaders/gl330/base.vs View File

@ -0,0 +1,19 @@
#version 330
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
out vec2 fragTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
// NOTE: Add here your custom variables
void main()
{
fragTexCoord = vertexTexCoord;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
}

+ 42
- 0
shaders/gl330/bloom.fs View File

@ -0,0 +1,42 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 sum = vec4(0);
vec4 tc = vec4(0);
for (int i = -4; i < 4; i++)
{
for (int j = -3; j < 3; j++)
{
sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
}
}
if (texture2D(texture0, fragTexCoord).r < 0.3)
{
tc = sum*sum*0.012 + texture2D(texture0, fragTexCoord);
}
else
{
if (texture2D(texture0, fragTexCoord).r < 0.5)
{
tc = sum*sum*0.009 + texture2D(texture0, fragTexCoord);
}
else
{
tc = sum*sum*0.0075 + texture2D(texture0, fragTexCoord);
}
}
fragColor = tc;
}

+ 29
- 0
shaders/gl330/blur.fs View File

@ -0,0 +1,29 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
void main()
{
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight[0];
for (int i = 1; i < 3; i++)
{
tc += texture2D(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
tc += texture2D(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
}
fragColor = vec4(tc, 1.0);
}

+ 44
- 0
shaders/gl330/cross_hatching.fs View File

@ -0,0 +1,44 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
float hatchOffsetY = 5.0f;
float lumThreshold01 = 0.9f;
float lumThreshold02 = 0.7f;
float lumThreshold03 = 0.5f;
float lumThreshold04 = 0.3f;
void main()
{
vec3 tc = vec3(1.0, 1.0, 1.0);
float lum = length(texture2D(texture0, fragTexCoord).rgb);
if (lum < lumThreshold01)
{
if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold02)
{
if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold03)
{
if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold04)
{
if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
fragColor = vec4(tc, 1.0);
}

+ 54
- 0
shaders/gl330/cross_stitching.fs View File

@ -0,0 +1,54 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
float stitchingSize = 6.0f;
uniform int invert = 0;
vec4 PostFX(sampler2D tex, vec2 uv)
{
vec4 c = vec4(0.0);
float size = stitchingSize;
vec2 cPos = uv * vec2(renderWidth, renderHeight);
vec2 tlPos = floor(cPos / vec2(size, size));
tlPos *= size;
int remX = int(mod(cPos.x, size));
int remY = int(mod(cPos.y, size));
if (remX == 0 && remY == 0) tlPos = cPos;
vec2 blPos = tlPos;
blPos.y += (size - 1.0);
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
{
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
}
else
{
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
else c = vec4(0.0, 0.0, 0.0, 1.0);
}
return c;
}
void main(void)
{
vec3 tc = PostFX(texture0, fragTexCoord).rgb;
fragColor = vec4(tc, 1.0);
}

+ 34
- 0
shaders/gl330/dream_vision.fs View File

@ -0,0 +1,34 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 color = texture2D(texture0, fragTexCoord);
color += texture2D(texture0, fragTexCoord + 0.001);
color += texture2D(texture0, fragTexCoord + 0.003);
color += texture2D(texture0, fragTexCoord + 0.005);
color += texture2D(texture0, fragTexCoord + 0.007);
color += texture2D(texture0, fragTexCoord + 0.009);
color += texture2D(texture0, fragTexCoord + 0.011);
color += texture2D(texture0, fragTexCoord - 0.001);
color += texture2D(texture0, fragTexCoord - 0.003);
color += texture2D(texture0, fragTexCoord - 0.005);
color += texture2D(texture0, fragTexCoord - 0.007);
color += texture2D(texture0, fragTexCoord - 0.009);
color += texture2D(texture0, fragTexCoord - 0.011);
color.rgb = vec3((color.r + color.g + color.b)/3.0);
color = color/9.5;
fragColor = color;
}

+ 40
- 0
shaders/gl330/fisheye.fs View File

@ -0,0 +1,40 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float PI = 3.1415926535;
void main()
{
float aperture = 178.0f;
float apertureHalf = 0.5 * aperture * (PI / 180.0);
float maxFactor = sin(apertureHalf);
vec2 uv = vec2(0);
vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
float d = length(xy);
if (d < (2.0 - maxFactor))
{
d = length(xy * maxFactor);
float z = sqrt(1.0 - d * d);
float r = atan(d, z) / PI;
float phi = atan(xy.y, xy.x);
uv.x = r * cos(phi) + 0.5;
uv.y = r * sin(phi) + 0.5;
}
else
{
uv = fragTexCoord.xy;
}
fragColor = texture2D(texture0, uv);
}

+ 20
- 0
shaders/gl330/grayscale.fs View File

@ -0,0 +1,20 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
fragColor = vec4(gray, gray, gray, tintColor.a);
}

+ 28
- 0
shaders/gl330/pixel.fs View File

@ -0,0 +1,28 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
uniform float pixelWidth = 5.0f;
uniform float pixelHeight = 5.0f;
void main()
{
float dx = pixelWidth*(1.0/renderWidth);
float dy = pixelHeight*(1.0/renderHeight);
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
vec3 tc = texture2D(texture0, coord).rgb;
fragColor = vec4(tc, 1.0);
}

+ 26
- 0
shaders/gl330/posterization.fs View File

@ -0,0 +1,26 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
float gamma = 0.6f;
float numColors = 8.0f;
void main()
{
vec3 color = texture2D(texture0, fragTexCoord.xy).rgb;
color = pow(color, vec3(gamma, gamma, gamma));
color = color*numColors;
color = floor(color);
color = color/numColors;
color = pow(color, vec3(1.0/gamma));
fragColor = vec4(color, 1.0);
}

+ 27
- 0
shaders/gl330/predator.fs View File

@ -0,0 +1,27 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec3 color = texture2D(texture0, fragTexCoord).rgb;
vec3 colors[3];
colors[0] = vec3(0.0, 0.0, 1.0);
colors[1] = vec3(1.0, 1.0, 0.0);
colors[2] = vec3(1.0, 0.0, 0.0);
float lum = (color.r + color.g + color.b)/3.0;
int ix = (lum < 0.5)? 0:1;
vec3 tc = mix(colors[ix], colors[ix + 1], (lum - float(ix)*0.5)/0.5);
fragColor = vec4(tc, 1.0);
}

+ 41
- 0
shaders/gl330/scanlines.fs View File

@ -0,0 +1,41 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
float offset = 0;
float frequency = 720/3.0;
uniform float time;
void main (void)
{
/*
// Scanlines method 1
float tval = 0; //time
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
vec4 color = texture2D(texture0, fragTexCoord);
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
color *= vec4(0.8, 1.0, 0.7, 1);
color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0);
color *= 0.97 + 0.03*sin(110.0*tval);
fragColor = color;
*/
// Scanlines method 2
float globalPos = (fragTexCoord.y + offset) * frequency;
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
vec4 color = texture2D(texture0, fragTexCoord);
fragColor = mix(vec4(0, 0.3, 0, 0), color, wavePos);
}

+ 41
- 0
shaders/gl330/swirl.fs View File

@ -0,0 +1,41 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200, 200);
void main (void)
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
tc -= center;
float dist = length(tc);
if (dist < radius)
{
float percent = (radius - dist)/radius;
float theta = percent*percent*angle*8.0;
float s = sin(theta);
float c = cos(theta);
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
}
tc += center;
vec3 color = texture2D(texture0, tc/texSize).rgb;
fragColor = vec4(color, 1.0);;
}

+ 19
- 0
shaders/gl330/template.fs View File

@ -0,0 +1,19 @@
#version 330
in vec2 fragTexCoord;
out vec4 fragColor;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 texelColor = texture2D(texture0, fragTexCoord);
// NOTE: Implement here your fragment shader code
fragColor = texelColor*tintColor;
}

+ 21
- 0
shaders/gles100/base.vs View File

@ -0,0 +1,21 @@
#version 100
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
varying vec2 fragTexCoord;
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
// NOTE: Add here your custom variables
void main()
{
vec3 normal = vertexNormal;
fragTexCoord = vertexTexCoord;
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
}

+ 42
- 0
shaders/gles100/bloom.fs View File

@ -0,0 +1,42 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 sum = vec4(0);
vec4 tc = vec4(0);
for (int i = -4; i < 4; i++)
{
for (int j = -3; j < 3; j++)
{
sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
}
}
if (texture2D(texture0, fragTexCoord).r < 0.3)
{
tc = sum*sum*0.012 + texture2D(texture0, fragTexCoord);
}
else
{
if (texture2D(texture0, fragTexCoord).r < 0.5)
{
tc = sum*sum*0.009 + texture2D(texture0, fragTexCoord);
}
else
{
tc = sum*sum*0.0075 + texture2D(texture0, fragTexCoord);
}
}
gl_FragColor = tc;
}

+ 28
- 0
shaders/gles100/blur.fs View File

@ -0,0 +1,28 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
float offset[3] = float[]( 0.0, 1.3846153846, 3.2307692308 );
float weight[3] = float[]( 0.2270270270, 0.3162162162, 0.0702702703 );
void main()
{
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight[0];
for (int i = 1; i < 3; i++)
{
tc += texture2D(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
tc += texture2D(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
}
gl_FragColor = vec4(tc, 1.0);
}

+ 44
- 0
shaders/gles100/cross_hatching.fs View File

@ -0,0 +1,44 @@
# version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
float hatchOffsetY = 5.0f;
float lumThreshold01 = 0.9f;
float lumThreshold02 = 0.7f;
float lumThreshold03 = 0.5f;
float lumThreshold04 = 0.3f;
void main()
{
vec3 tc = vec3(1.0, 1.0, 1.0);
float lum = length(texture2D(texture0, fragTexCoord).rgb);
if (lum < lumThreshold01)
{
if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold02)
{
if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold03)
{
if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold04)
{
if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
gl_FragColor = vec4(tc, 1.0);
}

+ 54
- 0
shaders/gles100/cross_stitching.fs View File

@ -0,0 +1,54 @@
# version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
float stitchingSize = 6.0f;
uniform int invert = 0;
vec4 PostFX(sampler2D tex, vec2 uv)
{
vec4 c = vec4(0.0);
float size = stitchingSize;
vec2 cPos = uv * vec2(renderWidth, renderHeight);
vec2 tlPos = floor(cPos / vec2(size, size));
tlPos *= size;
int remX = int(mod(cPos.x, size));
int remY = int(mod(cPos.y, size));
if (remX == 0 && remY == 0) tlPos = cPos;
vec2 blPos = tlPos;
blPos.y += (size - 1.0);
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
{
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
}
else
{
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
else c = vec4(0.0, 0.0, 0.0, 1.0);
}
return c;
}
void main(void)
{
vec3 tc = PostFX(texture0, fragTexCoord).rgb;
gl_FragColor = vec4(tc, 1.0);
}

+ 34
- 0
shaders/gles100/dream_vision.fs View File

@ -0,0 +1,34 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 color = texture2D(texture0, fragTexCoord);
color += texture2D(texture0, fragTexCoord + 0.001);
color += texture2D(texture0, fragTexCoord + 0.003);
color += texture2D(texture0, fragTexCoord + 0.005);
color += texture2D(texture0, fragTexCoord + 0.007);
color += texture2D(texture0, fragTexCoord + 0.009);
color += texture2D(texture0, fragTexCoord + 0.011);
color += texture2D(texture0, fragTexCoord - 0.001);
color += texture2D(texture0, fragTexCoord - 0.003);
color += texture2D(texture0, fragTexCoord - 0.005);
color += texture2D(texture0, fragTexCoord - 0.007);
color += texture2D(texture0, fragTexCoord - 0.009);
color += texture2D(texture0, fragTexCoord - 0.011);
color.rgb = vec3((color.r + color.g + color.b)/3.0);
color = color/9.5;
gl_FragColor = color;
}

+ 40
- 0
shaders/gles100/fisheye.fs View File

@ -0,0 +1,40 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float PI = 3.1415926535;
void main()
{
float aperture = 178.0f;
float apertureHalf = 0.5 * aperture * (PI / 180.0);
float maxFactor = sin(apertureHalf);
vec2 uv = vec2(0);
vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
float d = length(xy);
if (d < (2.0 - maxFactor))
{
d = length(xy * maxFactor);
float z = sqrt(1.0 - d * d);
float r = atan(d, z) / PI;
float phi = atan(xy.y, xy.x);
uv.x = r * cos(phi) + 0.5;
uv.y = r * sin(phi) + 0.5;
}
else
{
uv = fragTexCoord.xy;
}
gl_FragColor = texture2D(texture0, uv);
}

+ 20
- 0
shaders/gles100/grayscale.fs View File

@ -0,0 +1,20 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
gl_FragColor = vec4(gray, gray, gray, tintColor.a);
}

+ 28
- 0
shaders/gles100/pixel.fs View File

@ -0,0 +1,28 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
uniform float pixelWidth = 5.0f;
uniform float pixelHeight = 5.0f;
void main()
{
float dx = pixelWidth*(1.0/renderWidth);
float dy = pixelHeight*(1.0/renderHeight);
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
vec3 tc = texture2D(texture0, coord).rgb;
gl_FragColor = vec4(tc, 1.0);
}

+ 26
- 0
shaders/gles100/posterization.fs View File

@ -0,0 +1,26 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
float gamma = 0.6;
float numColors = 8.0;
void main()
{
vec3 color = texture2D(texture0, fragTexCoord.xy).rgb;
color = pow(color, vec3(gamma, gamma, gamma));
color = color*numColors;
color = floor(color);
color = color/numColors;
color = pow(color, vec3(1.0/gamma));
gl_FragColor = vec4(color, 1.0);
}

+ 27
- 0
shaders/gles100/predator.fs View File

@ -0,0 +1,27 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec3 color = texture2D(texture0, fragTexCoord).rgb;
vec3 colors[3];
colors[0] = vec3(0.0, 0.0, 1.0);
colors[1] = vec3(1.0, 1.0, 0.0);
colors[2] = vec3(1.0, 0.0, 0.0);
float lum = (color.r + color.g + color.b)/3.0;
int ix = (lum < 0.5)? 0:1;
vec3 tc = mix(colors[ix], colors[ix+1], (lum-float(ix)*0.5)/0.5);
gl_FragColor = vec4(tc, 1.0);
}

+ 41
- 0
shaders/gles100/scanlines.fs View File

@ -0,0 +1,41 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
float offset = 0;
float frequency = 720/3.0;
uniform float time;
void main (void)
{
/*
// Scanlines method 1
float tval = 0; //time
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
vec4 color = texture2D(texture0, fragTexCoord);
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
color *= vec4(0.8, 1.0, 0.7, 1);
color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0);
color *= 0.97 + 0.03*sin(110.0*tval);
fragColor = color;
*/
// Scanlines method 2
float globalPos = (fragTexCoord.y + offset) * frequency;
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
vec4 color = texture2D(texture0, fragTexCoord);
gl_FragColor = mix(vec4(0, 0.3, 0, 0), color, wavePos);
}

+ 41
- 0
shaders/gles100/swirl.fs View File

@ -0,0 +1,41 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200, 200);
void main (void)
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
tc -= center;
float dist = length(tc);
if (dist < radius)
{
float percent = (radius - dist)/radius;
float theta = percent*percent*angle*8.0;
float s = sin(theta);
float c = cos(theta);
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
}
tc += center;
vec3 color = texture2D(texture0, tc/texSize).rgb;
gl_FragColor = vec4(color, 1.0);;
}

+ 19
- 0
shaders/gles100/template.fs View File

@ -0,0 +1,19 @@
#version 100
precision mediump float;
varying vec2 fragTexCoord;
uniform sampler2D texture0;
uniform vec4 tintColor;
// NOTE: Add here your custom variables
void main()
{
vec4 texelColor = texture2D(texture0, fragTexCoord);
// NOTE: Implement here your fragment shader code
gl_FragColor = texelColor*tintColor;
}

Loading…
Cancel
Save