diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index c091026ba2..f1c68bb93a 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -26,8 +26,46 @@ typedef glm::vec3 Vec3; typedef glm::vec4 Vec4; typedef glm::quat Quat; + class Light { public: + + struct LightVolume { + vec3 position; + float radius; + vec3 direction; + float spotCos; + + bool isPoint() { return bool(spotCos < 0.f); } + bool isSpot() { return bool(spotCos >= 0.f); } + + vec3 getPosition() { return position; } + float getRadius() { return radius; } + float getRadiusSquare() { return radius * radius; } + vec3 getDirection() { return direction; } + + float getSpotAngleCos() { return spotCos; } + }; + + + struct LightIrradiance { + vec3 color; + float intensity; + float falloffRadius; + float falloffSpot; + float spare1; + float spare2; + + vec3 getColor() { return color; } + float getIntensity() { return intensity; } + vec3 getIrradiance() { return color * intensity; } + float getFalloffRadius() { return falloffRadius; } + float getFalloffRadiusSquare() { return falloffRadius * falloffRadius; } + float getFalloffSpot() { return falloffSpot; } + }; + + + enum Type { SUN = 0, POINT, diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 888abf5038..6e9f92e67f 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -11,129 +11,74 @@ <@if not MODEL_LIGHT_SLH@> <@def MODEL_LIGHT_SLH@> -struct SphericalHarmonics { - vec4 L00; - vec4 L1m1; - vec4 L10; - vec4 L11; - vec4 L2m2; - vec4 L2m1; - vec4 L20; - vec4 L21; - vec4 L22; -}; +<@include model/SphericalHarmonics.shared.slh@> +<@include model/LightVolume.shared.slh@> +<@include model/LightIrradiance.shared.slh@> -vec4 evalSphericalLight(SphericalHarmonics 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; -} +// NOw lets define Light struct Light { - vec4 _position; - vec4 _direction; - vec4 _color; - vec4 _attenuation; - vec4 _spot; - - // vec4 _shadow; - vec4 _control; - - vec4 _volumeGeometry; - - SphericalHarmonics _ambientSphere; + LightVolume volume; + LightIrradiance irradiance; }; -const int LIGHT_SPOT = 2; - -bool light_isSpot(Light l) { - return bool(l._control.y >= 2.f); -} - -vec3 getLightPosition(Light l) { return l._position.xyz; } -vec3 getLightDirection(Light l) { return l._direction.xyz; } // direction is -Z axis - -vec3 getLightColor(Light l) { return l._color.rgb; } -float getLightIntensity(Light l) { return l._color.w; } -float getLightAmbientIntensity(Light l) { return l._direction.w; } - -float getLightSpotAngleCos(Light l) { - return l._spot.x; -} - -vec2 getLightSpotOutsideNormal2(Light l) { - return vec2(-l._spot.y, l._spot.x); -} - -float evalLightSpotAttenuation(Light l, float cosA) { - return pow(cosA, l._spot.w); -} - -float getLightRadius(Light l) { - return l._attenuation.x; -} - -float getLightSquareRadius(Light l) { - return getLightRadius(l) * getLightRadius(l); -} - -float getLightCutoffRadius(Light l) { - return l._attenuation.z; -} - -float getLightCutoffSquareRadius(Light l) { - return getLightCutoffRadius(l) * getLightCutoffRadius(l); -} - -float getLightShowContour(Light l) { - return l._control.w; -} - -vec4 getLightVolumeGeometry(Light l) { - return l._volumeGeometry; -} // Light is the light source its self, d is the light's distance calculated as length(unnormalized light vector). float evalLightAttenuation(Light l, float d) { - float radius = getLightRadius(l); + float radius = lightIrradiance_getFalloffRadius(l.irradiance); + float cutoff = lightVolume_getRadius(l.volume); float denom = d / radius + 1.0; float attenuation = 1.0 / (denom * denom); - - float cutoff = getLightCutoffRadius(l); - + + // "Fade" the edges of light sources to make things look a bit more attractive. // Note: this tends to look a bit odd at lower exponents. attenuation *= min(1, max(0, -(d - cutoff))); - + return attenuation; } -SphericalHarmonics getLightAmbientSphere(Light l) { + +float evalLightSpotAttenuation(Light l, float cosA) { + return pow(cosA, lightIrradiance_getFalloffSpot(l.irradiance)); +} + +bool light_isSpot(Light l) { return lightVolume_isSpot(l.volume); } + +vec3 getLightPosition(Light l) { return lightVolume_getPosition(l.volume); } +vec3 getLightDirection(Light l) { return lightVolume_getDirection(l.volume); } + + +vec3 getLightColor(Light l) { return lightIrradiance_getColor(l.irradiance); } +float getLightIntensity(Light l) { return lightIrradiance_getIntensity(l.irradiance); } +vec3 getLightIrradiance(Light l) { return lightIrradiance_getIrradiance(l.irradiance); } + + + + + + + +struct LightAmbient { + vec4 _ambient; + SphericalHarmonics _ambientSphere; +}; + +SphericalHarmonics getLightAmbientSphere(LightAmbient l) { return l._ambientSphere; } -bool getLightHasAmbientMap(Light l) { - return l._control.x > 0; + +float getLightAmbientIntensity(LightAmbient l) { return l._ambient.w; } + + +bool getLightHasAmbientMap(LightAmbient l) { + return l._ambient.x > 0; + // return l._control.x > 0; } -float getLightAmbientMapNumMips(Light l) { - return l._control.x; +float getLightAmbientMapNumMips(LightAmbient l) { + return l._ambient.x; } <@func declareLightBuffer(N)@> @@ -146,6 +91,7 @@ uniform lightBuffer { Light getLight(int index) { return lightArray[index]; } + <@else@> uniform lightBuffer { Light light; @@ -161,39 +107,32 @@ Light getLight() { -bool clipFragToLightVolumePoint(Light light, vec3 fragPos, out vec4 fragLightVecLen2) { - fragLightVecLen2.xyz = getLightPosition(light) - fragPos.xyz; - fragLightVecLen2.w = dot(fragLightVecLen2.xyz, fragLightVecLen2.xyz); - // Kill if too far from the light center - if (fragLightVecLen2.w > getLightCutoffSquareRadius(light)) { - return false; - } - return true; + +<@func declareLightAmbientBuffer(N)@> + +<@if N@> + +uniform lightAmbientBuffer { + LightAmbient lightAmbientArray[<$N$>]; +}; + +LightAmbient getLightAmbient(int index) { + return lightAmbientArray[index]; } -bool clipFragToLightVolumeSpot(Light light, vec3 fragPos, out vec4 fragLightVecLen2, out vec4 fragLightDirLen, out float cosSpotAngle) { - fragLightVecLen2.xyz = getLightPosition(light) - fragPos.xyz; - fragLightVecLen2.w = dot(fragLightVecLen2.xyz, fragLightVecLen2.xyz); +<@else@> +uniform lightAmbientBuffer { + LightAmbient lightAmbient; +}; - // Kill if too far from the light center - if (fragLightVecLen2.w > getLightCutoffSquareRadius(light)) { - 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, getLightDirection(light)), 0.0); - if (cosSpotAngle < getLightSpotAngleCos(light)) { - return false; - } - - return true; +LightAmbient getLightAmbient() { + return lightAmbient; } +<@endif@> + +<@endfunc@> <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index cb5dd9dc48..76194965c1 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -15,6 +15,7 @@ <@include LightingModel.slh@> <$declareLightBuffer()$> +<$declareLightAmbientBuffer()$> <@include LightAmbient.slh@> <@include LightDirectional.slh@> @@ -29,7 +30,11 @@ // Get light Light light = getLight(); + LightAmbient lightAmbient = getLightAmbient(); + vec3 lightDirection = getLightDirection(light); + vec3 lightIrradiance = getLightIrradiance(light); + vec3 color = vec3(0.0); <@endfunc@> @@ -38,7 +43,7 @@ <@func declareEvalAmbientGlobalColor()@> vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, float roughness) { <$prepareGlobalLight()$> - color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light); + color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(lightAmbient); return color; } <@endfunc@> @@ -63,7 +68,7 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); @@ -74,7 +79,7 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); @@ -107,7 +112,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> @@ -119,7 +124,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> @@ -135,6 +140,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu <@func declareEvalLightmappedColor()@> vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 normal, vec3 albedo, vec3 lightmap) { Light light = getLight(); + LightAmbient ambient = getLightAmbient(); // Catch normals perpendicular to the projection plane, hence the magic number for the threshold // It should be just 0, but we have inaccuracy so we overshoot @@ -150,7 +156,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur vec3 diffuseLight = lightAttenuation * lightmap; // Ambient light is the lightmap when in shadow - vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light); + vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(ambient); return isLightmapEnabled() * obscurance * albedo * (diffuseLight + ambientLight); } @@ -172,7 +178,7 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance); + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; color += ambientSpecular / opacity; @@ -180,7 +186,7 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; color += directionalSpecular / opacity; diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index ec665e6deb..ecb8fa0ae5 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -30,16 +30,16 @@ vec3 fresnelSchlickAmbient(vec3 fresnelColor, vec3 lightDir, vec3 halfDir, float <$declareSkyboxMap()$> <@endif@> -vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal, float roughness, vec3 fresnel) { +vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, vec3 fragEyeDir, vec3 fragNormal, float roughness, vec3 fresnel) { vec3 direction = -reflect(fragEyeDir, fragNormal); vec3 ambientFresnel = fresnelSchlickAmbient(fresnel, fragEyeDir, fragNormal, 1 - roughness); vec3 specularLight; <@if supportIfAmbientMapElseAmbientSphere@> - if (getLightHasAmbientMap(light)) + if (getLightHasAmbientMap(ambient)) <@endif@> <@if supportAmbientMap@> { - float levels = getLightAmbientMapNumMips(light); + float levels = getLightAmbientMapNumMips(ambient); float lod = min(floor((roughness)* levels), levels); specularLight = evalSkyboxLight(direction, lod).xyz; } @@ -49,7 +49,7 @@ vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal <@endif@> <@if supportAmbientSphere@> { - specularLight = evalSphericalLight(getLightAmbientSphere(light), direction).xyz; + specularLight = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), direction).xyz; } <@endif@> @@ -67,7 +67,7 @@ float curvatureAO(in float k) { } <@endif@> -void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 eyeDir, vec3 normal, +void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambient, vec3 eyeDir, vec3 normal, float roughness, float metallic, vec3 fresnel, vec3 albedo, float obscurance <@if supportScattering@> , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature @@ -76,10 +76,10 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 // Diffuse from ambient - diffuse = (1 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz; + diffuse = (1 - metallic) * sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), normal).xyz; // Specular highlight from ambient - specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light); + specular = evalAmbientSpecularIrradiance(ambient, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(ambient); <@if supportScattering@> @@ -92,7 +92,7 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 if (scattering * isScatteringEnabled() > 0.0) { // Diffuse from ambient - diffuse = evalSphericalLight(getLightAmbientSphere(light), lowNormalCurvature.xyz).xyz; + diffuse = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), lowNormalCurvature.xyz).xyz; specular = vec3(0.0); } @@ -102,7 +102,7 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 obscurance = 1.0; } - float lightEnergy = obscurance * getLightAmbientIntensity(light); + float lightEnergy = obscurance * getLightAmbientIntensity(ambient); if (isAlbedoEnabled() > 0.0) { diffuse *= albedo; diff --git a/libraries/render-utils/src/LightDirectional.slh b/libraries/render-utils/src/LightDirectional.slh index 86eb130491..749709c600 100644 --- a/libraries/render-utils/src/LightDirectional.slh +++ b/libraries/render-utils/src/LightDirectional.slh @@ -11,7 +11,7 @@ <@func declareLightingDirectional(supportScattering)@> -void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light, +void evalLightingDirectional(out vec3 diffuse, out vec3 specular, vec3 lightDir, vec3 lightIrradiance, vec3 eyeDir, vec3 normal, float roughness, float metallic, vec3 fresnel, vec3 albedo, float shadow <@if supportScattering@> @@ -20,9 +20,9 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light, ) { // Attenuation - vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light); + vec3 lightEnergy = shadow * lightIrradiance; - evalFragShading(diffuse, specular, normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness, albedo + evalFragShading(diffuse, specular, normal, -lightDir, eyeDir, metallic, fresnel, roughness, albedo <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index 767a96fb51..b120df584a 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -25,7 +25,7 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, // Eval attenuation float radialAttenuation = evalLightAttenuation(light, fragLightDistance); - vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light); + vec3 lightEnergy = radialAttenuation * shadow * getLightIrradiance(light); // Eval shading evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, albedo @@ -39,7 +39,7 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, if (isShowLightContour() > 0.0) { // Show edge - float edge = abs(2.0 * ((getLightCutoffRadius(light) - fragLightDistance) / (0.1)) - 1.0); + float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); if (edge < 1) { float edgeCoord = exp2(-8.0*edge*edge); diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 65a417110a..3a04c28bfb 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -26,7 +26,7 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, // Eval attenuation float radialAttenuation = evalLightAttenuation(light, fragLightDistance); float angularAttenuation = evalLightSpotAttenuation(light, cosSpotAngle); - vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light); + vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow *getLightIrradiance(light); // Eval shading evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, albedo @@ -40,8 +40,8 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, if (isShowLightContour() > 0.0) { // Show edges - float edgeDistR = (getLightCutoffRadius(light) - fragLightDistance); - float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light)); + float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); + float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); float edgeDist = min(edgeDistR, edgeDistS); float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); if (edge < 1) { diff --git a/libraries/render-utils/src/deferred_light_point.slv b/libraries/render-utils/src/deferred_light_point.slv index 6bdc6fe42f..f126ee9251 100644 --- a/libraries/render-utils/src/deferred_light_point.slv +++ b/libraries/render-utils/src/deferred_light_point.slv @@ -34,7 +34,7 @@ void main(void) { Light light = getLight(instanceID); vec4 sphereVertex = inPosition; vec3 lightOrigin = getLightPosition(light); - vec4 sphereParam = getLightVolumeGeometry(light); + vec4 sphereParam = vec4(1.0); // = getLightVolumeGeometry(light); sphereVertex.xyz *= sphereParam.w; diff --git a/libraries/render-utils/src/deferred_light_spot.slv b/libraries/render-utils/src/deferred_light_spot.slv index c120fa28b1..5edd889704 100755 --- a/libraries/render-utils/src/deferred_light_spot.slv +++ b/libraries/render-utils/src/deferred_light_spot.slv @@ -31,7 +31,7 @@ void main(void) { int instanceID = lightIndex[gl_InstanceID]; Light light = getLight(instanceID); vec3 lightPos = getLightPosition(light); - vec4 coneParam = getLightVolumeGeometry(light); + vec4 coneParam = vec4(1.0); // = getLightVolumeGeometry(light); if(coneVertex.z >= 0.0) { // Evaluate the true position of the spot volume diff --git a/libraries/render-utils/src/local_lights_shading.slf b/libraries/render-utils/src/local_lights_shading.slf index eba65c39af..8cf817b127 100644 --- a/libraries/render-utils/src/local_lights_shading.slf +++ b/libraries/render-utils/src/local_lights_shading.slf @@ -94,7 +94,14 @@ void main(void) { vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0); vec3 fragEyeDir = normalize(fragEyeVector.xyz); - // int numLights = lightIndex[0]; + + /* int theLightIndex = clusterGrid_getClusterLightId(0, cluster); + if (theLightIndex == 65535) { + discard; + } + Light light = getLight(theLightIndex); + + int numLights = lightIndex[0];*/ for (int i = 0; i < numLights; i++) { // Need the light now int theLightIndex = clusterGrid_getClusterLightId(i, cluster); @@ -105,11 +112,11 @@ void main(void) { vec4 fragLightDirLen; float cosSpotAngle; if (isSpot) { - if (!clipFragToLightVolumeSpot(light, fragPos.xyz, fragLightVecLen2, fragLightDirLen, cosSpotAngle)) { + if (!lightVolume_clipFragToLightVolumeSpot(light.volume, fragPos.xyz, fragLightVecLen2, fragLightDirLen, cosSpotAngle)) { continue; } } else { - if (!clipFragToLightVolumePoint(light, fragPos.xyz, fragLightVecLen2)) { + if (!lightVolume_clipFragToLightVolumePoint(light.volume, fragPos.xyz, fragLightVecLen2)) { continue; } } diff --git a/libraries/render-utils/src/overlay3D.slf b/libraries/render-utils/src/overlay3D.slf index 1a629dedf1..0cb3340845 100644 --- a/libraries/render-utils/src/overlay3D.slf +++ b/libraries/render-utils/src/overlay3D.slf @@ -14,6 +14,7 @@ <@include model/Light.slh@> <$declareLightBuffer()$> +<$declareLightAmbientBuffer()$> <@include LightingModel.slh@> @@ -27,6 +28,11 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a // Need the light now Light light = getLight(); + vec3 lightDirection = getLightDirection(light); + vec3 lightIrradiance = getLightIrradiance(light); + + LightAmbient ambient = getLightAmbient(); + TransformCamera cam = getTransformCamera(); vec3 fragNormal; <$transformEyeToWorldDir(cam, normal, fragNormal)$> @@ -34,12 +40,12 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a vec3 fragEyeDir; <$transformEyeToWorldDir(cam, fragEyeVectorView, fragEyeDir)$> - vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light); + vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(ambient); // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); diff --git a/libraries/render-utils/src/overlay3D_translucent.slf b/libraries/render-utils/src/overlay3D_translucent.slf index f45aa897f9..9bdac2d21f 100644 --- a/libraries/render-utils/src/overlay3D_translucent.slf +++ b/libraries/render-utils/src/overlay3D_translucent.slf @@ -14,6 +14,7 @@ <@include model/Light.slh@> <$declareLightBuffer()$> +<$declareLightAmbientBuffer()$> <@include LightingModel.slh@> @@ -27,6 +28,11 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a // Need the light now Light light = getLight(); + vec3 lightDirection = getLightDirection(light); + vec3 lightIrradiance = getLightIrradiance(light); + + LightAmbient ambient = getLightAmbient(); + TransformCamera cam = getTransformCamera(); vec3 fragNormal; <$transformEyeToWorldDir(cam, normal, fragNormal)$> @@ -34,12 +40,12 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a vec3 fragEyeDir; <$transformEyeToWorldDir(cam, fragEyeVectorView, fragEyeDir)$> - vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light); + vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(ambient); // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; color += directionalSpecular / opacity; diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index 239cbd5c91..e646db5069 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -58,7 +58,7 @@ void main(void) { // Clip againgst the light volume and Make the Light vector going from fragment to light center in world space vec4 fragLightVecLen2; - if (!clipFragToLightVolumePoint(light, fragPos.xyz, fragLightVecLen2)) { + if (!lightVolume_clipFragToLightVolumePoint(light.volume, fragPos.xyz, fragLightVecLen2)) { discard; }