SHOW:
|
|
- or go back to the newest paste.
| 1 | struct BaseLight | |
| 2 | {
| |
| 3 | vec3 color; | |
| 4 | float intensity; | |
| 5 | }; | |
| 6 | ||
| 7 | struct Attenuation{
| |
| 8 | float constant; | |
| 9 | float linear; | |
| 10 | float exponent; | |
| 11 | }; | |
| 12 | ||
| 13 | struct PointLight{
| |
| 14 | BaseLight base; | |
| 15 | Attenuation atten; | |
| 16 | vec3 pos; | |
| 17 | float range; | |
| 18 | }; | |
| 19 | ||
| 20 | struct SpotLight{
| |
| 21 | PointLight point; | |
| 22 | vec3 direction; | |
| 23 | float cutoff; | |
| 24 | }; | |
| 25 | ||
| 26 | ||
| 27 | vec4 calcSpotLight(SpotLight spotLight, vec3 normal){
| |
| 28 | vec3 lightDirection = normalize(worldPos0 - spotLight.point.pos); | |
| 29 | float spotFactor = dot(lightDirection, spotLight.direction); | |
| 30 | ||
| 31 | vec4 color = vec4(0,0,0,0); | |
| 32 | ||
| 33 | if (spotFactor > spotLight.cutoff){
| |
| 34 | color = calcPointLight(spotLight.point, normal) * | |
| 35 | (1.0 - ((1.0 - spotFactor)/(1.0 - spotLight.cutoff))); | |
| 36 | } | |
| 37 | ||
| 38 | return color; | |
| 39 | ||
| 40 | } |