lygia
/lighting
/light
/directional
)Calculate directional light
Dependencies:
Use:
lightDirectional(<vec3> _diffuseColor, <vec3> _specularColor, <vec3> _N, <vec3> _V, <float> _NoV, <float> _f0, out <vec3> _diffuse, out <vec3> _specular)
#ifdef RAYMARCH_SHADOWS
#endif
#ifndef STR_LIGHT_DIRECTIONAL
#define STR_LIGHT_DIRECTIONAL
struct LightDirectional {
vec3 direction;
vec3 color;
float intensity;
};
#endif
#ifndef FNC_LIGHT_DIRECTIONAL
#define FNC_LIGHT_DIRECTIONAL
void lightDirectional(
const in vec3 _diffuseColor, const in vec3 _specularColor,
const in vec3 _V,
const in vec3 _Ld, const in vec3 _Lc, const in float _Li,
const in vec3 _P, const in vec3 _N, const in float _NoV, const in float _NoL,
const in float _roughness, const in float _f0,
inout vec3 _diffuse, inout vec3 _specular) {
float intensity = _Li;
#ifdef RAYMARCH_SHADOWS
intensity = raymarchSoftShadow(_P, _Ld);
#endif
float dif = diffuse(_Ld, _N, _V, _NoV, _NoL, _roughness);
float spec = specular(_Ld, _N, _V, _NoV, _NoL, _roughness, _f0);
_diffuse += max(vec3(0.0), intensity * (_diffuseColor * _Lc * dif) * _NoL);
_specular += max(vec3(0.0), intensity * (_specularColor * _Lc * spec) * _NoL);
}
#ifdef STR_MATERIAL
void lightDirectional(
const in vec3 _diffuseColor, const in vec3 _specularColor,
LightDirectional _L, const in Material _mat,
inout vec3 _diffuse, inout vec3 _specular) {
float f0 = max(_mat.f0.r, max(_mat.f0.g, _mat.f0.b));
float NoL = dot(_mat.normal, _L.direction);
lightDirectional(
_diffuseColor, _specularColor,
_mat.V,
_L.direction, _L.color, _L.intensity,
_mat.position, _mat.normal, _mat.NoV, NoL, _mat.roughness, f0,
_diffuse, _specular);
#ifdef SHADING_MODEL_SUBSURFACE
vec3 h = normalize(_mat.V + _L.direction);
float NoH = saturate(dot(_mat.normal, h));
float LoH = saturate(dot(_L.direction, h));
float scatterVoH = saturate(dot(_mat.V, -_L.direction));
float forwardScatter = exp2(scatterVoH * _mat.subsurfacePower - _mat.subsurfacePower);
float backScatter = saturate(NoL * _mat.subsurfaceThickness + (1.0 - _mat.subsurfaceThickness)) * 0.5;
float subsurface = mix(backScatter, 1.0, forwardScatter) * (1.0 - _mat.subsurfaceThickness);
_diffuse += _mat.subsurfaceColor * (subsurface * diffuseLambert());
#endif
}
#endif
#endif
Dependencies:
Use:
lightDirectional(<float3> _diffuseColor, <float3> _specularColor, <float3> _N, <float3> _V, <float> _NoV, <float> _f0, out <float3> _diffuse, out <float3> _specular)
#ifdef RAYMARCH_SHADOWS
#endif
#ifndef STR_LIGHT_DIRECTIONAL
#define STR_LIGHT_DIRECTIONAL
struct LightDirectional
{
float3 direction;
float3 color;
float intensity;
};
#endif
#ifndef FNC_LIGHT_DIRECTIONAL
#define FNC_LIGHT_DIRECTIONAL
void lightDirectional(
const in float3 _diffuseColor, const in float3 _specularColor,
const in float3 _V,
const in float3 _Ld, const in float3 _Lc, const in float _Li,
const in float3 _P, const in float3 _N, const in float _NoV, const in float _NoL,
const in float _roughness, const in float _f0,
inout float3 _diffuse, inout float3 _specular) {
float intensity = _Li;
#ifdef RAYMARCH_SHADOWS
intensity = raymarchSoftShadow(_P, _Ld);
#endif
float dif = diffuse(_Ld, _N, _V, _NoV, _NoL, _roughness);
float spec = specular(_Ld, _N, _V, _NoV, _NoL, _roughness, _f0);
_diffuse += max(float3(0.0, 0.0, 0.0), intensity * (_diffuseColor * _Lc * dif) * _NoL);
_specular += max(float3(0.0, 0.0, 0.0), intensity * (_specularColor * _Lc * spec) * _NoL);
}
#ifdef STR_MATERIAL
void lightDirectional(
const in float3 _diffuseColor, const in float3 _specularColor,
LightDirectional _L, const in Material _mat,
inout float3 _diffuse, inout float3 _specular) {
float f0 = max(_mat.f0.r, max(_mat.f0.g, _mat.f0.b));
float NoL = dot(_mat.normal, _L.direction);
lightDirectional(
_diffuseColor, _specularColor,
_mat.V,
_L.direction, _L.color, _L.intensity,
_mat.position, _mat.normal, _mat.NoV, NoL, _mat.roughness, f0,
_diffuse, _specular);
#ifdef SHADING_MODEL_SUBSURFACE
float3 h = normalize(_mat.V + _L.direction);
float NoH = saturate(dot(_mat.normal, h));
float LoH = saturate(dot(_L.direction, h));
float scatterVoH = saturate(dot(_mat.V, -_L.direction));
float forwardScatter = exp2(scatterVoH * _mat.subsurfacePower - _mat.subsurfacePower);
float backScatter = saturate(NoL * _mat.subsurfaceThickness + (1.0 - _mat.subsurfaceThickness)) * 0.5;
float subsurface = lerp(backScatter, 1.0, forwardScatter) * (1.0 - _mat.subsurfaceThickness);
_diffuse += _mat.subsurfaceColor * (subsurface * diffuseLambert());
#endif
}
#endif
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository