From 78b502b0bf1ee796d86837c611150ed5f8d58fd2 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 7 Apr 2016 11:48:09 +0200 Subject: Folders rename for consistency on shaders version --- shaders/gl330/base.vs | 18 --------- shaders/gl330/bloom.fs | 42 --------------------- shaders/gl330/blur.fs | 29 --------------- shaders/gl330/cross_hatching.fs | 44 ---------------------- shaders/gl330/cross_stitching.fs | 54 --------------------------- shaders/gl330/dream_vision.fs | 34 ----------------- shaders/gl330/fisheye.fs | 40 -------------------- shaders/gl330/grayscale.fs | 20 ---------- shaders/gl330/phong.fs | 76 -------------------------------------- shaders/gl330/phong.vs | 27 -------------- shaders/gl330/pixel.fs | 28 -------------- shaders/gl330/posterization.fs | 26 ------------- shaders/gl330/predator.fs | 27 -------------- shaders/gl330/scanlines.fs | 41 -------------------- shaders/gl330/swirl.fs | 41 -------------------- shaders/gl330/template.fs | 19 ---------- shaders/gles100/base.vs | 20 ---------- shaders/gles100/bloom.fs | 42 --------------------- shaders/gles100/blur.fs | 28 -------------- shaders/gles100/cross_hatching.fs | 44 ---------------------- shaders/gles100/cross_stitching.fs | 54 --------------------------- shaders/gles100/dream_vision.fs | 34 ----------------- shaders/gles100/fisheye.fs | 40 -------------------- shaders/gles100/grayscale.fs | 20 ---------- shaders/gles100/pixel.fs | 28 -------------- shaders/gles100/posterization.fs | 26 ------------- shaders/gles100/predator.fs | 27 -------------- shaders/gles100/scanlines.fs | 41 -------------------- shaders/gles100/swirl.fs | 41 -------------------- shaders/gles100/template.fs | 19 ---------- shaders/glsl100/base.vs | 20 ++++++++++ shaders/glsl100/bloom.fs | 42 +++++++++++++++++++++ shaders/glsl100/blur.fs | 28 ++++++++++++++ shaders/glsl100/cross_hatching.fs | 44 ++++++++++++++++++++++ shaders/glsl100/cross_stitching.fs | 54 +++++++++++++++++++++++++++ shaders/glsl100/dream_vision.fs | 34 +++++++++++++++++ shaders/glsl100/fisheye.fs | 40 ++++++++++++++++++++ shaders/glsl100/grayscale.fs | 20 ++++++++++ shaders/glsl100/pixel.fs | 28 ++++++++++++++ shaders/glsl100/posterization.fs | 26 +++++++++++++ shaders/glsl100/predator.fs | 27 ++++++++++++++ shaders/glsl100/scanlines.fs | 41 ++++++++++++++++++++ shaders/glsl100/swirl.fs | 41 ++++++++++++++++++++ shaders/glsl100/template.fs | 19 ++++++++++ shaders/glsl330/base.vs | 18 +++++++++ shaders/glsl330/bloom.fs | 42 +++++++++++++++++++++ shaders/glsl330/blur.fs | 29 +++++++++++++++ shaders/glsl330/cross_hatching.fs | 44 ++++++++++++++++++++++ shaders/glsl330/cross_stitching.fs | 54 +++++++++++++++++++++++++++ shaders/glsl330/dream_vision.fs | 34 +++++++++++++++++ shaders/glsl330/fisheye.fs | 40 ++++++++++++++++++++ shaders/glsl330/grayscale.fs | 20 ++++++++++ shaders/glsl330/phong.fs | 76 ++++++++++++++++++++++++++++++++++++++ shaders/glsl330/phong.vs | 27 ++++++++++++++ shaders/glsl330/pixel.fs | 28 ++++++++++++++ shaders/glsl330/posterization.fs | 26 +++++++++++++ shaders/glsl330/predator.fs | 27 ++++++++++++++ shaders/glsl330/scanlines.fs | 41 ++++++++++++++++++++ shaders/glsl330/swirl.fs | 41 ++++++++++++++++++++ shaders/glsl330/template.fs | 19 ++++++++++ 60 files changed, 1030 insertions(+), 1030 deletions(-) delete mode 100644 shaders/gl330/base.vs delete mode 100644 shaders/gl330/bloom.fs delete mode 100644 shaders/gl330/blur.fs delete mode 100644 shaders/gl330/cross_hatching.fs delete mode 100644 shaders/gl330/cross_stitching.fs delete mode 100644 shaders/gl330/dream_vision.fs delete mode 100644 shaders/gl330/fisheye.fs delete mode 100644 shaders/gl330/grayscale.fs delete mode 100644 shaders/gl330/phong.fs delete mode 100644 shaders/gl330/phong.vs delete mode 100644 shaders/gl330/pixel.fs delete mode 100644 shaders/gl330/posterization.fs delete mode 100644 shaders/gl330/predator.fs delete mode 100644 shaders/gl330/scanlines.fs delete mode 100644 shaders/gl330/swirl.fs delete mode 100644 shaders/gl330/template.fs delete mode 100644 shaders/gles100/base.vs delete mode 100644 shaders/gles100/bloom.fs delete mode 100644 shaders/gles100/blur.fs delete mode 100644 shaders/gles100/cross_hatching.fs delete mode 100644 shaders/gles100/cross_stitching.fs delete mode 100644 shaders/gles100/dream_vision.fs delete mode 100644 shaders/gles100/fisheye.fs delete mode 100644 shaders/gles100/grayscale.fs delete mode 100644 shaders/gles100/pixel.fs delete mode 100644 shaders/gles100/posterization.fs delete mode 100644 shaders/gles100/predator.fs delete mode 100644 shaders/gles100/scanlines.fs delete mode 100644 shaders/gles100/swirl.fs delete mode 100644 shaders/gles100/template.fs create mode 100644 shaders/glsl100/base.vs create mode 100644 shaders/glsl100/bloom.fs create mode 100644 shaders/glsl100/blur.fs create mode 100644 shaders/glsl100/cross_hatching.fs create mode 100644 shaders/glsl100/cross_stitching.fs create mode 100644 shaders/glsl100/dream_vision.fs create mode 100644 shaders/glsl100/fisheye.fs create mode 100644 shaders/glsl100/grayscale.fs create mode 100644 shaders/glsl100/pixel.fs create mode 100644 shaders/glsl100/posterization.fs create mode 100644 shaders/glsl100/predator.fs create mode 100644 shaders/glsl100/scanlines.fs create mode 100644 shaders/glsl100/swirl.fs create mode 100644 shaders/glsl100/template.fs create mode 100644 shaders/glsl330/base.vs create mode 100644 shaders/glsl330/bloom.fs create mode 100644 shaders/glsl330/blur.fs create mode 100644 shaders/glsl330/cross_hatching.fs create mode 100644 shaders/glsl330/cross_stitching.fs create mode 100644 shaders/glsl330/dream_vision.fs create mode 100644 shaders/glsl330/fisheye.fs create mode 100644 shaders/glsl330/grayscale.fs create mode 100644 shaders/glsl330/phong.fs create mode 100644 shaders/glsl330/phong.vs create mode 100644 shaders/glsl330/pixel.fs create mode 100644 shaders/glsl330/posterization.fs create mode 100644 shaders/glsl330/predator.fs create mode 100644 shaders/glsl330/scanlines.fs create mode 100644 shaders/glsl330/swirl.fs create mode 100644 shaders/glsl330/template.fs (limited to 'shaders') diff --git a/shaders/gl330/base.vs b/shaders/gl330/base.vs deleted file mode 100644 index b0f930b7..00000000 --- a/shaders/gl330/base.vs +++ /dev/null @@ -1,18 +0,0 @@ -#version 330 - -in vec3 vertexPosition; -in vec2 vertexTexCoord; -in vec3 vertexNormal; - -out vec2 fragTexCoord; - -uniform mat4 mvpMatrix; - -// NOTE: Add here your custom variables - -void main() -{ - fragTexCoord = vertexTexCoord; - - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); -} \ No newline at end of file diff --git a/shaders/gl330/bloom.fs b/shaders/gl330/bloom.fs deleted file mode 100644 index 34b6295c..00000000 --- a/shaders/gl330/bloom.fs +++ /dev/null @@ -1,42 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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 += texture(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25; - } - } - - if (texture(texture0, fragTexCoord).r < 0.3) - { - tc = sum*sum*0.012 + texture(texture0, fragTexCoord); - } - else - { - if (texture(texture0, fragTexCoord).r < 0.5) - { - tc = sum*sum*0.009 + texture(texture0, fragTexCoord); - } - else - { - tc = sum*sum*0.0075 + texture(texture0, fragTexCoord); - } - } - - fragColor = tc; -} \ No newline at end of file diff --git a/shaders/gl330/blur.fs b/shaders/gl330/blur.fs deleted file mode 100644 index 44ea42b1..00000000 --- a/shaders/gl330/blur.fs +++ /dev/null @@ -1,29 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -const float renderWidth = 1280.0; -const float renderHeight = 720.0; - -float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); -float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); - -void main() -{ - vec3 tc = texture(texture0, fragTexCoord).rgb*weight[0]; - - for (int i = 1; i < 3; i++) - { - tc += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; - tc += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; - } - - fragColor = vec4(tc, 1.0); -} \ No newline at end of file diff --git a/shaders/gl330/cross_hatching.fs b/shaders/gl330/cross_hatching.fs deleted file mode 100644 index 6f5df964..00000000 --- a/shaders/gl330/cross_hatching.fs +++ /dev/null @@ -1,44 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -float hatchOffsetY = 5.0; -float lumThreshold01 = 0.9; -float lumThreshold02 = 0.7; -float lumThreshold03 = 0.5; -float lumThreshold04 = 0.3; - -void main() -{ - vec3 tc = vec3(1.0, 1.0, 1.0); - float lum = length(texture(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); -} \ No newline at end of file diff --git a/shaders/gl330/cross_stitching.fs b/shaders/gl330/cross_stitching.fs deleted file mode 100644 index dcb26e79..00000000 --- a/shaders/gl330/cross_stitching.fs +++ /dev/null @@ -1,54 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -const float renderWidth = 1280.0; -const float renderHeight = 720.0; - -float stitchingSize = 6.0; - -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 = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; - } - else - { - if (invert == 1) c = texture(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); -} \ No newline at end of file diff --git a/shaders/gl330/dream_vision.fs b/shaders/gl330/dream_vision.fs deleted file mode 100644 index 0ea4ce20..00000000 --- a/shaders/gl330/dream_vision.fs +++ /dev/null @@ -1,34 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -void main() -{ - vec4 color = texture(texture0, fragTexCoord); - - color += texture(texture0, fragTexCoord + 0.001); - color += texture(texture0, fragTexCoord + 0.003); - color += texture(texture0, fragTexCoord + 0.005); - color += texture(texture0, fragTexCoord + 0.007); - color += texture(texture0, fragTexCoord + 0.009); - color += texture(texture0, fragTexCoord + 0.011); - - color += texture(texture0, fragTexCoord - 0.001); - color += texture(texture0, fragTexCoord - 0.003); - color += texture(texture0, fragTexCoord - 0.005); - color += texture(texture0, fragTexCoord - 0.007); - color += texture(texture0, fragTexCoord - 0.009); - color += texture(texture0, fragTexCoord - 0.011); - - color.rgb = vec3((color.r + color.g + color.b)/3.0); - color = color/9.5; - - fragColor = color; -} \ No newline at end of file diff --git a/shaders/gl330/fisheye.fs b/shaders/gl330/fisheye.fs deleted file mode 100644 index 5bd9abf4..00000000 --- a/shaders/gl330/fisheye.fs +++ /dev/null @@ -1,40 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -const float PI = 3.1415926535; - -void main() -{ - float aperture = 178.0; - 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 = texture(texture0, uv); -} \ No newline at end of file diff --git a/shaders/gl330/grayscale.fs b/shaders/gl330/grayscale.fs deleted file mode 100644 index b3a695bf..00000000 --- a/shaders/gl330/grayscale.fs +++ /dev/null @@ -1,20 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -void main() -{ - vec4 base = texture(texture0, fragTexCoord)*fragTintColor; - - // Convert to grayscale using NTSC conversion weights - float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); - - fragColor = vec4(gray, gray, gray, fragTintColor.a); -} \ No newline at end of file diff --git a/shaders/gl330/phong.fs b/shaders/gl330/phong.fs deleted file mode 100644 index 75b7e6d7..00000000 --- a/shaders/gl330/phong.fs +++ /dev/null @@ -1,76 +0,0 @@ -#version 330 - -// Vertex shader input data -in vec2 fragTexCoord; -in vec3 fragNormal; - -// Diffuse data -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// Light attributes -uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); -uniform vec3 light_diffuseColor = vec3(1, 0.5, 0); -uniform vec3 light_specularColor = vec3(0, 1, 0); -uniform float light_intensity = 1; -uniform float light_specIntensity = 1; - -// Material attributes -uniform vec3 mat_ambientColor = vec3(1, 1, 1); -uniform vec3 mat_specularColor = vec3(1, 1, 1); -uniform float mat_glossiness = 50; - -// World attributes -uniform vec3 lightPos; -uniform vec3 cameraPos; - -// Fragment shader output data -out vec4 fragColor; - -vec3 AmbientLighting() -{ - return mat_ambientColor * light_ambientColor; -} - -vec3 DiffuseLighting(in vec3 N, in vec3 L) -{ - // Lambertian reflection calculation - float diffuse = clamp(dot(N, L), 0, 1); - - return tintColor.xyz * light_diffuseColor * light_intensity * diffuse; -} - -vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V) -{ - float specular = 0; - - // Calculate specular reflection only if the surface is oriented to the light source - if(dot(N, L) > 0) - { - // Calculate half vector - vec3 H = normalize(L + V); - - // Calculate specular intensity - specular = pow(dot(N, H), 3 + mat_glossiness); - } - - return mat_specularColor * light_specularColor * light_specIntensity * specular; -} - -void main() -{ - // Normalize input vectors - vec3 L = normalize(lightPos); - vec3 V = normalize(cameraPos); - vec3 N = normalize(fragNormal); - - vec3 ambient = AmbientLighting(); - vec3 diffuse = DiffuseLighting(N, L); - vec3 specular = SpecularLighting(N, L, V); - - // Get base color from texture - vec4 textureColor = texture(texture0, fragTexCoord); - vec3 finalColor = textureColor.rgb; - - fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a); -} \ No newline at end of file diff --git a/shaders/gl330/phong.vs b/shaders/gl330/phong.vs deleted file mode 100644 index ee6d34bf..00000000 --- a/shaders/gl330/phong.vs +++ /dev/null @@ -1,27 +0,0 @@ -#version 330 - -// Vertex input data -in vec3 vertexPosition; -in vec2 vertexTexCoord; -in vec3 vertexNormal; - -// Projection and model data -uniform mat4 mvpMatrix; -uniform mat4 modelMatrix; - -// Attributes to fragment shader -out vec2 fragTexCoord; -out vec3 fragNormal; - -void main() -{ - // Send texture coord to fragment shader - fragTexCoord = vertexTexCoord; - - // Calculate view vector normal from model - mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); - fragNormal = normalize(normalMatrix*vertexNormal); - - // Calculate final vertex position - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); -} \ No newline at end of file diff --git a/shaders/gl330/pixel.fs b/shaders/gl330/pixel.fs deleted file mode 100644 index aa5a22fe..00000000 --- a/shaders/gl330/pixel.fs +++ /dev/null @@ -1,28 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -const float renderWidth = 1280.0; -const float renderHeight = 720.0; - -uniform float pixelWidth = 5.0; -uniform float pixelHeight = 5.0; - -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 = texture(texture0, coord).rgb; - - fragColor = vec4(tc, 1.0); -} \ No newline at end of file diff --git a/shaders/gl330/posterization.fs b/shaders/gl330/posterization.fs deleted file mode 100644 index 5215bd8b..00000000 --- a/shaders/gl330/posterization.fs +++ /dev/null @@ -1,26 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -float gamma = 0.6; -float numColors = 8.0; - -void main() -{ - vec3 color = texture(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); -} \ No newline at end of file diff --git a/shaders/gl330/predator.fs b/shaders/gl330/predator.fs deleted file mode 100644 index 85c93d0c..00000000 --- a/shaders/gl330/predator.fs +++ /dev/null @@ -1,27 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -void main() -{ - vec3 color = texture(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); -} \ No newline at end of file diff --git a/shaders/gl330/scanlines.fs b/shaders/gl330/scanlines.fs deleted file mode 100644 index 0c89e610..00000000 --- a/shaders/gl330/scanlines.fs +++ /dev/null @@ -1,41 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -float offset = 0.0; -float frequency = 720.0/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 = texture(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 = texture(texture0, fragTexCoord); - - fragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); -} \ No newline at end of file diff --git a/shaders/gl330/swirl.fs b/shaders/gl330/swirl.fs deleted file mode 100644 index 19d7468b..00000000 --- a/shaders/gl330/swirl.fs +++ /dev/null @@ -1,41 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -const float renderWidth = 1280.0; -const float renderHeight = 720.0; - -float radius = 250.0; -float angle = 0.8; - -uniform vec2 center = vec2(200.0, 200.0); - -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 = texture(texture0, tc/texSize).rgb; - - fragColor = vec4(color, 1.0);; -} \ No newline at end of file diff --git a/shaders/gl330/template.fs b/shaders/gl330/template.fs deleted file mode 100644 index ad7210a4..00000000 --- a/shaders/gl330/template.fs +++ /dev/null @@ -1,19 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; - -out vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -void main() -{ - vec4 texelColor = texture(texture0, fragTexCoord); - - // NOTE: Implement here your fragment shader code - - fragColor = texelColor*fragTintColor; -} diff --git a/shaders/gles100/base.vs b/shaders/gles100/base.vs deleted file mode 100644 index 9f339382..00000000 --- a/shaders/gles100/base.vs +++ /dev/null @@ -1,20 +0,0 @@ -#version 100 - -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec3 vertexNormal; - -varying vec2 fragTexCoord; - -uniform mat4 mvpMatrix; - -// NOTE: Add here your custom variables - -void main() -{ - vec3 normal = vertexNormal; - - fragTexCoord = vertexTexCoord; - - gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); -} \ No newline at end of file diff --git a/shaders/gles100/bloom.fs b/shaders/gles100/bloom.fs deleted file mode 100644 index 33754c7e..00000000 --- a/shaders/gles100/bloom.fs +++ /dev/null @@ -1,42 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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; -} \ No newline at end of file diff --git a/shaders/gles100/blur.fs b/shaders/gles100/blur.fs deleted file mode 100644 index a1069c6f..00000000 --- a/shaders/gles100/blur.fs +++ /dev/null @@ -1,28 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/cross_hatching.fs b/shaders/gles100/cross_hatching.fs deleted file mode 100644 index cf01b65e..00000000 --- a/shaders/gles100/cross_hatching.fs +++ /dev/null @@ -1,44 +0,0 @@ -# version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/cross_stitching.fs b/shaders/gles100/cross_stitching.fs deleted file mode 100644 index f1afef04..00000000 --- a/shaders/gles100/cross_stitching.fs +++ /dev/null @@ -1,54 +0,0 @@ -# version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/dream_vision.fs b/shaders/gles100/dream_vision.fs deleted file mode 100644 index bb828970..00000000 --- a/shaders/gles100/dream_vision.fs +++ /dev/null @@ -1,34 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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; -} \ No newline at end of file diff --git a/shaders/gles100/fisheye.fs b/shaders/gles100/fisheye.fs deleted file mode 100644 index e7a4485c..00000000 --- a/shaders/gles100/fisheye.fs +++ /dev/null @@ -1,40 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/grayscale.fs b/shaders/gles100/grayscale.fs deleted file mode 100644 index e55545e2..00000000 --- a/shaders/gles100/grayscale.fs +++ /dev/null @@ -1,20 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -void main() -{ - vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; - - // 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, fragTintColor.a); -} \ No newline at end of file diff --git a/shaders/gles100/pixel.fs b/shaders/gles100/pixel.fs deleted file mode 100644 index 552e8900..00000000 --- a/shaders/gles100/pixel.fs +++ /dev/null @@ -1,28 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/posterization.fs b/shaders/gles100/posterization.fs deleted file mode 100644 index 4f4c4b93..00000000 --- a/shaders/gles100/posterization.fs +++ /dev/null @@ -1,26 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/predator.fs b/shaders/gles100/predator.fs deleted file mode 100644 index 2fbdc7af..00000000 --- a/shaders/gles100/predator.fs +++ /dev/null @@ -1,27 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/scanlines.fs b/shaders/gles100/scanlines.fs deleted file mode 100644 index 85de158d..00000000 --- a/shaders/gles100/scanlines.fs +++ /dev/null @@ -1,41 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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); -} \ No newline at end of file diff --git a/shaders/gles100/swirl.fs b/shaders/gles100/swirl.fs deleted file mode 100644 index b0d54b23..00000000 --- a/shaders/gles100/swirl.fs +++ /dev/null @@ -1,41 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// 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);; -} \ No newline at end of file diff --git a/shaders/gles100/template.fs b/shaders/gles100/template.fs deleted file mode 100644 index 1f4b8ccf..00000000 --- a/shaders/gles100/template.fs +++ /dev/null @@ -1,19 +0,0 @@ -#version 100 - -precision mediump float; - -varying vec2 fragTexCoord; - -uniform sampler2D texture0; -uniform vec4 fragTintColor; - -// NOTE: Add here your custom variables - -void main() -{ - vec4 texelColor = texture2D(texture0, fragTexCoord); - - // NOTE: Implement here your fragment shader code - - gl_FragColor = texelColor*fragTintColor; -} \ No newline at end of file diff --git a/shaders/glsl100/base.vs b/shaders/glsl100/base.vs new file mode 100644 index 00000000..9f339382 --- /dev/null +++ b/shaders/glsl100/base.vs @@ -0,0 +1,20 @@ +#version 100 + +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec3 vertexNormal; + +varying vec2 fragTexCoord; + +uniform mat4 mvpMatrix; + +// NOTE: Add here your custom variables + +void main() +{ + vec3 normal = vertexNormal; + + fragTexCoord = vertexTexCoord; + + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/shaders/glsl100/bloom.fs b/shaders/glsl100/bloom.fs new file mode 100644 index 00000000..33754c7e --- /dev/null +++ b/shaders/glsl100/bloom.fs @@ -0,0 +1,42 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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; +} \ No newline at end of file diff --git a/shaders/glsl100/blur.fs b/shaders/glsl100/blur.fs new file mode 100644 index 00000000..a1069c6f --- /dev/null +++ b/shaders/glsl100/blur.fs @@ -0,0 +1,28 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/cross_hatching.fs b/shaders/glsl100/cross_hatching.fs new file mode 100644 index 00000000..cf01b65e --- /dev/null +++ b/shaders/glsl100/cross_hatching.fs @@ -0,0 +1,44 @@ +# version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/cross_stitching.fs b/shaders/glsl100/cross_stitching.fs new file mode 100644 index 00000000..f1afef04 --- /dev/null +++ b/shaders/glsl100/cross_stitching.fs @@ -0,0 +1,54 @@ +# version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/dream_vision.fs b/shaders/glsl100/dream_vision.fs new file mode 100644 index 00000000..bb828970 --- /dev/null +++ b/shaders/glsl100/dream_vision.fs @@ -0,0 +1,34 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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; +} \ No newline at end of file diff --git a/shaders/glsl100/fisheye.fs b/shaders/glsl100/fisheye.fs new file mode 100644 index 00000000..e7a4485c --- /dev/null +++ b/shaders/glsl100/fisheye.fs @@ -0,0 +1,40 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/grayscale.fs b/shaders/glsl100/grayscale.fs new file mode 100644 index 00000000..e55545e2 --- /dev/null +++ b/shaders/glsl100/grayscale.fs @@ -0,0 +1,20 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; + + // 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, fragTintColor.a); +} \ No newline at end of file diff --git a/shaders/glsl100/pixel.fs b/shaders/glsl100/pixel.fs new file mode 100644 index 00000000..552e8900 --- /dev/null +++ b/shaders/glsl100/pixel.fs @@ -0,0 +1,28 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/posterization.fs b/shaders/glsl100/posterization.fs new file mode 100644 index 00000000..4f4c4b93 --- /dev/null +++ b/shaders/glsl100/posterization.fs @@ -0,0 +1,26 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/predator.fs b/shaders/glsl100/predator.fs new file mode 100644 index 00000000..2fbdc7af --- /dev/null +++ b/shaders/glsl100/predator.fs @@ -0,0 +1,27 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/scanlines.fs b/shaders/glsl100/scanlines.fs new file mode 100644 index 00000000..85de158d --- /dev/null +++ b/shaders/glsl100/scanlines.fs @@ -0,0 +1,41 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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); +} \ No newline at end of file diff --git a/shaders/glsl100/swirl.fs b/shaders/glsl100/swirl.fs new file mode 100644 index 00000000..b0d54b23 --- /dev/null +++ b/shaders/glsl100/swirl.fs @@ -0,0 +1,41 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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);; +} \ No newline at end of file diff --git a/shaders/glsl100/template.fs b/shaders/glsl100/template.fs new file mode 100644 index 00000000..1f4b8ccf --- /dev/null +++ b/shaders/glsl100/template.fs @@ -0,0 +1,19 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 texelColor = texture2D(texture0, fragTexCoord); + + // NOTE: Implement here your fragment shader code + + gl_FragColor = texelColor*fragTintColor; +} \ No newline at end of file diff --git a/shaders/glsl330/base.vs b/shaders/glsl330/base.vs new file mode 100644 index 00000000..b0f930b7 --- /dev/null +++ b/shaders/glsl330/base.vs @@ -0,0 +1,18 @@ +#version 330 + +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; + +out vec2 fragTexCoord; + +uniform mat4 mvpMatrix; + +// NOTE: Add here your custom variables + +void main() +{ + fragTexCoord = vertexTexCoord; + + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/shaders/glsl330/bloom.fs b/shaders/glsl330/bloom.fs new file mode 100644 index 00000000..34b6295c --- /dev/null +++ b/shaders/glsl330/bloom.fs @@ -0,0 +1,42 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// 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 += texture(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25; + } + } + + if (texture(texture0, fragTexCoord).r < 0.3) + { + tc = sum*sum*0.012 + texture(texture0, fragTexCoord); + } + else + { + if (texture(texture0, fragTexCoord).r < 0.5) + { + tc = sum*sum*0.009 + texture(texture0, fragTexCoord); + } + else + { + tc = sum*sum*0.0075 + texture(texture0, fragTexCoord); + } + } + + fragColor = tc; +} \ No newline at end of file diff --git a/shaders/glsl330/blur.fs b/shaders/glsl330/blur.fs new file mode 100644 index 00000000..44ea42b1 --- /dev/null +++ b/shaders/glsl330/blur.fs @@ -0,0 +1,29 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +const float renderWidth = 1280.0; +const float renderHeight = 720.0; + +float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); +float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); + +void main() +{ + vec3 tc = texture(texture0, fragTexCoord).rgb*weight[0]; + + for (int i = 1; i < 3; i++) + { + tc += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + tc += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + } + + fragColor = vec4(tc, 1.0); +} \ No newline at end of file diff --git a/shaders/glsl330/cross_hatching.fs b/shaders/glsl330/cross_hatching.fs new file mode 100644 index 00000000..6f5df964 --- /dev/null +++ b/shaders/glsl330/cross_hatching.fs @@ -0,0 +1,44 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +float hatchOffsetY = 5.0; +float lumThreshold01 = 0.9; +float lumThreshold02 = 0.7; +float lumThreshold03 = 0.5; +float lumThreshold04 = 0.3; + +void main() +{ + vec3 tc = vec3(1.0, 1.0, 1.0); + float lum = length(texture(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); +} \ No newline at end of file diff --git a/shaders/glsl330/cross_stitching.fs b/shaders/glsl330/cross_stitching.fs new file mode 100644 index 00000000..dcb26e79 --- /dev/null +++ b/shaders/glsl330/cross_stitching.fs @@ -0,0 +1,54 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +const float renderWidth = 1280.0; +const float renderHeight = 720.0; + +float stitchingSize = 6.0; + +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 = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4; + } + else + { + if (invert == 1) c = texture(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); +} \ No newline at end of file diff --git a/shaders/glsl330/dream_vision.fs b/shaders/glsl330/dream_vision.fs new file mode 100644 index 00000000..0ea4ce20 --- /dev/null +++ b/shaders/glsl330/dream_vision.fs @@ -0,0 +1,34 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 color = texture(texture0, fragTexCoord); + + color += texture(texture0, fragTexCoord + 0.001); + color += texture(texture0, fragTexCoord + 0.003); + color += texture(texture0, fragTexCoord + 0.005); + color += texture(texture0, fragTexCoord + 0.007); + color += texture(texture0, fragTexCoord + 0.009); + color += texture(texture0, fragTexCoord + 0.011); + + color += texture(texture0, fragTexCoord - 0.001); + color += texture(texture0, fragTexCoord - 0.003); + color += texture(texture0, fragTexCoord - 0.005); + color += texture(texture0, fragTexCoord - 0.007); + color += texture(texture0, fragTexCoord - 0.009); + color += texture(texture0, fragTexCoord - 0.011); + + color.rgb = vec3((color.r + color.g + color.b)/3.0); + color = color/9.5; + + fragColor = color; +} \ No newline at end of file diff --git a/shaders/glsl330/fisheye.fs b/shaders/glsl330/fisheye.fs new file mode 100644 index 00000000..5bd9abf4 --- /dev/null +++ b/shaders/glsl330/fisheye.fs @@ -0,0 +1,40 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +const float PI = 3.1415926535; + +void main() +{ + float aperture = 178.0; + 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 = texture(texture0, uv); +} \ No newline at end of file diff --git a/shaders/glsl330/grayscale.fs b/shaders/glsl330/grayscale.fs new file mode 100644 index 00000000..b3a695bf --- /dev/null +++ b/shaders/glsl330/grayscale.fs @@ -0,0 +1,20 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 base = texture(texture0, fragTexCoord)*fragTintColor; + + // Convert to grayscale using NTSC conversion weights + float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); + + fragColor = vec4(gray, gray, gray, fragTintColor.a); +} \ No newline at end of file diff --git a/shaders/glsl330/phong.fs b/shaders/glsl330/phong.fs new file mode 100644 index 00000000..75b7e6d7 --- /dev/null +++ b/shaders/glsl330/phong.fs @@ -0,0 +1,76 @@ +#version 330 + +// Vertex shader input data +in vec2 fragTexCoord; +in vec3 fragNormal; + +// Diffuse data +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// Light attributes +uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); +uniform vec3 light_diffuseColor = vec3(1, 0.5, 0); +uniform vec3 light_specularColor = vec3(0, 1, 0); +uniform float light_intensity = 1; +uniform float light_specIntensity = 1; + +// Material attributes +uniform vec3 mat_ambientColor = vec3(1, 1, 1); +uniform vec3 mat_specularColor = vec3(1, 1, 1); +uniform float mat_glossiness = 50; + +// World attributes +uniform vec3 lightPos; +uniform vec3 cameraPos; + +// Fragment shader output data +out vec4 fragColor; + +vec3 AmbientLighting() +{ + return mat_ambientColor * light_ambientColor; +} + +vec3 DiffuseLighting(in vec3 N, in vec3 L) +{ + // Lambertian reflection calculation + float diffuse = clamp(dot(N, L), 0, 1); + + return tintColor.xyz * light_diffuseColor * light_intensity * diffuse; +} + +vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V) +{ + float specular = 0; + + // Calculate specular reflection only if the surface is oriented to the light source + if(dot(N, L) > 0) + { + // Calculate half vector + vec3 H = normalize(L + V); + + // Calculate specular intensity + specular = pow(dot(N, H), 3 + mat_glossiness); + } + + return mat_specularColor * light_specularColor * light_specIntensity * specular; +} + +void main() +{ + // Normalize input vectors + vec3 L = normalize(lightPos); + vec3 V = normalize(cameraPos); + vec3 N = normalize(fragNormal); + + vec3 ambient = AmbientLighting(); + vec3 diffuse = DiffuseLighting(N, L); + vec3 specular = SpecularLighting(N, L, V); + + // Get base color from texture + vec4 textureColor = texture(texture0, fragTexCoord); + vec3 finalColor = textureColor.rgb; + + fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a); +} \ No newline at end of file diff --git a/shaders/glsl330/phong.vs b/shaders/glsl330/phong.vs new file mode 100644 index 00000000..ee6d34bf --- /dev/null +++ b/shaders/glsl330/phong.vs @@ -0,0 +1,27 @@ +#version 330 + +// Vertex input data +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; + +// Projection and model data +uniform mat4 mvpMatrix; +uniform mat4 modelMatrix; + +// Attributes to fragment shader +out vec2 fragTexCoord; +out vec3 fragNormal; + +void main() +{ + // Send texture coord to fragment shader + fragTexCoord = vertexTexCoord; + + // Calculate view vector normal from model + mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); + fragNormal = normalize(normalMatrix*vertexNormal); + + // Calculate final vertex position + gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/shaders/glsl330/pixel.fs b/shaders/glsl330/pixel.fs new file mode 100644 index 00000000..aa5a22fe --- /dev/null +++ b/shaders/glsl330/pixel.fs @@ -0,0 +1,28 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +const float renderWidth = 1280.0; +const float renderHeight = 720.0; + +uniform float pixelWidth = 5.0; +uniform float pixelHeight = 5.0; + +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 = texture(texture0, coord).rgb; + + fragColor = vec4(tc, 1.0); +} \ No newline at end of file diff --git a/shaders/glsl330/posterization.fs b/shaders/glsl330/posterization.fs new file mode 100644 index 00000000..5215bd8b --- /dev/null +++ b/shaders/glsl330/posterization.fs @@ -0,0 +1,26 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +float gamma = 0.6; +float numColors = 8.0; + +void main() +{ + vec3 color = texture(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); +} \ No newline at end of file diff --git a/shaders/glsl330/predator.fs b/shaders/glsl330/predator.fs new file mode 100644 index 00000000..85c93d0c --- /dev/null +++ b/shaders/glsl330/predator.fs @@ -0,0 +1,27 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec3 color = texture(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); +} \ No newline at end of file diff --git a/shaders/glsl330/scanlines.fs b/shaders/glsl330/scanlines.fs new file mode 100644 index 00000000..0c89e610 --- /dev/null +++ b/shaders/glsl330/scanlines.fs @@ -0,0 +1,41 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +float offset = 0.0; +float frequency = 720.0/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 = texture(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 = texture(texture0, fragTexCoord); + + fragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); +} \ No newline at end of file diff --git a/shaders/glsl330/swirl.fs b/shaders/glsl330/swirl.fs new file mode 100644 index 00000000..19d7468b --- /dev/null +++ b/shaders/glsl330/swirl.fs @@ -0,0 +1,41 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +const float renderWidth = 1280.0; +const float renderHeight = 720.0; + +float radius = 250.0; +float angle = 0.8; + +uniform vec2 center = vec2(200.0, 200.0); + +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 = texture(texture0, tc/texSize).rgb; + + fragColor = vec4(color, 1.0);; +} \ No newline at end of file diff --git a/shaders/glsl330/template.fs b/shaders/glsl330/template.fs new file mode 100644 index 00000000..ad7210a4 --- /dev/null +++ b/shaders/glsl330/template.fs @@ -0,0 +1,19 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 fragTintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 texelColor = texture(texture0, fragTexCoord); + + // NOTE: Implement here your fragment shader code + + fragColor = texelColor*fragTintColor; +} -- cgit v1.2.3 From bc08271da3e68d2880f4ef712c13e88b99f1021d Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 18 May 2016 12:04:27 +0200 Subject: Updated shaders with comments --- shaders/glsl100/base.vs | 14 ++++-- shaders/glsl100/bloom.fs | 25 +++++------ shaders/glsl100/blur.fs | 5 +++ shaders/glsl100/cross_hatching.fs | 5 ++- shaders/glsl100/cross_stitching.fs | 5 ++- shaders/glsl100/dream_vision.fs | 3 ++ shaders/glsl100/fisheye.fs | 5 ++- shaders/glsl100/grayscale.fs | 13 ++++-- shaders/glsl100/pixel.fs | 3 ++ shaders/glsl100/posterization.fs | 3 ++ shaders/glsl100/predator.fs | 3 ++ shaders/glsl100/scanlines.fs | 5 ++- shaders/glsl100/swirl.fs | 16 ++++--- shaders/glsl100/template.fs | 4 ++ shaders/glsl330/base.vs | 12 +++++- shaders/glsl330/bloom.fs | 34 +++++++-------- shaders/glsl330/blur.fs | 19 ++++++--- shaders/glsl330/cross_hatching.fs | 18 +++++--- shaders/glsl330/cross_stitching.fs | 12 ++++-- shaders/glsl330/depth.fs | 27 ++++++++++++ shaders/glsl330/grayscale.fs | 18 +++++--- shaders/glsl330/phong.fs | 87 +++++++++++++++++++++----------------- shaders/glsl330/phong.vs | 14 +++--- shaders/glsl330/pixel.fs | 12 ++++-- shaders/glsl330/posterization.fs | 23 ++++++---- shaders/glsl330/predator.fs | 15 ++++--- shaders/glsl330/scanlines.fs | 15 ++++--- shaders/glsl330/swirl.fs | 17 +++++--- shaders/glsl330/template.fs | 11 +++-- 29 files changed, 288 insertions(+), 155 deletions(-) create mode 100644 shaders/glsl330/depth.fs (limited to 'shaders') diff --git a/shaders/glsl100/base.vs b/shaders/glsl100/base.vs index 9f339382..e9386939 100644 --- a/shaders/glsl100/base.vs +++ b/shaders/glsl100/base.vs @@ -1,20 +1,26 @@ #version 100 +// Input vertex attributes attribute vec3 vertexPosition; attribute vec2 vertexTexCoord; attribute vec3 vertexNormal; +attribute vec4 vertexColor; -varying vec2 fragTexCoord; - +// Input uniform values uniform mat4 mvpMatrix; +// Output vertex attributes (to fragment shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + // NOTE: Add here your custom variables void main() { - vec3 normal = vertexNormal; - + // Send vertex attributes to fragment shader fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + // Calculate final vertex position gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/shaders/glsl100/bloom.fs b/shaders/glsl100/bloom.fs index 33754c7e..280d2fb6 100644 --- a/shaders/glsl100/bloom.fs +++ b/shaders/glsl100/bloom.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; @@ -22,21 +25,13 @@ void main() } } - 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); - } - } + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + + // Calculate final fragment color + if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor; + else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor; + else tc = sum*sum*0.0075 + texelColor; gl_FragColor = tc; } \ No newline at end of file diff --git a/shaders/glsl100/blur.fs b/shaders/glsl100/blur.fs index a1069c6f..80d40834 100644 --- a/shaders/glsl100/blur.fs +++ b/shaders/glsl100/blur.fs @@ -2,7 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; @@ -16,6 +20,7 @@ float weight[3] = float[]( 0.2270270270, 0.3162162162, 0.0702702703 ); void main() { + // Texel color fetching from texture sampler vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight[0]; for (int i = 1; i < 3; i++) diff --git a/shaders/glsl100/cross_hatching.fs b/shaders/glsl100/cross_hatching.fs index cf01b65e..1f7dab08 100644 --- a/shaders/glsl100/cross_hatching.fs +++ b/shaders/glsl100/cross_hatching.fs @@ -2,12 +2,15 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; -// NOTE: Add here your custom variables +// NOTE: Add here your custom variables float hatchOffsetY = 5.0f; float lumThreshold01 = 0.9f; diff --git a/shaders/glsl100/cross_stitching.fs b/shaders/glsl100/cross_stitching.fs index f1afef04..6fabc027 100644 --- a/shaders/glsl100/cross_stitching.fs +++ b/shaders/glsl100/cross_stitching.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; @@ -46,7 +49,7 @@ vec4 PostFX(sampler2D tex, vec2 uv) return c; } -void main(void) +void main() { vec3 tc = PostFX(texture0, fragTexCoord).rgb; diff --git a/shaders/glsl100/dream_vision.fs b/shaders/glsl100/dream_vision.fs index bb828970..d0cdc687 100644 --- a/shaders/glsl100/dream_vision.fs +++ b/shaders/glsl100/dream_vision.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; diff --git a/shaders/glsl100/fisheye.fs b/shaders/glsl100/fisheye.fs index e7a4485c..9dba297b 100644 --- a/shaders/glsl100/fisheye.fs +++ b/shaders/glsl100/fisheye.fs @@ -2,12 +2,15 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; -// NOTE: Add here your custom variables +// NOTE: Add here your custom variables const float PI = 3.1415926535; diff --git a/shaders/glsl100/grayscale.fs b/shaders/glsl100/grayscale.fs index e55545e2..f92ec335 100644 --- a/shaders/glsl100/grayscale.fs +++ b/shaders/glsl100/grayscale.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; @@ -11,10 +14,12 @@ uniform vec4 fragTintColor; void main() { - vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor; + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor; - // Convert to grayscale using NTSC conversion weights - float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); + // Convert texel color to grayscale using NTSC conversion weights + float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); - gl_FragColor = vec4(gray, gray, gray, fragTintColor.a); + // Calculate final fragment color + gl_FragColor = vec4(gray, gray, gray, texelColor.a); } \ No newline at end of file diff --git a/shaders/glsl100/pixel.fs b/shaders/glsl100/pixel.fs index 552e8900..c532f219 100644 --- a/shaders/glsl100/pixel.fs +++ b/shaders/glsl100/pixel.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; diff --git a/shaders/glsl100/posterization.fs b/shaders/glsl100/posterization.fs index 4f4c4b93..801ca89c 100644 --- a/shaders/glsl100/posterization.fs +++ b/shaders/glsl100/posterization.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; diff --git a/shaders/glsl100/predator.fs b/shaders/glsl100/predator.fs index 2fbdc7af..1f0e2ce5 100644 --- a/shaders/glsl100/predator.fs +++ b/shaders/glsl100/predator.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; diff --git a/shaders/glsl100/scanlines.fs b/shaders/glsl100/scanlines.fs index 85de158d..d885e10b 100644 --- a/shaders/glsl100/scanlines.fs +++ b/shaders/glsl100/scanlines.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; @@ -14,7 +17,7 @@ float frequency = 720/3.0; uniform float time; -void main (void) +void main() { /* // Scanlines method 1 diff --git a/shaders/glsl100/swirl.fs b/shaders/glsl100/swirl.fs index b0d54b23..0d6d24f2 100644 --- a/shaders/glsl100/swirl.fs +++ b/shaders/glsl100/swirl.fs @@ -2,28 +2,32 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; // NOTE: Add here your custom variables -const float renderWidth = 1280; -const float renderHeight = 720; +const float renderWidth = 800.0; // HARDCODED for example! +const float renderHeight = 480.0; // Use uniforms instead... float radius = 250.0; float angle = 0.8; -uniform vec2 center = vec2(200, 200); +uniform vec2 center = vec2(200.0, 200.0); -void main (void) +void main() { vec2 texSize = vec2(renderWidth, renderHeight); vec2 tc = fragTexCoord*texSize; tc -= center; - float dist = length(tc); + float dist = length(tc); + if (dist < radius) { float percent = (radius - dist)/radius; @@ -33,7 +37,7 @@ void main (void) tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); } - + tc += center; vec3 color = texture2D(texture0, tc/texSize).rgb; diff --git a/shaders/glsl100/template.fs b/shaders/glsl100/template.fs index 1f4b8ccf..a3942890 100644 --- a/shaders/glsl100/template.fs +++ b/shaders/glsl100/template.fs @@ -2,8 +2,11 @@ precision mediump float; +// Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; +varying vec4 fragColor; +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; @@ -11,6 +14,7 @@ uniform vec4 fragTintColor; void main() { + // Texel color fetching from texture sampler vec4 texelColor = texture2D(texture0, fragTexCoord); // NOTE: Implement here your fragment shader code diff --git a/shaders/glsl330/base.vs b/shaders/glsl330/base.vs index b0f930b7..638cb8ae 100644 --- a/shaders/glsl330/base.vs +++ b/shaders/glsl330/base.vs @@ -1,18 +1,26 @@ #version 330 +// Input vertex attributes in vec3 vertexPosition; in vec2 vertexTexCoord; in vec3 vertexNormal; +in vec4 vertexColor; -out vec2 fragTexCoord; - +// Input uniform values uniform mat4 mvpMatrix; +// Output vertex attributes (to fragment shader) +out vec2 fragTexCoord; +out vec4 fragColor; + // NOTE: Add here your custom variables void main() { + // Send vertex attributes to fragment shader fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + // Calculate final vertex position gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/bloom.fs b/shaders/glsl330/bloom.fs index 34b6295c..0307bc06 100644 --- a/shaders/glsl330/bloom.fs +++ b/shaders/glsl330/bloom.fs @@ -1,12 +1,16 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables void main() @@ -18,25 +22,17 @@ void main() { for (int j = -3; j < 3; j++) { - sum += texture(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25; + sum += texture(texture0, fragTexCoord + vec2(j, i)*0.004)*0.25; } } - if (texture(texture0, fragTexCoord).r < 0.3) - { - tc = sum*sum*0.012 + texture(texture0, fragTexCoord); - } - else - { - if (texture(texture0, fragTexCoord).r < 0.5) - { - tc = sum*sum*0.009 + texture(texture0, fragTexCoord); - } - else - { - tc = sum*sum*0.0075 + texture(texture0, fragTexCoord); - } - } + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); - fragColor = tc; + // Calculate final fragment color + if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor; + else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor; + else tc = sum*sum*0.0075 + texelColor; + + finalColor = tc; } \ No newline at end of file diff --git a/shaders/glsl330/blur.fs b/shaders/glsl330/blur.fs index 44ea42b1..7c31f727 100644 --- a/shaders/glsl330/blur.fs +++ b/shaders/glsl330/blur.fs @@ -1,12 +1,16 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables const float renderWidth = 1280.0; @@ -17,13 +21,14 @@ float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); void main() { - vec3 tc = texture(texture0, fragTexCoord).rgb*weight[0]; - + // Texel color fetching from texture sampler + vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0]; + for (int i = 1; i < 3; i++) { - tc += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; - tc += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; + texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i]; } - fragColor = vec4(tc, 1.0); + finalColor = vec4(texelColor, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/cross_hatching.fs b/shaders/glsl330/cross_hatching.fs index 6f5df964..c12c48cd 100644 --- a/shaders/glsl330/cross_hatching.fs +++ b/shaders/glsl330/cross_hatching.fs @@ -1,13 +1,17 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; -// NOTE: Add here your custom variables +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables float hatchOffsetY = 5.0; float lumThreshold01 = 0.9; @@ -27,18 +31,18 @@ void main() if (lum < lumThreshold02) { - if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0); + 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 (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); + 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); + finalColor = vec4(tc, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/cross_stitching.fs b/shaders/glsl330/cross_stitching.fs index dcb26e79..7c87c6cd 100644 --- a/shaders/glsl330/cross_stitching.fs +++ b/shaders/glsl330/cross_stitching.fs @@ -1,12 +1,16 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables const float renderWidth = 1280.0; @@ -46,9 +50,9 @@ vec4 PostFX(sampler2D tex, vec2 uv) return c; } -void main(void) +void main() { vec3 tc = PostFX(texture0, fragTexCoord).rgb; - fragColor = vec4(tc, 1.0); + finalColor = vec4(tc, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/depth.fs b/shaders/glsl330/depth.fs new file mode 100644 index 00000000..06d399f9 --- /dev/null +++ b/shaders/glsl330/depth.fs @@ -0,0 +1,27 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; // Depth texture +uniform vec4 fragTintColor; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables + +void main() +{ + float zNear = 0.01; // camera z near + float zFar = 10.0; // camera z far + float z = texture(texture0, fragTexCoord).x; + + // Linearize depth value + float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); + + // Calculate final fragment color + finalColor = vec4(depth, depth, depth, 1.0f); +} \ No newline at end of file diff --git a/shaders/glsl330/grayscale.fs b/shaders/glsl330/grayscale.fs index b3a695bf..d4a8824f 100644 --- a/shaders/glsl330/grayscale.fs +++ b/shaders/glsl330/grayscale.fs @@ -1,20 +1,26 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables void main() { - vec4 base = texture(texture0, fragTexCoord)*fragTintColor; + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor; - // Convert to grayscale using NTSC conversion weights - float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); + // Convert texel color to grayscale using NTSC conversion weights + float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); - fragColor = vec4(gray, gray, gray, fragTintColor.a); + // Calculate final fragment color + finalColor = vec4(gray, gray, gray, texelColor.a); } \ No newline at end of file diff --git a/shaders/glsl330/phong.fs b/shaders/glsl330/phong.fs index 75b7e6d7..c14b346a 100644 --- a/shaders/glsl330/phong.fs +++ b/shaders/glsl330/phong.fs @@ -1,76 +1,85 @@ #version 330 -// Vertex shader input data +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; in vec3 fragNormal; -// Diffuse data +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; -// Light attributes -uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0); -uniform vec3 light_diffuseColor = vec3(1, 0.5, 0); -uniform vec3 light_specularColor = vec3(0, 1, 0); -uniform float light_intensity = 1; -uniform float light_specIntensity = 1; +// Output fragment color +out vec4 finalColor; -// Material attributes -uniform vec3 mat_ambientColor = vec3(1, 1, 1); -uniform vec3 mat_specularColor = vec3(1, 1, 1); -uniform float mat_glossiness = 50; +// NOTE: Add here your custom variables -// World attributes -uniform vec3 lightPos; -uniform vec3 cameraPos; +// Light uniform values +uniform vec3 lightAmbientColor = vec3(0.6, 0.3, 0.0); +uniform vec3 lightDiffuseColor = vec3(1.0, 0.5, 0.0); +uniform vec3 lightSpecularColor = vec3(0.0, 1.0, 0.0); +uniform float lightIntensity = 1.0; +uniform float lightSpecIntensity = 1.0; + +// Material uniform values +uniform vec3 matAmbientColor = vec3(1.0, 1.0, 1.0); +uniform vec3 matSpecularColor = vec3(1.0, 1.0, 1.0); +uniform float matGlossiness = 50.0; + +// World uniform values +uniform vec3 lightPosition; +uniform vec3 cameraPosition; // Fragment shader output data out vec4 fragColor; +// Calculate ambient lighting component vec3 AmbientLighting() { - return mat_ambientColor * light_ambientColor; + return (matAmbientColor*lightAmbientColor); } +// Calculate diffuse lighting component vec3 DiffuseLighting(in vec3 N, in vec3 L) { - // Lambertian reflection calculation - float diffuse = clamp(dot(N, L), 0, 1); - - return tintColor.xyz * light_diffuseColor * light_intensity * diffuse; + // Lambertian reflection calculation + float diffuse = clamp(dot(N, L), 0, 1); + + return (fragTintColor.xyz*lightDiffuseColor*lightIntensity*diffuse); } +// Calculate specular lighting component vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V) { - float specular = 0; - - // Calculate specular reflection only if the surface is oriented to the light source - if(dot(N, L) > 0) - { - // Calculate half vector - vec3 H = normalize(L + V); - - // Calculate specular intensity - specular = pow(dot(N, H), 3 + mat_glossiness); - } + float specular = 0.0; + + // Calculate specular reflection only if the surface is oriented to the light source + if (dot(N, L) > 0) + { + // Calculate half vector + vec3 H = normalize(L + V); + + // Calculate specular intensity + specular = pow(dot(N, H), 3 + matGlossiness); + } - return mat_specularColor * light_specularColor * light_specIntensity * specular; + return (matSpecularColor*lightSpecularColor*lightSpecIntensity*specular); } void main() { // Normalize input vectors - vec3 L = normalize(lightPos); - vec3 V = normalize(cameraPos); + vec3 L = normalize(lightPosition); + vec3 V = normalize(cameraPosition); vec3 N = normalize(fragNormal); + // Calculate lighting components vec3 ambient = AmbientLighting(); vec3 diffuse = DiffuseLighting(N, L); vec3 specular = SpecularLighting(N, L, V); - // Get base color from texture - vec4 textureColor = texture(texture0, fragTexCoord); - vec3 finalColor = textureColor.rgb; - - fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a); + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + + // Calculate final fragment color + finalColor = vec4(texelColor.rgb*(ambient + diffuse + specular), texelColor.a); } \ No newline at end of file diff --git a/shaders/glsl330/phong.vs b/shaders/glsl330/phong.vs index ee6d34bf..d68d9b3f 100644 --- a/shaders/glsl330/phong.vs +++ b/shaders/glsl330/phong.vs @@ -1,23 +1,25 @@ #version 330 -// Vertex input data +// Input vertex attributes in vec3 vertexPosition; in vec2 vertexTexCoord; in vec3 vertexNormal; -// Projection and model data +// Input uniform values uniform mat4 mvpMatrix; -uniform mat4 modelMatrix; -// Attributes to fragment shader +// Output vertex attributes (to fragment shader) out vec2 fragTexCoord; out vec3 fragNormal; +// NOTE: Add here your custom variables +uniform mat4 modelMatrix; + void main() { - // Send texture coord to fragment shader + // Send vertex attributes to fragment shader fragTexCoord = vertexTexCoord; - + // Calculate view vector normal from model mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); fragNormal = normalize(normalMatrix*vertexNormal); diff --git a/shaders/glsl330/pixel.fs b/shaders/glsl330/pixel.fs index aa5a22fe..9ed3ea7d 100644 --- a/shaders/glsl330/pixel.fs +++ b/shaders/glsl330/pixel.fs @@ -1,13 +1,17 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; -// NOTE: Add here your custom variables +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables const float renderWidth = 1280.0; const float renderHeight = 720.0; @@ -24,5 +28,5 @@ void main() vec3 tc = texture(texture0, coord).rgb; - fragColor = vec4(tc, 1.0); + finalColor = vec4(tc, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/posterization.fs b/shaders/glsl330/posterization.fs index 5215bd8b..f1d72a19 100644 --- a/shaders/glsl330/posterization.fs +++ b/shaders/glsl330/posterization.fs @@ -1,12 +1,16 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables float gamma = 0.6; @@ -14,13 +18,14 @@ float numColors = 8.0; void main() { - vec3 color = texture(texture0, fragTexCoord.xy).rgb; + // Texel color fetching from texture sampler + vec3 texelColor = texture(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)); + texelColor = pow(texelColor, vec3(gamma, gamma, gamma)); + texelColor = texelColor*numColors; + texelColor = floor(texelColor); + texelColor = texelColor/numColors; + texelColor = pow(texelColor, vec3(1.0/gamma)); - fragColor = vec4(color, 1.0); + finalColor = vec4(texelColor, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/predator.fs b/shaders/glsl330/predator.fs index 85c93d0c..9269dfd4 100644 --- a/shaders/glsl330/predator.fs +++ b/shaders/glsl330/predator.fs @@ -1,27 +1,32 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables void main() { - vec3 color = texture(texture0, fragTexCoord).rgb; + // Texel color fetching from texture sampler + vec3 texelColor = texture(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; + float lum = (texelColor.r + texelColor.g + texelColor.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); + finalColor = vec4(tc, 1.0); } \ No newline at end of file diff --git a/shaders/glsl330/scanlines.fs b/shaders/glsl330/scanlines.fs index 0c89e610..177f000d 100644 --- a/shaders/glsl330/scanlines.fs +++ b/shaders/glsl330/scanlines.fs @@ -1,12 +1,16 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables float offset = 0.0; @@ -14,7 +18,7 @@ float frequency = 720.0/3.0; uniform float time; -void main (void) +void main() { /* // Scanlines method 1 @@ -35,7 +39,8 @@ void main (void) float globalPos = (fragTexCoord.y + offset) * frequency; float wavePos = cos((fract(globalPos) - 0.5)*3.14); - vec4 color = texture(texture0, fragTexCoord); + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); - fragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); + finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos); } \ No newline at end of file diff --git a/shaders/glsl330/swirl.fs b/shaders/glsl330/swirl.fs index 19d7468b..80c16cc9 100644 --- a/shaders/glsl330/swirl.fs +++ b/shaders/glsl330/swirl.fs @@ -1,27 +1,32 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables -const float renderWidth = 1280.0; -const float renderHeight = 720.0; +const float renderWidth = 800.0; // HARDCODED for example! +const float renderHeight = 480.0; // Use uniforms instead... float radius = 250.0; float angle = 0.8; uniform vec2 center = vec2(200.0, 200.0); -void main (void) +void main() { vec2 texSize = vec2(renderWidth, renderHeight); vec2 tc = fragTexCoord*texSize; tc -= center; + float dist = length(tc); if (dist < radius) @@ -37,5 +42,5 @@ void main (void) tc += center; vec3 color = texture(texture0, tc/texSize).rgb; - fragColor = vec4(color, 1.0);; + finalColor = vec4(color, 1.0);; } \ No newline at end of file diff --git a/shaders/glsl330/template.fs b/shaders/glsl330/template.fs index ad7210a4..55b8d4a4 100644 --- a/shaders/glsl330/template.fs +++ b/shaders/glsl330/template.fs @@ -1,19 +1,24 @@ #version 330 +// Input vertex attributes (from vertex shader) in vec2 fragTexCoord; +in vec4 fragColor; -out vec4 fragColor; - +// Input uniform values uniform sampler2D texture0; uniform vec4 fragTintColor; +// Output fragment color +out vec4 finalColor; + // NOTE: Add here your custom variables void main() { + // Texel color fetching from texture sampler vec4 texelColor = texture(texture0, fragTexCoord); // NOTE: Implement here your fragment shader code - fragColor = texelColor*fragTintColor; + finalColor = texelColor*fragTintColor; } -- cgit v1.2.3