split shader and make use of more inbuilt functions
parent
a1fb917e15
commit
903888e615
@ -0,0 +1,9 @@
|
|||||||
|
#include "sh_Flashlight.h"
|
||||||
|
|
||||||
|
vec4 getColourAt(vec2 diff, vec2 size, vec4 originalColour)
|
||||||
|
{
|
||||||
|
float dist = length(diff);
|
||||||
|
float flashlightRadius = length(size);
|
||||||
|
|
||||||
|
return vec4(originalColour.xyz, smoothstep(flashlightRadius, flashlightRadius * smoothness, dist));
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
#ifdef GL_ES
|
|
||||||
precision mediump float;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
varying vec2 v_Position;
|
|
||||||
varying vec4 v_Colour;
|
|
||||||
|
|
||||||
uniform bool rectangular;
|
|
||||||
uniform vec2 flashlightPos;
|
|
||||||
uniform float circularFlashlightSize;
|
|
||||||
uniform vec2 rectangularFlashlightSize;
|
|
||||||
|
|
||||||
const float smoothness = 1.1;
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
if(rectangular)
|
|
||||||
{
|
|
||||||
vec2 diff = abs(v_Position - flashlightPos);
|
|
||||||
|
|
||||||
float alpha = 1.0 - smoothstep(rectangularFlashlightSize.x, rectangularFlashlightSize.x * smoothness, diff.x);
|
|
||||||
alpha *= 1.0 - smoothstep(rectangularFlashlightSize.y, rectangularFlashlightSize.y * smoothness, diff.y);
|
|
||||||
|
|
||||||
gl_FragColor = v_Colour * vec4(1.0, 1.0, 1.0, 1.0 - alpha);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vec2 diff = flashlightPos - v_Position;
|
|
||||||
|
|
||||||
float dist = sqrt(diff.x * diff.x + diff.y * diff.y);
|
|
||||||
|
|
||||||
gl_FragColor = v_Colour * vec4(1.0, 1.0, 1.0, smoothstep(circularFlashlightSize, circularFlashlightSize * smoothness, dist));
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,10 @@
|
|||||||
|
#include "sh_Flashlight.h"
|
||||||
|
|
||||||
|
vec4 getColourAt(vec2 diff, vec2 size, vec4 originalColour)
|
||||||
|
{
|
||||||
|
diff = abs(diff);
|
||||||
|
|
||||||
|
float alpha = length(smoothstep(size, size * smoothness, diff));
|
||||||
|
|
||||||
|
return vec4(originalColour.xyz, alpha);
|
||||||
|
}
|
Loading…
Reference in New Issue