armory/Shaders/std/light_mobile.glsl

108 lines
2.9 KiB
Plaintext
Raw Normal View History

2018-12-10 17:25:29 +01:00
#ifndef _LIGHT_MOBILE_GLSL_
#define _LIGHT_MOBILE_GLSL_
#include "compiled.inc"
#include "std/brdf.glsl"
#ifdef _ShadowMap
#include "std/shadows.glsl"
#endif
#ifdef _ShadowMap
2018-12-15 19:03:11 +01:00
#ifdef _SinglePoint
#ifdef _Spot
uniform sampler2DShadow shadowMapSpot[1];
uniform mat4 LWVPSpot0;
#else
uniform samplerCubeShadow shadowMapPoint[1];
2018-12-10 17:25:29 +01:00
uniform vec2 lightProj;
2018-12-15 19:03:11 +01:00
#endif
#endif
#ifdef _Clusters
2018-12-15 15:07:30 +01:00
uniform samplerCubeShadow shadowMapPoint[4];
2018-12-15 19:03:11 +01:00
uniform vec2 lightProj;
2018-12-10 17:25:29 +01:00
#ifdef _Spot
2018-12-15 15:07:30 +01:00
uniform sampler2DShadow shadowMapSpot[4];
2018-12-10 17:25:29 +01:00
uniform mat4 LWVPSpot0;
2018-12-10 23:29:04 +01:00
uniform mat4 LWVPSpot1;
uniform mat4 LWVPSpot2;
uniform mat4 LWVPSpot3;
2018-12-10 17:25:29 +01:00
#endif
#endif
2018-12-15 19:03:11 +01:00
#endif
2018-12-10 17:25:29 +01:00
vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, const vec3 lp, const vec3 lightCol,
const vec3 albedo, const float rough, const float spec, const vec3 f0
#ifdef _ShadowMap
2018-12-10 23:29:04 +01:00
, int index, float bias
2018-12-10 17:25:29 +01:00
#endif
#ifdef _Spot
, bool isSpot, float spotA, float spotB, vec3 spotDir
#endif
) {
vec3 ld = lp - p;
vec3 l = normalize(ld);
vec3 h = normalize(v + l);
float dotNH = dot(n, h);
float dotVH = dot(v, h);
float dotNL = dot(n, l);
vec3 direct = albedo * max(dotNL, 0.0) +
specularBRDF(f0, rough, dotNL, dotNH, dotNV, dotVH) * spec;
direct *= lightCol;
direct *= attenuate(distance(p, lp));
#ifdef _Spot
if (isSpot) {
float spotEffect = dot(spotDir, l); // lightDir
// x - cutoff, y - cutoff - exponent
if (spotEffect < spotA) {
direct *= smoothstep(spotB, spotA, spotEffect);
}
#ifdef _ShadowMap
2018-12-15 19:03:11 +01:00
#ifdef _SinglePoint
2018-12-11 23:05:18 +01:00
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
2019-01-09 21:25:09 +01:00
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
2018-12-15 19:03:11 +01:00
#endif
#ifdef _Clusters
if (index == 0) {
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
2019-01-09 21:25:09 +01:00
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias);
2018-12-15 19:03:11 +01:00
}
else if (index == 1) {
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
2019-01-09 21:25:09 +01:00
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias);
2018-12-15 19:03:11 +01:00
}
else if (index == 2) {
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
2019-01-09 21:25:09 +01:00
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias);
2018-12-15 19:03:11 +01:00
}
else if (index == 3) {
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
2019-01-09 21:25:09 +01:00
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias);
2018-12-15 19:03:11 +01:00
}
#endif
2018-12-10 17:25:29 +01:00
#endif
return direct;
}
#endif
#ifdef _ShadowMap
2019-01-09 21:25:09 +01:00
#ifndef _Spot
2018-12-15 19:03:11 +01:00
#ifdef _SinglePoint
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
#endif
#ifdef _Clusters
if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n);
else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n);
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
#endif
2018-12-10 17:25:29 +01:00
#endif
2019-01-09 21:25:09 +01:00
#endif
2018-12-10 17:25:29 +01:00
return direct;
}
#endif