mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 17:33:49 +02:00
pass the visibility of the enitity to the LightPaylkoad correctly, clean up the ambient shader
This commit is contained in:
parent
9a492b3a88
commit
6f2452815c
9 changed files with 54 additions and 43 deletions
|
@ -26,7 +26,7 @@
|
|||
#include "SoundCache.h"
|
||||
#include "AudioSRC.h"
|
||||
|
||||
//int audioInjectorPtrMetaTypeId = qRegisterMetaType<AudioInjector*>();
|
||||
int audioInjectorPtrMetaTypeId = qRegisterMetaType<AudioInjector*>();
|
||||
|
||||
AbstractAudioInterface* AudioInjector::_localAudioInterface{ nullptr };
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)@>
|
||||
|
||||
|
|
|
@ -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<DeferredLightingEffect>();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue