REVIEWED: shaders_spotlight example

It seems something is not working properly...
This commit is contained in:
raysan5 2020-03-24 19:49:09 +01:00
parent 05abaee0e0
commit 5e670be239
2 changed files with 134 additions and 149 deletions

View file

@ -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);
}