aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-06-21 13:45:35 +0200
committerraysan5 <raysan5@gmail.com>2016-06-21 13:45:35 +0200
commite913de58c73ff82fbcd8f23b8cb1fd1a88664164 (patch)
tree67c158d76411d002471fbb8f7f4d10ad13e777aa /examples
parentafe033412b4d8bffc9235a49dc8049eb74af59f3 (diff)
downloadraylib-e913de58c73ff82fbcd8f23b8cb1fd1a88664164.tar.gz
raylib-e913de58c73ff82fbcd8f23b8cb1fd1a88664164.zip
Added distortion shader for testing
Diffstat (limited to 'examples')
-rw-r--r--examples/resources/shaders/base.vs26
-rw-r--r--examples/resources/shaders/distortion.fs59
2 files changed, 85 insertions, 0 deletions
diff --git a/examples/resources/shaders/base.vs b/examples/resources/shaders/base.vs
new file mode 100644
index 00000000..638cb8ae
--- /dev/null
+++ b/examples/resources/shaders/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/examples/resources/shaders/distortion.fs b/examples/resources/shaders/distortion.fs
new file mode 100644
index 00000000..cd5951fe
--- /dev/null
+++ b/examples/resources/shaders/distortion.fs
@@ -0,0 +1,59 @@
+#version 330
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+
+// Input uniform values
+uniform sampler2D texture0;
+
+// Output fragment color
+out vec4 finalColor;
+
+// NOTE: Add here your custom variables
+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); //vec2(0.1469278, 0.2350845);
+const vec2 ScaleIn = vec2(4, 2.2222);
+const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0);
+
+/*
+// Another set of default values
+ChromaAbCorrection = {1.0, 0.0, 1.0, 0}
+DistortionK = {1.0, 0.22, 0.24, 0}
+Scale = {0.25, 0.5*AspectRatio, 0, 0}
+ScaleIn = {4.0, 2/AspectRatio, 0, 0}
+Left Screen Center = {0.25, 0.5, 0, 0}
+Left Lens Center = {0.287994117, 0.5, 0, 0}
+Right Screen Center = {0.75, 0.5, 0, 0}
+Right Lens Center = {0.712005913, 0.5, 0, 0}
+*/
+
+// Scales input texture coordinates for distortion.
+vec2 HmdWarp(vec2 in01, vec2 LensCenter)
+{
+ vec2 theta = (in01 - LensCenter)*ScaleIn; // Scales to [-1, 1]
+ float rSq = theta.x*theta.x + theta.y*theta.y;
+ vec2 rvector = theta*(HmdWarpParam.x + HmdWarpParam.y*rSq + HmdWarpParam.z*rSq*rSq + HmdWarpParam.w*rSq*rSq*rSq);
+
+ return LensCenter + Scale*rvector;
+}
+
+void main()
+{
+ // SOURCE: http://www.mtbs3d.com/phpbb/viewtopic.php?f=140&t=17081
+
+ // The following two variables need to be set per eye
+ vec2 LensCenter = gl_FragCoord.x < 540 ? LeftLensCenter : RightLensCenter;
+ vec2 ScreenCenter = gl_FragCoord.x < 540 ? LeftScreenCenter : RightScreenCenter;
+
+ vec2 tc = HmdWarp(fragTexCoord, LensCenter);
+
+ if (any(bvec2(clamp(tc,ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)) - tc))) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
+ else
+ {
+ //tc.x = gl_FragCoord.x < 640 ? (2.0 * tc.x) : (2.0 * (tc.x - 0.5));
+ finalColor = texture2D(texture0, tc);
+ }
+}