aboutsummaryrefslogtreecommitdiff
path: root/examples/resources
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2016-07-15 19:44:18 +0200
committerGitHub <noreply@github.com>2016-07-15 19:44:18 +0200
commita2794379a0e1e2ab1486888aaa710f65d492e0fc (patch)
treeacd8185cf8574ccba8fab46ccdbca30f9a3cd895 /examples/resources
parent1c98e6b698b8002e0c6c769c6d9f23a6e15f3bdf (diff)
parentfc19e24eba4358b3afb052f80425af4947b172d6 (diff)
downloadraylib-a2794379a0e1e2ab1486888aaa710f65d492e0fc.tar.gz
raylib-a2794379a0e1e2ab1486888aaa710f65d492e0fc.zip
Merge pull request #132 from raysan5/develop
Develop branch integration
Diffstat (limited to 'examples/resources')
-rw-r--r--examples/resources/shaders/glsl100/bloom.fs2
-rw-r--r--examples/resources/shaders/glsl100/distortion.fs54
-rw-r--r--examples/resources/shaders/glsl100/grayscale.fs4
-rw-r--r--examples/resources/shaders/glsl100/swirl.fs8
-rw-r--r--examples/resources/shaders/glsl330/distortion.fs56
-rw-r--r--examples/resources/shaders/glsl330/swirl.fs6
-rw-r--r--examples/resources/shaders/standard.fs155
-rw-r--r--examples/resources/shaders/standard.vs23
8 files changed, 120 insertions, 188 deletions
diff --git a/examples/resources/shaders/glsl100/bloom.fs b/examples/resources/shaders/glsl100/bloom.fs
index 280d2fb6..128736f2 100644
--- a/examples/resources/shaders/glsl100/bloom.fs
+++ b/examples/resources/shaders/glsl100/bloom.fs
@@ -26,7 +26,7 @@ void main()
}
// Texel color fetching from texture sampler
- vec4 texelColor = texture(texture0, fragTexCoord);
+ vec4 texelColor = texture2D(texture0, fragTexCoord);
// Calculate final fragment color
if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor;
diff --git a/examples/resources/shaders/glsl100/distortion.fs b/examples/resources/shaders/glsl100/distortion.fs
new file mode 100644
index 00000000..50116ce0
--- /dev/null
+++ b/examples/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/examples/resources/shaders/glsl100/grayscale.fs b/examples/resources/shaders/glsl100/grayscale.fs
index f92ec335..15174ea5 100644
--- a/examples/resources/shaders/glsl100/grayscale.fs
+++ b/examples/resources/shaders/glsl100/grayscale.fs
@@ -8,14 +8,14 @@ varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
-uniform vec4 fragTintColor;
+uniform vec4 colDiffuse;
// NOTE: Add here your custom variables
void main()
{
// Texel color fetching from texture sampler
- vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor;
+ 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));
diff --git a/examples/resources/shaders/glsl100/swirl.fs b/examples/resources/shaders/glsl100/swirl.fs
index 0d6d24f2..ca7668b2 100644
--- a/examples/resources/shaders/glsl100/swirl.fs
+++ b/examples/resources/shaders/glsl100/swirl.fs
@@ -8,7 +8,7 @@ varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
-uniform vec4 fragTintColor;
+uniform vec4 colDiffuse;
// NOTE: Add here your custom variables
@@ -18,7 +18,7 @@ const float renderHeight = 480.0; // Use uniforms instead...
float radius = 250.0;
float angle = 0.8;
-uniform vec2 center = vec2(200.0, 200.0);
+uniform vec2 center;
void main()
{
@@ -39,7 +39,7 @@ void main()
}
tc += center;
- vec3 color = texture2D(texture0, tc/texSize).rgb;
+ vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
- gl_FragColor = vec4(color, 1.0);;
+ gl_FragColor = vec4(color.rgb, 1.0);;
} \ No newline at end of file
diff --git a/examples/resources/shaders/glsl330/distortion.fs b/examples/resources/shaders/glsl330/distortion.fs
new file mode 100644
index 00000000..cb4be8fc
--- /dev/null
+++ b/examples/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/examples/resources/shaders/glsl330/swirl.fs b/examples/resources/shaders/glsl330/swirl.fs
index 80c16cc9..5d238ac9 100644
--- a/examples/resources/shaders/glsl330/swirl.fs
+++ b/examples/resources/shaders/glsl330/swirl.fs
@@ -6,7 +6,7 @@ in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
-uniform vec4 fragTintColor;
+uniform vec4 colDiffuse;
// Output fragment color
out vec4 finalColor;
@@ -40,7 +40,7 @@ void main()
}
tc += center;
- vec3 color = texture(texture0, tc/texSize).rgb;
+ vec4 color = texture2D(texture0, tc/texSize)*colDiffuse*fragColor;;
- finalColor = vec4(color, 1.0);;
+ finalColor = vec4(color.rgb, 1.0);;
} \ No newline at end of file
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