[example] Review shaders_spotlight to work on GLSL 100
This commit is contained in:
parent
2dbcef218c
commit
74339b9fdc
3 changed files with 44 additions and 45 deletions
|
@ -4,7 +4,6 @@ precision mediump float;
|
|||
|
||||
#define MAX_SPOTS 3
|
||||
|
||||
|
||||
struct Spot {
|
||||
vec2 pos; // window coords of spot
|
||||
float inner; // inner fully transparent centre radius
|
||||
|
@ -16,21 +15,21 @@ uniform float screenWidth; // Width of the screen
|
|||
|
||||
void main()
|
||||
{
|
||||
|
||||
float alpha = 1.0;
|
||||
// get the position of the current fragment (screen coordinates!)
|
||||
|
||||
// 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.0; // some high value
|
||||
int fi = -1;
|
||||
int fi = -1; // found index
|
||||
|
||||
for (int i = 0; i < MAX_SPOTS; i++)
|
||||
{
|
||||
for (int j = 0; j < MAX_SPOTS; j++)
|
||||
{
|
||||
float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius;
|
||||
|
||||
if (d > dj)
|
||||
{
|
||||
d = dj;
|
||||
|
@ -41,23 +40,32 @@ void main()
|
|||
|
||||
// d now equals distance to nearest spot...
|
||||
// allowing for the different radii of all spotlights
|
||||
if (fi != -1) {
|
||||
|
||||
if (d > spots[fi].radius)
|
||||
if (fi == 0)
|
||||
{
|
||||
alpha = 1.0;
|
||||
}
|
||||
if (d > spots[0].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[fi].inner)
|
||||
{
|
||||
alpha = 0.0;
|
||||
if (d < spots[0].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[0].inner)/(spots[0].radius - spots[0].inner);
|
||||
}
|
||||
}
|
||||
else if (fi == 1)
|
||||
{
|
||||
if (d > spots[1].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
alpha = (d - spots[fi].inner) / (spots[fi].radius - spots[fi].inner);
|
||||
if (d < spots[1].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[1].inner)/(spots[1].radius - spots[1].inner);
|
||||
}
|
||||
}
|
||||
else if (fi == 2)
|
||||
{
|
||||
if (d > spots[2].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[2].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[2].inner)/(spots[2].radius - spots[2].inner);
|
||||
}
|
||||
}
|
||||
|
||||
// Right hand side of screen is dimly lit,
|
||||
|
|
|
@ -25,7 +25,6 @@ void main()
|
|||
float alpha = 1.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
|
||||
|
@ -37,6 +36,7 @@ void main()
|
|||
for (int j = 0; j < MAX_SPOTS; j++)
|
||||
{
|
||||
float dj = distance(pos, spots[j].pos) - spots[j].radius + spots[i].radius;
|
||||
|
||||
if (d > dj)
|
||||
{
|
||||
d = dj;
|
||||
|
@ -47,22 +47,13 @@ void main()
|
|||
|
||||
// d now equals distance to nearest spot...
|
||||
// allowing for the different radii of all spotlights
|
||||
if (fi != -1) {
|
||||
|
||||
if (d > spots[fi].radius)
|
||||
if (fi != -1)
|
||||
{
|
||||
alpha = 1.0;
|
||||
}
|
||||
if (d > spots[fi].radius) alpha = 1.0;
|
||||
else
|
||||
{
|
||||
if (d < spots[fi].inner)
|
||||
{
|
||||
alpha = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
alpha = (d - spots[fi].inner) / (spots[fi].radius - spots[fi].inner);
|
||||
}
|
||||
if (d < spots[fi].inner) alpha = 0.0;
|
||||
else alpha = (d - spots[fi].inner) / (spots[fi].radius - spots[fi].inner);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
BIN
examples/shaders/shaders_spotlight.png
Normal file
BIN
examples/shaders/shaders_spotlight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 118 KiB |
Loading…
Add table
Add a link
Reference in a new issue