diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 43bff3ccce..6f6534e2d2 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -26,7 +26,7 @@ #include "SoundCache.h" #include "AudioSRC.h" -//int audioInjectorPtrMetaTypeId = qRegisterMetaType(); +int audioInjectorPtrMetaTypeId = qRegisterMetaType(); AbstractAudioInterface* AudioInjector::_localAudioInterface{ nullptr }; diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 9f97b7f405..4ae2da295f 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -140,6 +140,9 @@ void RenderableLightEntityItem::updateLightFromEntity(render::PendingChanges& pe void RenderableLightEntityItem::updateRenderItemFromEntity(LightPayload* lightPayload) { auto entity = this; + + lightPayload->setVisible(entity->getVisible()); + auto light = lightPayload->editLight(); light->setPosition(entity->getPosition()); light->setOrientation(entity->getRotation()); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 061da3e397..821d4d14c9 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -511,10 +511,7 @@ void GL45Texture::stripToMip(uint16_t newMinMip) { _minMip = newMinMip; // Re-sync the sampler to force access to the new mip level syncSampler(); - size_t oldSize = _size; updateSize(); - // Q_ASSERT(_size > oldSize); - // Re-insert into the texture-by-mips map if appropriate mipLevels = usedMipLevels(); diff --git a/libraries/model/src/model/Light.slh b/libraries/model/src/model/Light.slh index 78fa11416d..d405848d43 100644 --- a/libraries/model/src/model/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -11,13 +11,10 @@ <@if not MODEL_LIGHT_SLH@> <@def MODEL_LIGHT_SLH@> -<@include model/SphericalHarmonics.shared.slh@> <@include model/LightVolume.shared.slh@> <@include model/LightIrradiance.shared.slh@> // NOw lets define Light - - struct Light { LightVolume volume; LightIrradiance irradiance; @@ -28,38 +25,23 @@ 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); } - - - - - - +// AMbient lighting needs extra info provided from a different Buffer +<@include model/SphericalHarmonics.shared.slh@> +// Light Ambient struct LightAmbient { vec4 _ambient; SphericalHarmonics _ambientSphere; }; -SphericalHarmonics getLightAmbientSphere(LightAmbient l) { - return l._ambientSphere; -} +SphericalHarmonics getLightAmbientSphere(LightAmbient l) { return l._ambientSphere; } - -float getLightAmbientIntensity(LightAmbient l) { return l._ambient.w; } - - -bool getLightHasAmbientMap(LightAmbient l) { - return l._ambient.x > 0; - // return l._control.x > 0; -} - -float getLightAmbientMapNumMips(LightAmbient l) { - return l._ambient.x; -} +float getLightAmbientIntensity(LightAmbient l) { return l._ambient.x; } +bool getLightHasAmbientMap(LightAmbient l) { return l._ambient.y > 0; } +float getLightAmbientMapNumMips(LightAmbient l) { return l._ambient.y; } <@func declareLightBuffer(N)@> diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b1833764dd..ace969563e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -43,7 +43,6 @@ using namespace render; struct LightLocations { int radius{ -1 }; - int ambientSphere{ -1 }; int lightBufferUnit{ -1 }; int ambientBufferUnit { -1 }; int lightIndexBufferUnit { -1 }; @@ -199,6 +198,22 @@ void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBuff batch.setResourceTexture(skyboxCubemapUnit, keyLight->getAmbientMap()); } } + +void DeferredLightingEffect::unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { + auto keyLight = _allocatedLights[_globalLights.front()]; + + if (lightBufferUnit >= 0) { + batch.setUniformBuffer(lightBufferUnit, nullptr); + } + if (keyLight->hasAmbient() && (ambientBufferUnit >= 0)) { + batch.setUniformBuffer(ambientBufferUnit, nullptr); + } + + if (keyLight->getAmbientMap() && (skyboxCubemapUnit >= 0)) { + batch.setResourceTexture(skyboxCubemapUnit, nullptr); + } +} + static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* fragSource, LightLocationsPtr& locations) { auto VS = gpu::Shader::createVertex(std::string(vertSource)); auto PS = gpu::Shader::createPixel(std::string(fragSource)); @@ -237,7 +252,6 @@ static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* f gpu::Shader::makeProgram(*program, slotBindings); locations->radius = program->getUniforms().findLocation("radius"); - locations->ambientSphere = program->getUniforms().findLocation("ambientSphere.L00"); locations->texcoordFrameTransform = program->getUniforms().findLocation("texcoordFrameTransform"); @@ -646,15 +660,14 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c auto textureFrameTransform = gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(deferredFramebuffer->getFrameSize(), args->_viewport); batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); - { // Setup the global lighting - deferredLightingEffect->setupKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); - } - + // Setup the global lighting + deferredLightingEffect->setupKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); + batch.draw(gpu::TRIANGLE_STRIP, 4); - if (keyLight->getAmbientMap()) { - batch.setResourceTexture(SKYBOX_MAP_UNIT, nullptr); - } + deferredLightingEffect->unsetKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); + + batch.setResourceTexture(SHADOW_MAP_UNIT, nullptr); } } @@ -806,6 +819,11 @@ void RenderDeferredCleanup::run(const render::SceneContextPointer& sceneContext, batch.setUniformBuffer(SCATTERING_PARAMETERS_BUFFER_SLOT, nullptr); // batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, nullptr); batch.setUniformBuffer(DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT, nullptr); + + batch.setUniformBuffer(LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, nullptr); + batch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, nullptr); + batch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, nullptr); + } auto deferredLightingEffect = DependencyManager::get(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 1045cab30e..9462dbcc4e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -57,6 +57,7 @@ public: const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI); void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); + void unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); // update global lighting void setGlobalLight(const model::LightPointer& light); diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index ecb8fa0ae5..98f043081e 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -74,7 +74,6 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambie <@endif@> ) { - // Diffuse from ambient diffuse = (1 - metallic) * sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(ambient), normal).xyz; diff --git a/libraries/render-utils/src/LightPayload.cpp b/libraries/render-utils/src/LightPayload.cpp index 8f7b893f6a..5f58677efe 100644 --- a/libraries/render-utils/src/LightPayload.cpp +++ b/libraries/render-utils/src/LightPayload.cpp @@ -16,7 +16,12 @@ namespace render { template <> const ItemKey payloadGetKey(const LightPayload::Pointer& payload) { - return ItemKey::Builder::light(); + ItemKey::Builder builder; + builder.withTypeLight(); + if (!payload || !payload->isVisible()) { + builder.withInvisible(); + } + return builder.build(); } template <> const Item::Bound payloadGetBound(const LightPayload::Pointer& payload) { @@ -63,7 +68,9 @@ void LightPayload::render(RenderArgs* args) { _needUpdate = false; } - // FInally, push the light visible in the frame - _stage->_currentFrame.pushLight(_index, _light->getType()); + if (isVisible()) { + // FInally, push the light visible in the frame + _stage->_currentFrame.pushLight(_index, _light->getType()); + } } diff --git a/libraries/render-utils/src/LightPayload.h b/libraries/render-utils/src/LightPayload.h index fba4ff15cb..6b5fe83f07 100644 --- a/libraries/render-utils/src/LightPayload.h +++ b/libraries/render-utils/src/LightPayload.h @@ -27,13 +27,17 @@ public: model::LightPointer editLight() { _needUpdate = true; return _light; } render::Item::Bound& editBound() { _needUpdate = true; return _bound; } - + + void setVisible(bool visible) { _isVisible = visible; } + bool isVisible() const { return _isVisible; } + protected: model::LightPointer _light; render::Item::Bound _bound; LightStagePointer _stage; LightStage::Index _index { LightStage::INVALID_INDEX }; bool _needUpdate { true }; + bool _isVisible{ true }; }; namespace render {