diff --git a/libraries/model/src/model/LightIrradiance.shared.slh b/libraries/model/src/model/LightIrradiance.shared.slh new file mode 100644 index 0000000000..5068f71480 --- /dev/null +++ b/libraries/model/src/model/LightIrradiance.shared.slh @@ -0,0 +1,39 @@ +// glsl / C++ compatible source as interface for Light +#ifndef LightIrradiance_Shared_slh +#define LightIrradiance_Shared_slh + +// +// Created by Sam Gateau on 14/9/2016. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#define LightIrradianceConstRef LightIrradiance + +struct LightIrradiance { + vec3 color; + float intensity; + float falloffRadius; + float falloffSpot; + float spare1; + float spare2; +}; + + +vec3 lightIrradiance_getColor(LightIrradianceConstRef li) { return li.color; } +float lightIrradiance_getIntensity(LightIrradianceConstRef li) { return li.intensity; } +vec3 lightIrradiance_getIrradiance(LightIrradianceConstRef li) { return li.color * li.intensity; } +float lightIrradiance_getFalloffRadius(LightIrradianceConstRef li) { return li.falloffRadius; } +float lightIrradiance_getFalloffRadiusSquare(LightIrradianceConstRef li) { return li.falloffRadius * li.falloffRadius; } +float lightIrradiance_getFalloffSpot(LightIrradianceConstRef li) { return li.falloffSpot; } + + +#endif + + +// <@if 1@> +// Trigger Scribe include +// <@endif@> \ No newline at end of file diff --git a/libraries/model/src/model/LightVolume.shared.slh b/libraries/model/src/model/LightVolume.shared.slh new file mode 100644 index 0000000000..1ca32bd90e --- /dev/null +++ b/libraries/model/src/model/LightVolume.shared.slh @@ -0,0 +1,75 @@ +// glsl / C++ compatible source as interface for Light +#ifndef LightVolume_Shared_slh +#define LightVolume_Shared_slh + +// Light.shared.slh +// libraries/model/src/model +// +// Created by Sam Gateau on 14/9/2016. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#define LightVolumeConstRef LightVolume + +struct LightVolume { + vec3 position; + float radius; + vec3 direction; + float spotCos; +}; + +bool lightVolume_isPoint(LightVolumeConstRef lv) { return bool(lv.spotCos < 0.f); } +bool lightVolume_isSpot(LightVolumeConstRef lv) { return bool(lv.spotCos >= 0.f); } + +vec3 lightVolume_getPosition(LightVolumeConstRef lv) { return lv.position; } +float lightVolume_getRadius(LightVolumeConstRef lv) { return lv.radius; } +float lightVolume_getRadiusSquare(LightVolumeConstRef lv) { return lv.radius * lv.radius; } +vec3 lightVolume_getDirection(LightVolumeConstRef lv) { return lv.direction; } // direction is -Z axis + +float lightVolume_getSpotAngleCos(LightVolumeConstRef lv) { return lv.spotCos; } +vec2 lightVolume_getSpotOutsideNormal2(LightVolumeConstRef lv) { return vec2(-sqrt(1.0 - lv.spotCos * lv.spotCos), lv.spotCos); } + + +bool lightVolume_clipFragToLightVolumePoint(LightVolume lv, vec3 fragPos, vec4 fragLightVecLen2) { + fragLightVecLen2 = vec4(lightVolume_getPosition(lv) - fragPos.xyz, 1.0f); + fragLightVecLen2.w = dot(fragLightVecLen2.xyz, fragLightVecLen2.xyz); + + // Kill if too far from the light center + if (fragLightVecLen2.w > lightVolume_getRadiusSquare(lv)) { + return false; + } + return true; +} + +bool lightVolume_clipFragToLightVolumeSpot(LightVolume lv, vec3 fragPos, vec4 fragLightVecLen2, vec4 fragLightDirLen, float cosSpotAngle) { + fragLightVecLen2 = vec4(lightVolume_getPosition(lv) - fragPos.xyz, 1.0f); + fragLightVecLen2.w = dot(fragLightVecLen2.xyz, fragLightVecLen2.xyz); + + // Kill if too far from the light center + if (fragLightVecLen2.w > lightVolume_getRadiusSquare(lv)) { + return false; + } + + // Allright we re valid in the volume + fragLightDirLen.w = length(fragLightVecLen2.xyz); + fragLightDirLen.xyz = fragLightVecLen2.xyz / fragLightDirLen.w; + + // Kill if not in the spot light (ah ah !) + cosSpotAngle = max(-dot(fragLightDirLen.xyz, lightVolume_getDirection(lv)), 0.0); + if (cosSpotAngle < lightVolume_getSpotAngleCos(lv)) { + return false; + } + + return true; +} + +#endif + + +// <@if 1@> +// Trigger Scribe include +// <@endif@> \ No newline at end of file diff --git a/libraries/model/src/model/SphericalHarmonics.shared.slh b/libraries/model/src/model/SphericalHarmonics.shared.slh new file mode 100644 index 0000000000..664c9e52db --- /dev/null +++ b/libraries/model/src/model/SphericalHarmonics.shared.slh @@ -0,0 +1,57 @@ +// glsl / C++ compatible source as interface for Light +#ifndef SphericalHarmonics_Shared_slh +#define SphericalHarmonics_Shared_slh + +// SphericalHarmonics.shared.slh +// libraries/model/src/model +// +// Created by Sam Gateau on 14/9/2016. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#define SphericalHarmonicsConstRef SphericalHarmonics + +struct SphericalHarmonics { + vec4 L00; + vec4 L1m1; + vec4 L10; + vec4 L11; + vec4 L2m2; + vec4 L2m1; + vec4 L20; + vec4 L21; + vec4 L22; +}; + +vec4 sphericalHarmonics_evalSphericalLight(SphericalHarmonicsConstRef sh, vec3 direction) { + + vec3 dir = direction.xyz; + + const float C1 = 0.429043; + const float C2 = 0.511664; + const float C3 = 0.743125; + const float C4 = 0.886227; + const float C5 = 0.247708; + + vec4 value = C1 * sh.L22 * (dir.x * dir.x - dir.y * dir.y) + + C3 * sh.L20 * dir.z * dir.z + + C4 * sh.L00 - C5 * sh.L20 + + 2.0 * C1 * (sh.L2m2 * dir.x * dir.y + + sh.L21 * dir.x * dir.z + + sh.L2m1 * dir.y * dir.z) + + 2.0 * C2 * (sh.L11 * dir.x + + sh.L1m1 * dir.y + + sh.L10 * dir.z); + return value; +} + +#endif + + +// <@if 1@> +// Trigger Scribe include +// <@endif@> End C++ compatible \ No newline at end of file