summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/shaders/resources/shaders/glsl100/base.fs24
-rw-r--r--examples/shaders/resources/shaders/glsl100/blur.fs34
-rw-r--r--examples/shaders/resources/shaders/glsl100/cross_hatching.fs47
-rw-r--r--examples/shaders/resources/shaders/glsl100/cross_stitching.fs57
-rw-r--r--examples/shaders/resources/shaders/glsl100/dream_vision.fs37
-rw-r--r--examples/shaders/resources/shaders/glsl100/fisheye.fs43
-rw-r--r--examples/shaders/resources/shaders/glsl100/pixelizer.fs32
-rw-r--r--examples/shaders/resources/shaders/glsl100/posterization.fs29
-rw-r--r--examples/shaders/resources/shaders/glsl100/predator.fs31
-rw-r--r--examples/shaders/resources/shaders/glsl100/scanlines.fs44
-rw-r--r--examples/shaders/resources/shaders/glsl100/sobel.fs40
-rw-r--r--examples/shaders/resources/shaders/glsl100/swirl.fs5
-rw-r--r--examples/shaders/resources/shaders/glsl330/base.fs25
-rw-r--r--examples/shaders/resources/shaders/glsl330/blur.fs35
-rw-r--r--examples/shaders/resources/shaders/glsl330/cross_hatching.fs48
-rw-r--r--examples/shaders/resources/shaders/glsl330/cross_stitching.fs59
-rw-r--r--examples/shaders/resources/shaders/glsl330/depth.fs2
-rw-r--r--examples/shaders/resources/shaders/glsl330/dream_vision.fs34
-rw-r--r--examples/shaders/resources/shaders/glsl330/fisheye.fs40
-rw-r--r--examples/shaders/resources/shaders/glsl330/overdraw.fs26
-rw-r--r--examples/shaders/resources/shaders/glsl330/pixelizer.fs33
-rw-r--r--examples/shaders/resources/shaders/glsl330/posterization.fs31
-rw-r--r--examples/shaders/resources/shaders/glsl330/predator.fs32
-rw-r--r--examples/shaders/resources/shaders/glsl330/scanlines.fs49
-rw-r--r--examples/shaders/resources/shaders/glsl330/sobel.fs41
-rw-r--r--examples/shaders/resources/shaders/glsl330/swirl.fs5
-rw-r--r--examples/shaders/shaders_postprocessing.c89
27 files changed, 959 insertions, 13 deletions
diff --git a/examples/shaders/resources/shaders/glsl100/base.fs b/examples/shaders/resources/shaders/glsl100/base.fs
new file mode 100644
index 00000000..b004ba0b
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/base.fs
@@ -0,0 +1,24 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+uniform vec2 resolution = vec2(800, 450);
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(texture0, fragTexCoord);
+
+ // NOTE: Implement here your fragment shader code
+
+ gl_FragColor = texelColor*colDiffuse;
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/blur.fs b/examples/shaders/resources/shaders/glsl100/blur.fs
new file mode 100644
index 00000000..96f780e1
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/blur.fs
@@ -0,0 +1,34 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800.0;
+const float renderHeight = 450.0;
+
+vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308);
+vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703);
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x;
+
+ tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
+ tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
+
+ tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
+ tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
+
+ gl_FragColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/cross_hatching.fs b/examples/shaders/resources/shaders/glsl100/cross_hatching.fs
new file mode 100644
index 00000000..7d63b0a5
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/cross_hatching.fs
@@ -0,0 +1,47 @@
+# version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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(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/examples/shaders/resources/shaders/glsl100/cross_stitching.fs b/examples/shaders/resources/shaders/glsl100/cross_stitching.fs
new file mode 100644
index 00000000..de6d4f40
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/cross_stitching.fs
@@ -0,0 +1,57 @@
+# version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800.0;
+const float renderHeight = 450.0;
+
+float stitchingSize = 6.0;
+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()
+{
+ vec3 tc = PostFX(texture0, fragTexCoord).rgb;
+
+ gl_FragColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/dream_vision.fs b/examples/shaders/resources/shaders/glsl100/dream_vision.fs
new file mode 100644
index 00000000..fa9c5b77
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/dream_vision.fs
@@ -0,0 +1,37 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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/examples/shaders/resources/shaders/glsl100/fisheye.fs b/examples/shaders/resources/shaders/glsl100/fisheye.fs
new file mode 100644
index 00000000..8beb3d4a
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/fisheye.fs
@@ -0,0 +1,43 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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.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/examples/shaders/resources/shaders/glsl100/pixelizer.fs b/examples/shaders/resources/shaders/glsl100/pixelizer.fs
new file mode 100644
index 00000000..44fb0ca2
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/pixelizer.fs
@@ -0,0 +1,32 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800.0;
+const float renderHeight = 450.0;
+
+float pixelWidth = 5.0;
+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 = texture2D(texture0, coord).rgb;
+
+ gl_FragColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/posterization.fs b/examples/shaders/resources/shaders/glsl100/posterization.fs
new file mode 100644
index 00000000..a7942c82
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/posterization.fs
@@ -0,0 +1,29 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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/examples/shaders/resources/shaders/glsl100/predator.fs b/examples/shaders/resources/shaders/glsl100/predator.fs
new file mode 100644
index 00000000..37dc0bdf
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/predator.fs
@@ -0,0 +1,31 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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;
+
+ vec3 tc = vec3(0.0, 0.0, 0.0);
+
+ if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5);
+ else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5);
+
+ gl_FragColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/scanlines.fs b/examples/shaders/resources/shaders/glsl100/scanlines.fs
new file mode 100644
index 00000000..ce649e1a
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/scanlines.fs
@@ -0,0 +1,44 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+
+float offset = 0.0;
+float frequency = 450.0/3.0;
+
+uniform float time;
+
+void main()
+{
+/*
+ // 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, 0.3, 0.0, 0.0), color, wavePos);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/sobel.fs b/examples/shaders/resources/shaders/glsl100/sobel.fs
new file mode 100644
index 00000000..745562ad
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/sobel.fs
@@ -0,0 +1,40 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+vec2 resolution = vec2(800.0, 450.0);
+
+void main()
+{
+ float x = 1.0/resolution.x;
+ float y = 1.0/resolution.y;
+
+ vec4 horizEdge = vec4(0.0);
+ horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
+ horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
+ horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
+ horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
+ horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
+ horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
+
+ vec4 vertEdge = vec4(0.0);
+ vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
+ vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
+ vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
+ vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
+ vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
+ vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
+
+ vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
+
+ gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl100/swirl.fs b/examples/shaders/resources/shaders/glsl100/swirl.fs
index ca7668b2..b969aab7 100644
--- a/examples/shaders/resources/shaders/glsl100/swirl.fs
+++ b/examples/shaders/resources/shaders/glsl100/swirl.fs
@@ -12,8 +12,9 @@ uniform vec4 colDiffuse;
// NOTE: Add here your custom variables
-const float renderWidth = 800.0; // HARDCODED for example!
-const float renderHeight = 480.0; // Use uniforms instead...
+// NOTE: Render size values should be passed from code
+const float renderWidth = 800;
+const float renderHeight = 450;
float radius = 250.0;
float angle = 0.8;
diff --git a/examples/shaders/resources/shaders/glsl330/base.fs b/examples/shaders/resources/shaders/glsl330/base.fs
new file mode 100644
index 00000000..f1418df1
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/base.fs
@@ -0,0 +1,25 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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
+
+ finalColor = texelColor*colDiffuse;
+}
+
diff --git a/examples/shaders/resources/shaders/glsl330/blur.fs b/examples/shaders/resources/shaders/glsl330/blur.fs
new file mode 100644
index 00000000..e4df406d
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/blur.fs
@@ -0,0 +1,35 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800;
+const float renderHeight = 450;
+
+float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
+float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0];
+
+ for (int i = 1; i < 3; 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];
+ }
+
+ finalColor = vec4(texelColor, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/cross_hatching.fs b/examples/shaders/resources/shaders/glsl330/cross_hatching.fs
new file mode 100644
index 00000000..f95ad075
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/cross_hatching.fs
@@ -0,0 +1,48 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// 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);
+ }
+
+ finalColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/cross_stitching.fs b/examples/shaders/resources/shaders/glsl330/cross_stitching.fs
new file mode 100644
index 00000000..9cdd36ca
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/cross_stitching.fs
@@ -0,0 +1,59 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800.0;
+const float renderHeight = 450.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()
+{
+ vec3 tc = PostFX(texture0, fragTexCoord).rgb;
+
+ finalColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/depth.fs b/examples/shaders/resources/shaders/glsl330/depth.fs
index 06d399f9..2422f390 100644
--- a/examples/shaders/resources/shaders/glsl330/depth.fs
+++ b/examples/shaders/resources/shaders/glsl330/depth.fs
@@ -6,7 +6,7 @@ in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0; // Depth texture
-uniform vec4 fragTintColor;
+uniform vec4 colDiffuse;
// Output fragment color
out vec4 finalColor;
diff --git a/examples/shaders/resources/shaders/glsl330/dream_vision.fs b/examples/shaders/resources/shaders/glsl330/dream_vision.fs
new file mode 100644
index 00000000..03115862
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/dream_vision.fs
@@ -0,0 +1,34 @@
+#version 330
+
+in vec2 fragTexCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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/examples/shaders/resources/shaders/glsl330/fisheye.fs b/examples/shaders/resources/shaders/glsl330/fisheye.fs
new file mode 100644
index 00000000..e85d7c9d
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/fisheye.fs
@@ -0,0 +1,40 @@
+#version 330
+
+in vec2 fragTexCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// 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/examples/shaders/resources/shaders/glsl330/overdraw.fs b/examples/shaders/resources/shaders/glsl330/overdraw.fs
new file mode 100644
index 00000000..435217c3
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/overdraw.fs
@@ -0,0 +1,26 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+void main()
+{
+ // To show overdraw, we just render all the fragments
+ // with a solid color and some transparency
+
+ // NOTE: This is not a postpro render,
+ // it will only render all screen texture in a plain color
+
+ finalColor = vec4(1.0, 0.0, 0.0, 0.2);
+}
+
diff --git a/examples/shaders/resources/shaders/glsl330/pixelizer.fs b/examples/shaders/resources/shaders/glsl330/pixelizer.fs
new file mode 100644
index 00000000..cf8aec44
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/pixelizer.fs
@@ -0,0 +1,33 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800;
+const float renderHeight = 450;
+
+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;
+
+ finalColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/posterization.fs b/examples/shaders/resources/shaders/glsl330/posterization.fs
new file mode 100644
index 00000000..be2b5dd6
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/posterization.fs
@@ -0,0 +1,31 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+float gamma = 0.6;
+float numColors = 8.0;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec3 texelColor = texture(texture0, fragTexCoord.xy).rgb;
+
+ texelColor = pow(texelColor, vec3(gamma, gamma, gamma));
+ texelColor = texelColor*numColors;
+ texelColor = floor(texelColor);
+ texelColor = texelColor/numColors;
+ texelColor = pow(texelColor, vec3(1.0/gamma));
+
+ finalColor = vec4(texelColor, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/predator.fs b/examples/shaders/resources/shaders/glsl330/predator.fs
new file mode 100644
index 00000000..6a55c762
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/predator.fs
@@ -0,0 +1,32 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+void main()
+{
+ // 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 = (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);
+
+ finalColor = vec4(tc, 1.0);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/scanlines.fs b/examples/shaders/resources/shaders/glsl330/scanlines.fs
new file mode 100644
index 00000000..22dc9cd5
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/scanlines.fs
@@ -0,0 +1,49 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+
+// NOTE: Render size values must be passed from code
+const float renderWidth = 800;
+const float renderHeight = 450;
+float offset = 0.0;
+
+uniform float time;
+
+void main()
+{
+ float frequency = renderHeight/3.0;
+/*
+ // 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);
+
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord);
+
+ finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/sobel.fs b/examples/shaders/resources/shaders/glsl330/sobel.fs
new file mode 100644
index 00000000..a1430cdd
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/sobel.fs
@@ -0,0 +1,41 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+uniform vec2 resolution = vec2(800, 450);
+
+void main()
+{
+ float x = 1.0/resolution.x;
+ float y = 1.0/resolution.y;
+
+ vec4 horizEdge = vec4(0.0);
+ horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
+ horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0;
+ horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
+ horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
+ horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0;
+ horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
+
+ vec4 vertEdge = vec4(0.0);
+ vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
+ vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0;
+ vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
+ vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
+ vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0;
+ vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;
+
+ vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));
+
+ finalColor = vec4(edge, texture2D(texture0, fragTexCoord).a);
+} \ No newline at end of file
diff --git a/examples/shaders/resources/shaders/glsl330/swirl.fs b/examples/shaders/resources/shaders/glsl330/swirl.fs
index 5d238ac9..4741e597 100644
--- a/examples/shaders/resources/shaders/glsl330/swirl.fs
+++ b/examples/shaders/resources/shaders/glsl330/swirl.fs
@@ -13,8 +13,9 @@ out vec4 finalColor;
// NOTE: Add here your custom variables
-const float renderWidth = 800.0; // HARDCODED for example!
-const float renderHeight = 480.0; // Use uniforms instead...
+// NOTE: Render size values should be passed from code
+const float renderWidth = 800;
+const float renderHeight = 450;
float radius = 250.0;
float angle = 0.8;
diff --git a/examples/shaders/shaders_postprocessing.c b/examples/shaders/shaders_postprocessing.c
index 43d1af72..bb239efa 100644
--- a/examples/shaders/shaders_postprocessing.c
+++ b/examples/shaders/shaders_postprocessing.c
@@ -18,6 +18,48 @@
#include "raylib.h"
+#if defined(PLATFORM_DESKTOP)
+ #define GLSL_VERSION 330
+ #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl330/base.vs"
+#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
+ #define GLSL_VERSION 100
+ #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl100/base.vs"
+#endif
+
+#define MAX_POSTPRO_SHADERS 12
+
+typedef enum {
+ FX_GRAYSCALE = 0,
+ FX_POSTERIZATION,
+ FX_DREAM_VISION,
+ FX_PIXELIZER,
+ FX_CROSS_HATCHING,
+ FX_CROSS_STITCHING,
+ FX_PREDATOR_VIEW,
+ FX_SCANLINES,
+ FX_FISHEYE,
+ FX_SOBEL,
+ FX_BLOOM,
+ FX_BLUR,
+ //FX_FXAA
+} PostproShader;
+
+static const char *postproShaderText[] = {
+ "GRAYSCALE",
+ "POSTERIZATION",
+ "DREAM_VISION",
+ "PIXELIZER",
+ "CROSS_HATCHING",
+ "CROSS_STITCHING",
+ "PREDATOR_VIEW",
+ "SCANLINES",
+ "FISHEYE",
+ "SOBEL",
+ "BLOOM",
+ "BLUR",
+ //"FXAA"
+};
+
int main()
{
// Initialization
@@ -38,8 +80,25 @@ int main()
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
- Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
- "resources/shaders/glsl330/bloom.fs"); // Load postpro shader
+ // Load all postpro shaders
+ // NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
+ // NOTE 2: We load the correct shader depending on GLSL version
+ Shader shaders[MAX_POSTPRO_SHADERS];
+
+ shaders[FX_GRAYSCALE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
+ shaders[FX_POSTERIZATION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION));
+ shaders[FX_DREAM_VISION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION));
+ shaders[FX_PIXELIZER] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION));
+ shaders[FX_CROSS_HATCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION));
+ shaders[FX_CROSS_STITCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION));
+ shaders[FX_PREDATOR_VIEW] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION));
+ shaders[FX_SCANLINES] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION));
+ shaders[FX_FISHEYE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION));
+ shaders[FX_SOBEL] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION));
+ shaders[FX_BLOOM] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION));
+ shaders[FX_BLUR] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION));
+
+ int currentShader = FX_GRAYSCALE;
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
@@ -56,6 +115,12 @@ int main()
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
+
+ if (IsKeyPressed(KEY_RIGHT)) currentShader++;
+ else if (IsKeyPressed(KEY_LEFT)) currentShader--;
+
+ if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0;
+ else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1;
//----------------------------------------------------------------------------------
// Draw
@@ -73,21 +138,26 @@ int main()
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();
-
- DrawText("HELLO POSTPROCESSING!", 70, 190, 50, RED);
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
- BeginShaderMode(shader);
+ // Render previously generated texture using selected postpro shader
+ BeginShaderMode(shaders[currentShader]);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
EndShaderMode();
+ DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));
+
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY);
-
- DrawFPS(10, 10);
+
+ DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
+ DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
+ DrawText("< >", 540, 10, 30, DARKBLUE);
+
+ DrawFPS(700, 15);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -95,7 +165,10 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadShader(shader); // Unload shader
+
+ // Unload all postpro shaders
+ for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]);
+
UnloadTexture(texture); // Unload texture
UnloadModel(dwarf); // Unload model
UnloadRenderTexture(target); // Unload render texture