|
@@ -113,99 +113,3 @@ float calcLightAttenuation( float lightDistance, float cutoffDistance, float dec
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
-#define MAX_LIGHT_PROBES 0
|
|
|
-
|
|
|
-#if MAX_LIGHT_PROBES > 0
|
|
|
-
|
|
|
- struct ProbeLight {
|
|
|
- vec3 position;
|
|
|
- vec3 sh[9];
|
|
|
- };
|
|
|
-
|
|
|
- uniform LightProbes lightProbes[ MAX_LIGHT_PROBES ];
|
|
|
-
|
|
|
- void getLightProbeIncidentLight( const in GeometricContext geometry, out IncidentLight incidentLight ) {
|
|
|
-
|
|
|
- // TODO: loop through all light probes and calculate their contributions
|
|
|
- // based on an inverse distance weighting.
|
|
|
-
|
|
|
- incidentLight.color = vec3( 0.0 );
|
|
|
- incidentLight.direction = geometry.normal;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-#endif
|
|
|
-
|
|
|
-
|
|
|
-#define MAX_AREA_LIGHTS 0
|
|
|
-
|
|
|
-#if MAX_AREA_LIGHTS > 0
|
|
|
-
|
|
|
- struct HemisphereLight {
|
|
|
- vec3 position; // NOTE: top left of area light, not the center
|
|
|
- vec3 width;
|
|
|
- vec3 height;
|
|
|
- vec3 color;
|
|
|
- //sampler2D image;
|
|
|
- float distance;
|
|
|
- float decay;
|
|
|
- };
|
|
|
-
|
|
|
- uniform AreaLight areaLights[ MAX_AREA_LIGHTS ];
|
|
|
-
|
|
|
- vec3 clampToAreaLight( const in mat3 worldToPlaneMat, const in vec3 lightPositionPlaneCoord, const in vec3 point ) {
|
|
|
-
|
|
|
- // convert into "plane space" from world space
|
|
|
- var pointPlaneCoord = worldToPlaneMat * point;
|
|
|
-
|
|
|
- // clamp point plane coords to positive unit in plane space.
|
|
|
- pointPlaneCoord.xy = clamp( positionPlaneCoord.xy - lightPositionPlaneCoord.xy, 0.0, 1.0 ) + lightPositionPlaneCoord.xy;
|
|
|
- pointPlaneCoord.z = lightPositionPlaneOffset; // project onto plane in plane coordinate space
|
|
|
-
|
|
|
- // convert out of "plane space" into world space
|
|
|
- return positionPlaneCoord * worldToPlaneMat;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- void getAreaIncidentLight( const in AreaLight areaLight, const in GeometricContext geometry, out IncidentLight diffuseIncidentLight, out IncidentLight specularIncidentLight ) {
|
|
|
-
|
|
|
- vec3 areaLightDirection = normalize( cross( widthDir, heightDir ) );
|
|
|
- // NOTE: width and height are purposely not normalized, this is necessary because plane space is scaled based on width/height size.
|
|
|
- mat3 worldToPlaneMat = mat3( areaLight.width, areaLight.height, areaLightDirection );
|
|
|
- vec3 lightPositionPlaneCoord = worldToPlaneMat * areaLight.position;
|
|
|
-
|
|
|
- vec3 clampedPlanePosition = clampToAreaLight( worldToPlaneMat, lightPositionPlaneCoord, geometry.position );
|
|
|
-
|
|
|
- vec3 positionToLight = ( clampedPlanePosition - geometry.position );
|
|
|
- float lightDistance = length( positionToLight );
|
|
|
-
|
|
|
- diffuseIncidentLight.color = areaLight.color[ i ] * calcLightAttenuation( lightDistance, areaLight.distance, areaLight.decay ) * 0.01;
|
|
|
- diffuseIncidentLight.direction = positionToLight / lightDistance;
|
|
|
-
|
|
|
- vec3 reflectDir = reflect( geometry.viewDir, geometry.normal );
|
|
|
- float specAngle = dot( reflectDir, direction );
|
|
|
-
|
|
|
- if( dot( geometry.position - areaLight.position, areaLightDirection ) >= 0.0 && specAngle > 0.0 ) {
|
|
|
-
|
|
|
- lightPositionPlaneCoord = linePlaneIntersect( geometry.position, reflectDir, areaLight.position, areaLight.normal );
|
|
|
- clampedPlanePosition = clampToAreaLight( worldToPlaneMat, lightPositionPlaneCoord, lightPositionPlaneCoord );
|
|
|
-
|
|
|
- positionToLight = ( clampedPlanePosition - geometry.position );
|
|
|
- lightDistance = length( positionToLight );
|
|
|
-
|
|
|
- specularIncidentLight.color = areaLight.color[ i ] * calcLightAttenuation( lightDistance, areaLight.distance, areaLight.decay );
|
|
|
- specularIncidentLight.direction = positionToLight / lightDistance;
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- specularIncidentLight.color = vec3( 0.0 );
|
|
|
- specularIncidentLight.direction = vec3( 1.0, 0.0, 0.0 );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-#endif
|