summaryrefslogtreecommitdiffhomepage
path: root/examples/resources
diff options
context:
space:
mode:
authorvictorfisac <[email protected]>2016-07-05 11:57:05 +0200
committervictorfisac <[email protected]>2016-07-05 11:57:05 +0200
commit1aecd5be072083e27e4289499865b5681f1ea656 (patch)
tree808159aa95df9b2be5509d83791aa6cad4ddf6b8 /examples/resources
parent1b0996fb0bcf68e2a14bc6260c6f2c5366ab033f (diff)
parent2ff2096b36d80078cbda5e61ff77d7fedeeeaeb5 (diff)
downloadraylib-1aecd5be072083e27e4289499865b5681f1ea656.tar.gz
raylib-1aecd5be072083e27e4289499865b5681f1ea656.zip
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'examples/resources')
-rw-r--r--examples/resources/shaders/glsl100/distortion.fs66
-rw-r--r--examples/resources/shaders/glsl330/distortion.fs69
-rw-r--r--examples/resources/shaders/standard.fs155
-rw-r--r--examples/resources/shaders/standard.vs23
4 files changed, 135 insertions, 178 deletions
diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs
new file mode 100644
index 00000000..a0a6cc18
--- /dev/null
+++ b/examples/resources/shaders/glsl100/distortion.fs
@@ -0,0 +1,66 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+
+// Input uniform values
+uniform sampler2D texture0;
+
+// 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);
+const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.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}
+*/
+
+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/examples/resources/shaders/glsl330/distortion.fs b/examples/resources/shaders/glsl330/distortion.fs
new file mode 100644
index 00000000..62856341
--- /dev/null
+++ b/examples/resources/shaders/glsl330/distortion.fs
@@ -0,0 +1,69 @@
+#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.288, 0.5);
+const vec2 RightLensCenter = vec2(0.712, 0.5);
+const vec2 LeftScreenCenter = vec2(0.25, 0.5);
+const vec2 RightScreenCenter = vec2(0.75, 0.5);
+uniform vec2 Scale = vec2(0.25, 0.45); //vec2(0.1469278, 0.2350845);
+uniform vec2 ScaleIn = vec2(4, 2.2222);
+
+const vec4 HmdWarpParam = vec4(1, 0.22, 0.24, 0);
+const vec4 ChromaAbParam = vec4(0.996, -0.004, 1.014, 0.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}
+*/
+
+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/examples/resources/shaders/standard.fs b/examples/resources/shaders/standard.fs
deleted file mode 100644
index e5a6d1bc..00000000
--- a/examples/resources/shaders/standard.fs
+++ /dev/null
@@ -1,155 +0,0 @@
-#version 330
-
-in vec3 fragPosition;
-in vec2 fragTexCoord;
-in vec4 fragColor;
-in vec3 fragNormal;
-
-out vec4 finalColor;
-
-uniform sampler2D texture0;
-uniform sampler2D texture1;
-uniform sampler2D texture2;
-
-uniform vec4 colAmbient;
-uniform vec4 colDiffuse;
-uniform vec4 colSpecular;
-uniform float glossiness;
-
-uniform int useNormal;
-uniform int useSpecular;
-
-uniform mat4 modelMatrix;
-uniform vec3 viewDir;
-
-struct Light {
- int enabled;
- int type;
- vec3 position;
- vec3 direction;
- vec4 diffuse;
- float intensity;
- float radius;
- float coneAngle;
-};
-
-const int maxLights = 8;
-uniform int lightsCount;
-uniform Light lights[maxLights];
-
-vec3 CalcPointLight(Light l, vec3 n, vec3 v, float s)
-{
- vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
- vec3 surfaceToLight = l.position - surfacePos;
-
- // Diffuse shading
- float brightness = clamp(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n)), 0, 1);
- float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity;
-
- // Specular shading
- float spec = 0.0;
- if (diff > 0.0)
- {
- vec3 h = normalize(-l.direction + v);
- spec = pow(dot(n, h), 3 + glossiness)*s;
- }
-
- return (diff*l.diffuse.rgb + spec*colSpecular.rgb);
-}
-
-vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v, float s)
-{
- vec3 lightDir = normalize(-l.direction);
-
- // Diffuse shading
- float diff = clamp(dot(n, lightDir), 0.0, 1.0)*l.intensity;
-
- // Specular shading
- float spec = 0.0;
- if (diff > 0.0)
- {
- vec3 h = normalize(lightDir + v);
- spec = pow(dot(n, h), 3 + glossiness)*s;
- }
-
- // Combine results
- return (diff*l.intensity*l.diffuse.rgb + spec*colSpecular.rgb);
-}
-
-vec3 CalcSpotLight(Light l, vec3 n, vec3 v, float s)
-{
- vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
- vec3 lightToSurface = normalize(surfacePos - l.position);
- vec3 lightDir = normalize(-l.direction);
-
- // Diffuse shading
- float diff = clamp(dot(n, lightDir), 0.0, 1.0)*l.intensity;
-
- // Spot attenuation
- float attenuation = clamp(dot(n, lightToSurface), 0.0, 1.0);
- attenuation = dot(lightToSurface, -lightDir);
-
- float lightToSurfaceAngle = degrees(acos(attenuation));
- if (lightToSurfaceAngle > l.coneAngle) attenuation = 0.0;
-
- float falloff = (l.coneAngle - lightToSurfaceAngle)/l.coneAngle;
-
- // Combine diffuse and attenuation
- float diffAttenuation = diff*attenuation;
-
- // Specular shading
- float spec = 0.0;
- if (diffAttenuation > 0.0)
- {
- vec3 h = normalize(lightDir + v);
- spec = pow(dot(n, h), 3 + glossiness)*s;
- }
-
- return (falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb));
-}
-
-void main()
-{
- // Calculate fragment normal in screen space
- // NOTE: important to multiply model matrix by fragment normal to apply model transformation (rotation and scale)
- mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
- vec3 normal = normalize(normalMatrix*fragNormal);
-
- // Normalize normal and view direction vectors
- vec3 n = normalize(normal);
- vec3 v = normalize(viewDir);
-
- // Calculate diffuse texture color fetching
- vec4 texelColor = texture(texture0, fragTexCoord);
- vec3 lighting = colAmbient.rgb;
-
- // Calculate normal texture color fetching or set to maximum normal value by default
- if (useNormal == 1)
- {
- n *= texture(texture1, fragTexCoord).rgb;
- n = normalize(n);
- }
-
- // Calculate specular texture color fetching or set to maximum specular value by default
- float spec = 1.0;
- if (useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r);
-
- for (int i = 0; i < lightsCount; i++)
- {
- // Check if light is enabled
- if (lights[i].enabled == 1)
- {
- // Calculate lighting based on light type
- switch (lights[i].type)
- {
- case 0: lighting += CalcPointLight(lights[i], n, v, spec); break;
- case 1: lighting += CalcDirectionalLight(lights[i], n, v, spec); break;
- case 2: lighting += CalcSpotLight(lights[i], n, v, spec); break;
- default: break;
- }
- }
- }
-
- // Calculate final fragment color
- finalColor = vec4(texelColor.rgb*lighting*colDiffuse.rgb, texelColor.a*colDiffuse.a);
-}
diff --git a/examples/resources/shaders/standard.vs b/examples/resources/shaders/standard.vs
deleted file mode 100644
index fc0a5ff4..00000000
--- a/examples/resources/shaders/standard.vs
+++ /dev/null
@@ -1,23 +0,0 @@
-#version 330
-
-in vec3 vertexPosition;
-in vec3 vertexNormal;
-in vec2 vertexTexCoord;
-in vec4 vertexColor;
-
-out vec3 fragPosition;
-out vec2 fragTexCoord;
-out vec4 fragColor;
-out vec3 fragNormal;
-
-uniform mat4 mvpMatrix;
-
-void main()
-{
- fragPosition = vertexPosition;
- fragTexCoord = vertexTexCoord;
- fragColor = vertexColor;
- fragNormal = vertexNormal;
-
- gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
-} \ No newline at end of file