summaryrefslogtreecommitdiffhomepage
path: root/examples/shaders/resources
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-03-24 19:49:09 +0100
committerraysan5 <[email protected]>2020-03-24 19:49:09 +0100
commit5e670be2392b5bdff2db09a65899a978cdb175d4 (patch)
tree84b30d9546194b66b74988325e6ed046371268dc /examples/shaders/resources
parent05abaee0e092bb2367283e0771a5b628ed9b2282 (diff)
downloadraylib-5e670be2392b5bdff2db09a65899a978cdb175d4.tar.gz
raylib-5e670be2392b5bdff2db09a65899a978cdb175d4.zip
REVIEWED: shaders_spotlight example
It seems something is not working properly...
Diffstat (limited to 'examples/shaders/resources')
-rw-r--r--examples/shaders/resources/shaders/glsl330/spotlight.fs50
1 files changed, 23 insertions, 27 deletions
diff --git a/examples/shaders/resources/shaders/glsl330/spotlight.fs b/examples/shaders/resources/shaders/glsl330/spotlight.fs
index f97722c6..f20d92a8 100644
--- a/examples/shaders/resources/shaders/glsl330/spotlight.fs
+++ b/examples/shaders/resources/shaders/glsl330/spotlight.fs
@@ -1,27 +1,29 @@
#version 330
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
// Output fragment color
out vec4 finalColor;
-#define MAX_SPOTS 4
-#define RADIUS 256
-#define INNER 200
+// NOTE: Add here your custom variables
-// Inputs
-// array of spotlight positions
-uniform vec2 spots[MAX_SPOTS];
+#define MAX_SPOTS 2
+#define RADIUS 128
+#define INNER 96
-uniform float screenWidth; // width of the screen
+uniform vec2 spots[MAX_SPOTS]; // Spotlight positions array
+uniform float screenWidth; // Width of the screen
void main()
{
-
- float alpha;
- // get the position of the current fragment (screen coordinates!)
+ float alpha = 0.0;
+
+ // Get the position of the current fragment (screen coordinates!)
vec2 pos = vec2(gl_FragCoord.x, gl_FragCoord.y);
-
- // find out which spotlight is nearest
+ // Find out which spotlight is nearest
float d = 65000; // some high value
float di = 0;
@@ -32,22 +34,16 @@ void main()
}
// 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);
- }
+ 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;
- }
+ // 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);
+ finalColor = vec4(0, 0, 0, alpha);
}