summaryrefslogtreecommitdiffhomepage
path: root/examples/shaders/resources
diff options
context:
space:
mode:
authorchriscamacho <[email protected]>2020-03-24 13:27:14 +0000
committerGitHub <[email protected]>2020-03-24 14:27:14 +0100
commitefe359d61303b2148199c009abab34e44b0ab04f (patch)
tree9d0b1e0ed67617f65cc5ce99db178c9232bfe5f4 /examples/shaders/resources
parentc45fe62abcf7d710678f7f4bc25dc9b1bfdc8ea2 (diff)
downloadraylib-efe359d61303b2148199c009abab34e44b0ab04f.tar.gz
raylib-efe359d61303b2148199c009abab34e44b0ab04f.zip
as per request spotlight example (#1146)
Co-authored-by: codifies <[email protected]>
Diffstat (limited to 'examples/shaders/resources')
-rw-r--r--examples/shaders/resources/raysan.pngbin0 -> 15064 bytes
-rw-r--r--examples/shaders/resources/shaders/glsl100/spotlight.fs52
-rw-r--r--examples/shaders/resources/shaders/glsl330/spotlight.fs53
3 files changed, 105 insertions, 0 deletions
diff --git a/examples/shaders/resources/raysan.png b/examples/shaders/resources/raysan.png
new file mode 100644
index 00000000..3d4e70fe
--- /dev/null
+++ b/examples/shaders/resources/raysan.png
Binary files differ
diff --git a/examples/shaders/resources/shaders/glsl100/spotlight.fs b/examples/shaders/resources/shaders/glsl100/spotlight.fs
new file mode 100644
index 00000000..204b89a7
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/spotlight.fs
@@ -0,0 +1,52 @@
+#version 100
+
+precision mediump float;
+
+#define MAX_SPOTS 4
+#define RADIUS 256.0
+#define INNER 200.0
+
+// Inputs
+// array of spotlight positions
+uniform vec2 spots[MAX_SPOTS];
+
+uniform float screenWidth; // width of the screen
+
+void main()
+{
+
+ float alpha;
+ // get the position of the current fragment (screen coordinates!)
+ vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
+
+
+ // find out which spotlight is nearest
+ float d = 65000.0; // some high value
+ float di = 0.0;
+
+ for (int i = 0; i < MAX_SPOTS; i++)
+ {
+ di = distance(pos, spots[i]);
+ if (d > di) d = di;
+ }
+
+ // d now equals distance to nearest spot...
+ if (d > RADIUS) {
+ alpha = 1.0;
+ } else {
+ if (d < INNER) {
+ alpha = 0.0;
+ } else {
+ alpha = (d - INNER) / (RADIUS - INNER);
+ }
+ }
+
+ // right hand side of screen is dimly lit, could make the
+ // threshold value user definable.
+ if (pos.x > screenWidth/2.0 && alpha > 0.9) {
+ alpha = 0.9;
+ }
+
+ // could make the black out colour user definable...
+ gl_FragColor = vec4( 0, 0, 0, alpha);
+}
diff --git a/examples/shaders/resources/shaders/glsl330/spotlight.fs b/examples/shaders/resources/shaders/glsl330/spotlight.fs
new file mode 100644
index 00000000..f97722c6
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/spotlight.fs
@@ -0,0 +1,53 @@
+#version 330
+
+// Output fragment color
+out vec4 finalColor;
+
+#define MAX_SPOTS 4
+#define RADIUS 256
+#define INNER 200
+
+// Inputs
+// array of spotlight positions
+uniform vec2 spots[MAX_SPOTS];
+
+uniform float screenWidth; // width of the screen
+
+void main()
+{
+
+ float alpha;
+ // get the position of the current fragment (screen coordinates!)
+ vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
+
+
+ // find out which spotlight is nearest
+ float d = 65000; // some high value
+ float di = 0;
+
+ for (int i = 0; i < MAX_SPOTS; i++)
+ {
+ di = distance(pos, spots[i]);
+ if (d > di) d = di;
+ }
+
+ // d now equals distance to nearest spot...
+ if (d > RADIUS) {
+ alpha = 1.0;
+ } else {
+ if (d < INNER) {
+ alpha = 0.0;
+ } else {
+ alpha = (d - INNER) / (RADIUS - INNER);
+ }
+ }
+
+ // right hand side of screen is dimly lit, could make the
+ // threshold value user definable.
+ if (pos.x>screenWidth/2.0 && alpha >0.9) {
+ alpha = 0.9;
+ }
+
+ // could make the black out colour user definable...
+ finalColor = vec4( 0, 0, 0, alpha);
+}