summaryrefslogtreecommitdiffhomepage
path: root/docs/examples/web/resources/shaders
diff options
context:
space:
mode:
authorRay San <[email protected]>2017-02-06 18:48:56 +0100
committerRay San <[email protected]>2017-02-06 18:48:56 +0100
commit1f6eb1fc61d2cc0cca54a79c1516432f09c86313 (patch)
tree9ddff0e6ddba65004557c3628a3d56dfaf47ea4b /docs/examples/web/resources/shaders
parentf2f05a734d4999ffdc19629c838f46914650bbd0 (diff)
downloadraylib-1f6eb1fc61d2cc0cca54a79c1516432f09c86313.tar.gz
raylib-1f6eb1fc61d2cc0cca54a79c1516432f09c86313.zip
Moved raylib webpage to docs folder
raylib webpage has been completely reorganized and moved from gh-pages (a pain to work with) to docs folder. Useless libs have been removed, webs have been renamed, etc. Now it would be easier (hopefully) to update webpage. :)
Diffstat (limited to 'docs/examples/web/resources/shaders')
-rw-r--r--docs/examples/web/resources/shaders/glsl100/base.vs26
-rw-r--r--docs/examples/web/resources/shaders/glsl100/bloom.fs37
-rw-r--r--docs/examples/web/resources/shaders/glsl100/distortion.fs54
-rw-r--r--docs/examples/web/resources/shaders/glsl100/grayscale.fs25
-rw-r--r--docs/examples/web/resources/shaders/glsl100/swirl.fs45
-rw-r--r--docs/examples/web/resources/shaders/glsl330/base.vs26
-rw-r--r--docs/examples/web/resources/shaders/glsl330/bloom.fs38
-rw-r--r--docs/examples/web/resources/shaders/glsl330/depth.fs27
-rw-r--r--docs/examples/web/resources/shaders/glsl330/distortion.fs56
-rw-r--r--docs/examples/web/resources/shaders/glsl330/grayscale.fs26
-rw-r--r--docs/examples/web/resources/shaders/glsl330/swirl.fs46
11 files changed, 406 insertions, 0 deletions
diff --git a/docs/examples/web/resources/shaders/glsl100/base.vs b/docs/examples/web/resources/shaders/glsl100/base.vs
new file mode 100644
index 00000000..e9386939
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl100/base.vs
@@ -0,0 +1,26 @@
+#version 100
+
+// Input vertex attributes
+attribute vec3 vertexPosition;
+attribute vec2 vertexTexCoord;
+attribute vec3 vertexNormal;
+attribute vec4 vertexColor;
+
+// 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()
+{
+ // 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/docs/examples/web/resources/shaders/glsl100/bloom.fs b/docs/examples/web/resources/shaders/glsl100/bloom.fs
new file mode 100644
index 00000000..128736f2
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl100/bloom.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 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;
+ }
+ }
+
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(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/docs/examples/web/resources/shaders/glsl100/distortion.fs b/docs/examples/web/resources/shaders/glsl100/distortion.fs
new file mode 100644
index 00000000..50116ce0
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl100/distortion.fs
@@ -0,0 +1,54 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+
+// Input uniform values
+uniform sampler2D texture0;
+
+// NOTE: Default parameters for Oculus Rift DK2 device
+const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
+const vec2 RightLensCenter = vec2(0.7136753, 0.5);
+const vec2 LeftScreenCenter = vec2(0.25, 0.5);
+const vec2 RightScreenCenter = vec2(0.75, 0.5);
+const vec2 Scale = vec2(0.25, 0.45);
+const vec2 ScaleIn = vec2(4.0, 2.5);
+const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0);
+const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
+
+void main()
+{
+ // The following two variables need to be set per eye
+ vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter;
+ vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter;
+
+ // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter)
+ vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1]
+ float rSq = theta.x*theta.x + theta.y*theta.y;
+ vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
+ //vec2 tc = LensCenter + Scale*theta1;
+
+ // Detect whether blue texture coordinates are out of range since these will scaled out the furthest
+ vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq);
+ vec2 tcBlue = LensCenter + Scale*thetaBlue;
+
+ if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ else
+ {
+ // Do blue texture lookup
+ float blue = texture2D(texture0, tcBlue).b;
+
+ // Do green lookup (no scaling)
+ vec2 tcGreen = LensCenter + Scale*theta1;
+ float green = texture2D(texture0, tcGreen).g;
+
+ // Do red scale and lookup
+ vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq);
+ vec2 tcRed = LensCenter + Scale*thetaRed;
+ float red = texture2D(texture0, tcRed).r;
+
+ gl_FragColor = vec4(red, green, blue, 1.0);
+ }
+}
diff --git a/docs/examples/web/resources/shaders/glsl100/grayscale.fs b/docs/examples/web/resources/shaders/glsl100/grayscale.fs
new file mode 100644
index 00000000..15174ea5
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl100/grayscale.fs
@@ -0,0 +1,25 @@
+#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()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor;
+
+ // Convert texel color to grayscale using NTSC conversion weights
+ float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
+
+ // Calculate final fragment color
+ gl_FragColor = vec4(gray, gray, gray, texelColor.a);
+} \ No newline at end of file
diff --git a/docs/examples/web/resources/shaders/glsl100/swirl.fs b/docs/examples/web/resources/shaders/glsl100/swirl.fs
new file mode 100644
index 00000000..95de61fa
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl100/swirl.fs
@@ -0,0 +1,45 @@
+#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 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()
+{
+ 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;
+ vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
+
+ gl_FragColor = vec4(color.rgb, 1.0);;
+} \ No newline at end of file
diff --git a/docs/examples/web/resources/shaders/glsl330/base.vs b/docs/examples/web/resources/shaders/glsl330/base.vs
new file mode 100644
index 00000000..638cb8ae
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl330/base.vs
@@ -0,0 +1,26 @@
+#version 330
+
+// Input vertex attributes
+in vec3 vertexPosition;
+in vec2 vertexTexCoord;
+in vec3 vertexNormal;
+in vec4 vertexColor;
+
+// 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/docs/examples/web/resources/shaders/glsl330/bloom.fs b/docs/examples/web/resources/shaders/glsl330/bloom.fs
new file mode 100644
index 00000000..0307bc06
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl330/bloom.fs
@@ -0,0 +1,38 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in 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 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;
+ }
+ }
+
+ // 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;
+
+ finalColor = tc;
+} \ No newline at end of file
diff --git a/docs/examples/web/resources/shaders/glsl330/depth.fs b/docs/examples/web/resources/shaders/glsl330/depth.fs
new file mode 100644
index 00000000..06d399f9
--- /dev/null
+++ b/docs/examples/web/resources/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/docs/examples/web/resources/shaders/glsl330/distortion.fs b/docs/examples/web/resources/shaders/glsl330/distortion.fs
new file mode 100644
index 00000000..cb4be8fc
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl330/distortion.fs
@@ -0,0 +1,56 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+
+// Input uniform values
+uniform sampler2D texture0;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Default parameters for Oculus Rift DK2 device
+const vec2 LeftLensCenter = vec2(0.2863248, 0.5);
+const vec2 RightLensCenter = vec2(0.7136753, 0.5);
+const vec2 LeftScreenCenter = vec2(0.25, 0.5);
+const vec2 RightScreenCenter = vec2(0.75, 0.5);
+const vec2 Scale = vec2(0.25, 0.45);
+const vec2 ScaleIn = vec2(4.0, 2.5);
+const vec4 HmdWarpParam = vec4(1.0, 0.22, 0.24, 0.0);
+const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
+
+void main()
+{
+ // The following two variables need to be set per eye
+ vec2 LensCenter = fragTexCoord.x < 0.5 ? LeftLensCenter : RightLensCenter;
+ vec2 ScreenCenter = fragTexCoord.x < 0.5 ? LeftScreenCenter : RightScreenCenter;
+
+ // Scales input texture coordinates for distortion: vec2 HmdWarp(vec2 fragTexCoord, vec2 LensCenter)
+ vec2 theta = (fragTexCoord - LensCenter)*ScaleIn; // Scales to [-1, 1]
+ float rSq = theta.x*theta.x + theta.y*theta.y;
+ vec2 theta1 = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
+ //vec2 tc = LensCenter + Scale*theta1;
+
+ // Detect whether blue texture coordinates are out of range since these will scaled out the furthest
+ vec2 thetaBlue = theta1*(ChromaAbParam.z + ChromaAbParam.w*rSq);
+ vec2 tcBlue = LensCenter + Scale*thetaBlue;
+
+ if (any(bvec2(clamp(tcBlue, ScreenCenter - vec2(0.25, 0.5), ScreenCenter + vec2(0.25, 0.5)) - tcBlue))) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
+ else
+ {
+ // Do blue texture lookup
+ float blue = texture(texture0, tcBlue).b;
+
+ // Do green lookup (no scaling)
+ vec2 tcGreen = LensCenter + Scale*theta1;
+ float green = texture(texture0, tcGreen).g;
+
+ // Do red scale and lookup
+ vec2 thetaRed = theta1*(ChromaAbParam.x + ChromaAbParam.y*rSq);
+ vec2 tcRed = LensCenter + Scale*thetaRed;
+ float red = texture(texture0, tcRed).r;
+
+ finalColor = vec4(red, green, blue, 1.0);
+ }
+}
+
diff --git a/docs/examples/web/resources/shaders/glsl330/grayscale.fs b/docs/examples/web/resources/shaders/glsl330/grayscale.fs
new file mode 100644
index 00000000..5b3e11be
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl330/grayscale.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()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor;
+
+ // Convert texel color to grayscale using NTSC conversion weights
+ float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
+
+ // Calculate final fragment color
+ finalColor = vec4(gray, gray, gray, texelColor.a);
+} \ No newline at end of file
diff --git a/docs/examples/web/resources/shaders/glsl330/swirl.fs b/docs/examples/web/resources/shaders/glsl330/swirl.fs
new file mode 100644
index 00000000..788ffeec
--- /dev/null
+++ b/docs/examples/web/resources/shaders/glsl330/swirl.fs
@@ -0,0 +1,46 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in 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 = 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()
+{
+ 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;
+ vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
+
+ finalColor = vec4(color.rgb, 1.0);;
+} \ No newline at end of file