From 9b0036d010474d4466e9e2e07f7a9d863cf73162 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 5 Feb 2015 14:10:06 -0800 Subject: [PATCH] adding Light and replace glLights also for the first deferred pass --- libraries/model/src/model/Light.cpp | 10 +- libraries/model/src/model/Light.h | 4 + .../render-utils/src/DeferredGlobalLight.slh | 122 ++++++++++++++++++ .../render-utils/src/DeferredLighting.slh | 76 ----------- .../src/DeferredLightingEffect.cpp | 66 +++++----- .../render-utils/src/DeferredLightingEffect.h | 5 +- libraries/render-utils/src/Light.slh | 4 + .../src/directional_ambient_light.slf | 5 +- ...onal_ambient_light_cascaded_shadow_map.slf | 5 +- .../directional_ambient_light_shadow_map.slf | 5 +- .../render-utils/src/directional_light.slf | 5 +- .../directional_light_cascaded_shadow_map.slf | 5 +- .../src/directional_light_shadow_map.slf | 5 +- libraries/render-utils/src/point_light.slf | 14 +- libraries/render-utils/src/spot_light.slf | 20 +-- 15 files changed, 202 insertions(+), 149 deletions(-) create mode 100755 libraries/render-utils/src/DeferredGlobalLight.slh diff --git a/libraries/model/src/model/Light.cpp b/libraries/model/src/model/Light.cpp index d66c82ee16..30e873ea30 100755 --- a/libraries/model/src/model/Light.cpp +++ b/libraries/model/src/model/Light.cpp @@ -48,7 +48,7 @@ void Light::setOrientation(const glm::quat& orientation) { } void Light::setDirection(const Vec3& direction) { - editSchema()._direction = direction; + editSchema()._direction = glm::normalize(direction); } const Vec3& Light::getDirection() const { @@ -56,7 +56,7 @@ const Vec3& Light::getDirection() const { } void Light::setColor(const Color& color) { - editSchema()._color = color; + editSchema()._color = glm::normalize(color); } void Light::setIntensity(float intensity) { @@ -89,3 +89,9 @@ void Light::setSpotExponent(float exponent) { editSchema()._spot.w = exponent; } +void Light::setShowVolumeContour(float show) { + if (show <= 0.f) { + show = 0.0f; + } + editSchema()._control.w = show; +} \ No newline at end of file diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index c016d54491..4640711f4d 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -84,6 +84,10 @@ public: void setSpotExponent(float exponent); float getSpotExponent() const { return getSchema()._spot.w; } + // For editing purpose, show the light volume contour + void setShowVolumeContour(float show); + float getShowVolumeContour() const { return getSchema()._control.w; } + // Schema to access the attribute values of the light class Schema { public: diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh new file mode 100755 index 0000000000..bb33a124dc --- /dev/null +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -0,0 +1,122 @@ + +<@if not DEFERRED_GLOBAL_LIGHT_SLH@> +<@def DEFERRED_GLOBAL_LIGHT_SLH@> + +<@include DeferredLighting.slh@> + +struct SphericalHarmonics { + vec4 L00; + vec4 L1m1; + vec4 L10; + vec4 L11; + vec4 L2m2; + vec4 L2m1; + vec4 L20; + vec4 L21; + vec4 L22; +}; + +vec4 evalSphericalLight(SphericalHarmonics sh, vec3 direction ) { + + 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 * (direction.x * direction.x - direction.y * direction.y) + + C3 * sh.L20 * direction.z * direction.z + + C4 * sh.L00 - C5 * sh.L20 + + 2.0 * C1 * ( sh.L2m2 * direction.x * direction.y + + sh.L21 * direction.x * direction.z + + sh.L2m1 * direction.y * direction.z ) + + 2.0 * C2 * ( sh.L11 * direction.x + + sh.L1m1 * direction.y + + sh.L10 * direction.z ) ; + return value; +} + +// Need one SH +uniform SphericalHarmonics ambientSphere; + +// Everything about light +<@include Light.slh@> + +// The view Matrix +uniform mat4 invViewMat; + +vec3 evalAmbientColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) { + return diffuse.rgb * gl_FrontLightProduct[0].ambient.rgb; +} + +vec3 evalAmbientSphereColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) { + vec3 ambientLight = 0.5 * evalSphericalLight(ambientSphere, normal).xyz; + + return diffuse.rgb * ambientLight; +} + + + + +vec3 evalDirectionalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) { + + // Need the light now + Light light = getLight(); + vec4 shading = evalFragShading(normal, getLightDirection(light), normalize(position), specular, gloss); + return vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + // return vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * gl_FrontLightProduct[0].diffuse.rgb; +} + +vec3 evalAmbienGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) { + vec3 color = evalAmbientColor(normal, diffuse, specular, gloss) + + evalDirectionalColor(shadowAttenuation, + position, + normal, + diffuse, + specular, + gloss); + return color; +} +vec3 evalAmbienSphereGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) { + vec3 color = evalAmbientSphereColor(normal, diffuse, specular, gloss) + + evalDirectionalColor(shadowAttenuation, + position, + normal, + diffuse, + specular, + gloss); + return color; +} + +vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) { + + Light light = getLight(); + float diffuseDot = dot(normal, getLightDirection(light)); + + // need to catch normals perpendicular to the projection plane hence the magic number for the threshold + // it should be just 0, but we have innacurracy so we need to overshoot + const float PERPENDICULAR_THRESHOLD = -0.005; + float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); + + // evaluate the shadow test but only relevant for light facing fragments + float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; + + // diffuse light is the lightmap dimmed by shadow + vec3 diffuseLight = lightAttenuation * lightmap; + + // ambient is a tiny percentage of the lightmap and only when in the shadow + vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap; + + return diffuse * (ambientLight + diffuseLight); +} + +<@endif@> diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index 1c9f77c2e0..f6845fbccb 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -11,53 +11,6 @@ <@if not DEFERRED_LIGHTING_SLH@> <@def DEFERRED_LIGHTING_SLH@> -struct SphericalHarmonics { - vec4 L00; - vec4 L1m1; - vec4 L10; - vec4 L11; - vec4 L2m2; - vec4 L2m1; - vec4 L20; - vec4 L21; - vec4 L22; -}; - -vec4 evalSphericalLight(SphericalHarmonics sh, vec3 direction ) { - - 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 * (direction.x * direction.x - direction.y * direction.y) + - C3 * sh.L20 * direction.z * direction.z + - C4 * sh.L00 - C5 * sh.L20 + - 2.0 * C1 * ( sh.L2m2 * direction.x * direction.y + - sh.L21 * direction.x * direction.z + - sh.L2m1 * direction.y * direction.z ) + - 2.0 * C2 * ( sh.L11 * direction.x + - sh.L1m1 * direction.y + - sh.L10 * direction.z ) ; - return value; -} - -uniform SphericalHarmonics ambientSphere; - -// Everything about light -<@include Light.slh@> - -vec3 evalAmbientColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) { - return diffuse.rgb * gl_FrontLightProduct[0].ambient.rgb; -} - -vec3 evalAmbientSphereColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) { - vec3 ambientLight = 0.5 * evalSphericalLight(ambientSphere, normal).xyz; - - return diffuse.rgb * ambientLight; -} - // Frag Shading returns the diffuse amount as W and the specular rgb as xyz vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) { // Diffuse Lighting @@ -74,33 +27,4 @@ vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 s return vec4(reflect, diffuse); } -vec3 evalDirectionalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) { - - vec4 shading = evalFragShading(normal, gl_LightSource[0].position.xyz, normalize(position), specular, gloss); - - return vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * gl_FrontLightProduct[0].diffuse.rgb; -} - - -vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) { - - float diffuseDot = dot(normal, gl_LightSource[0].position.xyz); - - // need to catch normals perpendicular to the projection plane hence the magic number for the threshold - // it should be just 0, but we have innacurracy so we need to overshoot - const float PERPENDICULAR_THRESHOLD = -0.005; - float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); - - // evaluate the shadow test but only relevant for light facing fragments - float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; - - // diffuse light is the lightmap dimmed by shadow - vec3 diffuseLight = lightAttenuation * lightmap; - - // ambient is a tiny percentage of the lightmap and only when in the shadow - vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap; - - return diffuse * (ambientLight + diffuseLight); -} - <@endif@> diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 61330b8943..1241845675 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -209,6 +209,17 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { loadLightProgram(point_light_frag, true, _pointLight, _pointLightLocations); loadLightProgram(spot_light_frag, true, _spotLight, _spotLightLocations); + + // Allocate 2 global lights representing the GLobal Directional light casting shadow (the sun) and the ambient light + _globalLights.push_back(0); + _allocatedLights.push_back(model::LightPointer(new model::Light())); + + model::LightPointer lp = _allocatedLights[0]; + + lp->setDirection(-glm::vec3(1.0f, 1.0f, 1.0f)); + lp->setColor(glm::vec3(1.0f)); + lp->setIntensity(1.0f); + lp->setType(model::Light::SUN); } void DeferredLightingEffect::bindSimpleProgram() { @@ -264,51 +275,27 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu const glm::vec3& diffuse, const glm::vec3& specular, float constantAttenuation, float linearAttenuation, float quadraticAttenuation, const glm::vec3& direction, float exponent, float cutoff) { - int lightID = _pointLights.size() + _spotLights.size(); + int lightID = _pointLights.size() + _spotLights.size() + _globalLights.size(); if (lightID >= _allocatedLights.size()) { _allocatedLights.push_back(model::LightPointer(new model::Light())); } model::LightPointer lp = _allocatedLights[lightID]; - if (exponent == 0.0f && cutoff == PI) { - PointLight light; - light.position = glm::vec4(position, 1.0f); - light.radius = radius; - light.ambient = glm::vec4(ambient, 1.0f); - light.diffuse = glm::vec4(diffuse, 1.0f); - light.specular = glm::vec4(specular, 1.0f); - light.constantAttenuation = constantAttenuation; - light.linearAttenuation = linearAttenuation; + lp->setPosition(position); + lp->setMaximumRadius(radius); + lp->setColor(diffuse); + lp->setIntensity(1.0f); + lp->setShowVolumeContour(quadraticAttenuation); - lp->setPosition(position); - lp->setMaximumRadius(radius); - lp->setColor(diffuse); - lp->setIntensity(1.0f); + if (exponent == 0.0f && cutoff == PI) { lp->setType(model::Light::POINT); _pointLights.push_back(lightID); } else { - SpotLight light; - light.position = glm::vec4(position, 1.0f); - light.radius = radius; - light.ambient = glm::vec4(ambient, 1.0f); - light.diffuse = glm::vec4(diffuse, 1.0f); - light.specular = glm::vec4(specular, 1.0f); - light.constantAttenuation = constantAttenuation; - light.linearAttenuation = linearAttenuation; - light.direction = direction; - light.exponent = exponent; - light.cutoff = cutoff; - - lp->setPosition(position); lp->setDirection(direction); - lp->setMaximumRadius(radius); lp->setSpotAngle(cutoff); lp->setSpotExponent(exponent); - lp->setColor(diffuse); - lp->setIntensity(1.0f); lp->setType(model::Light::SPOT); - _spotLights.push_back(lightID); } } @@ -368,6 +355,10 @@ void DeferredLightingEffect::render() { float tMin = viewport[VIEWPORT_Y_INDEX] / (float)primaryFBO->height(); float tHeight = viewport[VIEWPORT_HEIGHT_INDEX] / (float)primaryFBO->height(); + // Fetch the ViewMatrix; + glm::mat4 invViewMat; + _viewState->getViewTransform().getMatrix(invViewMat); + ProgramObject* program = &_directionalLight; const LightLocations* locations = &_directionalLightLocations; bool shadowsEnabled = _viewState->getShadowsEnabled(); @@ -418,6 +409,17 @@ void DeferredLightingEffect::render() { } } + { + auto light = _allocatedLights[_globalLights.front()]; + + if (locations->lightBufferUnit >= 0) { + gpu::Batch batch; + batch.setUniformBuffer(locations->lightBufferUnit, light->getSchemaBuffer()); + gpu::GLBackend::renderBatch(batch); + } + glUniformMatrix4fv(locations->invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat)); + } + float left, right, bottom, top, nearVal, farVal; glm::vec4 nearClipPlane, farClipPlane; _viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); @@ -457,8 +459,6 @@ void DeferredLightingEffect::render() { const glm::vec3& eyePoint = _viewState->getCurrentViewFrustum()->getPosition(); float nearRadius = glm::distance(eyePoint, _viewState->getCurrentViewFrustum()->getNearTopLeft()); - glm::mat4 invViewMat; - _viewState->getViewTransform().getMatrix(invViewMat); auto geometryCache = DependencyManager::get(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 8e6606506a..ad4231a0b7 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -91,7 +91,7 @@ public: void setAmbientLightMode(int preset); private: - DeferredLightingEffect() { } + DeferredLightingEffect() {} virtual ~DeferredLightingEffect() { } class LightLocations { @@ -154,10 +154,9 @@ private: typedef std::vector< model::LightPointer > Lights; Lights _allocatedLights; + std::vector _globalLights; std::vector _pointLights; std::vector _spotLights; - // QVector _pointLights; - // QVector _spotLights; QVector _postLightingRenderables; AbstractViewStateInterface* _viewState; diff --git a/libraries/render-utils/src/Light.slh b/libraries/render-utils/src/Light.slh index 0560898d09..abb9fb6c2a 100755 --- a/libraries/render-utils/src/Light.slh +++ b/libraries/render-utils/src/Light.slh @@ -61,6 +61,10 @@ float getLightAttenuationCutoff(Light l) { return l._attenuation.z; } +float getLightShowContour(Light l) { + return l._control.w; +} + <@if GLPROFILE == PC_GL@> uniform lightBuffer { Light light; diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index a0b850e925..308a8a73a7 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -15,7 +15,7 @@ // Everything about deferred buffer <@include DeferredBuffer.slh@> -<@include DeferredLighting.slh@> +<@include DeferredGlobalLight.slh@> void main(void) { DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); @@ -31,8 +31,7 @@ void main(void) { gl_FragColor = vec4(color, 1.0); } else { - vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) - + evalDirectionalColor(1.0, + vec3 color = evalAmbienSphereGlobalColor(1.0, frag.position.xyz, frag.normal, frag.diffuse, diff --git a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf index 5f88c558d3..db017cf5ac 100755 --- a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf +++ b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf @@ -15,7 +15,7 @@ // Everything about deferred buffer <@include DeferredBuffer.slh@> -<@include DeferredLighting.slh@> +<@include DeferredGlobalLight.slh@> // Everything about shadow <@include Shadow.slh@> @@ -36,8 +36,7 @@ void main(void) { frag.specularVal.xyz), 1.0); } else { - vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) - + evalDirectionalColor(shadowAttenuation, + vec3 color = evalAmbienSphereGlobalColor(shadowAttenuation, frag.position.xyz, frag.normal, frag.diffuse, diff --git a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf index 6c241853e3..43d3e91dbe 100755 --- a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf @@ -15,7 +15,7 @@ // Everything about deferred buffer <@include DeferredBuffer.slh@> -<@include DeferredLighting.slh@> +<@include DeferredGlobalLight.slh@> // Everything about shadow <@include Shadow.slh@> @@ -37,8 +37,7 @@ void main(void) { frag.specularVal.xyz), 1.0); } else { - vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) - + evalDirectionalColor(shadowAttenuation, + vec3 color = evalAmbienSphereGlobalColor(shadowAttenuation, frag.position.xyz, frag.normal, frag.diffuse, diff --git a/libraries/render-utils/src/directional_light.slf b/libraries/render-utils/src/directional_light.slf index 8ff6cd6c87..3e708f849e 100644 --- a/libraries/render-utils/src/directional_light.slf +++ b/libraries/render-utils/src/directional_light.slf @@ -15,7 +15,7 @@ // Everything about deferred buffer <@include DeferredBuffer.slh@> -<@include DeferredLighting.slh@> +<@include DeferredGlobalLight.slh@> void main(void) { DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st); @@ -29,8 +29,7 @@ void main(void) { frag.specularVal.xyz), 1.0); } else { - vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) - + evalDirectionalColor(1.0, + vec3 color = evalAmbienGlobalColor(1.0, frag.position.xyz, frag.normal, frag.diffuse, diff --git a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf index ccf8909b64..90b3bf1d2b 100644 --- a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf +++ b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf @@ -15,7 +15,7 @@ // Everything about deferred buffer <@include DeferredBuffer.slh@> -<@include DeferredLighting.slh@> +<@include DeferredGlobalLight.slh@> // Everything about shadow <@include Shadow.slh@> @@ -36,8 +36,7 @@ void main(void) { frag.specularVal.xyz), 1.0); } else { - vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) - + evalDirectionalColor(shadowAttenuation, + vec3 color = evalAmbienGlobalColor(shadowAttenuation, frag.position.xyz, frag.normal, frag.diffuse, diff --git a/libraries/render-utils/src/directional_light_shadow_map.slf b/libraries/render-utils/src/directional_light_shadow_map.slf index 13435e9101..5029b57020 100644 --- a/libraries/render-utils/src/directional_light_shadow_map.slf +++ b/libraries/render-utils/src/directional_light_shadow_map.slf @@ -15,7 +15,7 @@ // Everything about deferred buffer <@include DeferredBuffer.slh@> -<@include DeferredLighting.slh@> +<@include DeferredGlobalLight.slh@> // Everything about shadow <@include Shadow.slh@> @@ -37,8 +37,7 @@ void main(void) { frag.specularVal.xyz), 1.0); } else { - vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) - + evalDirectionalColor(shadowAttenuation, + vec3 color = evalAmbienGlobalColor(shadowAttenuation, frag.position.xyz, frag.normal, frag.diffuse, diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index 3d3d922203..abe904ecce 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -64,12 +64,12 @@ void main(void) { vec3 fragColor = shading.w * (frag.diffuse + shading.xyz); gl_FragColor = vec4(fragColor * radialAttenuation * getLightColor(light) * getLightIntensity(light), 0.0); -<@if SHOW_LIGHT_CONTOUR@> - // Show edge - float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1) { - float edgeCoord = exp2(-8.0*edge*edge); - gl_FragColor = vec4(edgeCoord * edgeCoord * getLightColor(light), 0.0); + if (getLightShowContour(light) > 0.0) { + // Show edge + float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0); + if (edge < 1) { + float edgeCoord = exp2(-8.0*edge*edge); + gl_FragColor = vec4(edgeCoord * edgeCoord * getLightShowContour(light) * getLightColor(light), 0.0); + } } -<@endif@> } diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index aec1ce4b89..95fabae3ed 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -72,16 +72,16 @@ void main(void) { vec3 fragColor = shading.w * (frag.diffuse + shading.xyz); gl_FragColor = vec4(fragColor * angularAttenuation * radialAttenuation * getLightColor(light) * getLightIntensity(light), 0.0); -<@if SHOW_LIGHT_CONTOUR@> - // Show edges - float edgeDistR = (getLightRadius(light) - fragLightDistance); - float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light)); - float edgeDist = min(edgeDistR, edgeDistS); - float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); - if (edge < 1) { - float edgeCoord = exp2(-8.0*edge*edge); - gl_FragColor = vec4(edgeCoord * edgeCoord * getLightColor(light), 0.0); + if (getLightShowContour(light) > 0.0) { + // Show edges + float edgeDistR = (getLightRadius(light) - fragLightDistance); + float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light)); + float edgeDist = min(edgeDistR, edgeDistS); + float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); + if (edge < 1) { + float edgeCoord = exp2(-8.0*edge*edge); + gl_FragColor = vec4(edgeCoord * edgeCoord * getLightColor(light), 0.0); + } } -<@endif@> }