Showing the changes to libraries/render-utils/src/DeferredLightingEffect.cpp (1 of 7 files). Show all
Unified · Split
| @@ -343,6 +343,8 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo · 342 unmodified lines | ||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | { // Setup the global lighting |
| 346 | + setupKeyLightBatch(batch, locations->lightBufferUnit, SKYBOX_MAP_UNIT); | |
| 347 | + /* | |
| 346 | 348 | auto globalLight = _allocatedLights[_globalLights.front()]; |
| 347 | 349 | |
| 348 | 350 | if (locations->ambientSphere >= 0) { |
| @@ -361,7 +363,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo · 12 unmodified lines | ||
| 361 | 363 | |
| 362 | 364 | if (locations->lightBufferUnit >= 0) { |
| 363 | 365 | batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer()); |
| 364 | − } | |
| 366 | + }*/ | |
| 365 | 367 | |
| 366 | 368 | } |
| 367 | 369 | |
| @@ -511,10 +513,29 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo · 143 unmodified lines | ||
| 511 | 513 | } |
| 512 | 514 | } |
| 513 | 515 | |
| 514 | −void DeferredLightingEffect::setupBatch(gpu::Batch& batch, int lightBufferUnit) { | |
| 516 | +void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit) { | |
| 515 | 517 | PerformanceTimer perfTimer("DLE->setupBatch()"); |
| 516 | 518 | auto globalLight = _allocatedLights[_globalLights.front()]; |
| 517 | − batch.setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); | |
| 519 | + | |
| 520 | + if (lightBufferUnit >= 0) { | |
| 521 | + batch.setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); | |
| 522 | + } | |
| 523 | + | |
| 524 | + bool useSkyboxCubemap = (_skybox) && (_skybox->getCubemap()); | |
| 525 | + | |
| 526 | + /* if (ambientSphereBufferUnit >= 0) { | |
| 527 | + gpu::SphericalHarmonics sh = globalLight->getAmbientSphere(); | |
| 528 | + if (useSkyboxCubemap && _skybox->getCubemap()->getIrradiance()) { | |
| 529 | + sh = (*_skybox->getCubemap()->getIrradiance()); | |
| 530 | + } | |
| 531 | + for (int i =0; i <gpu::SphericalHarmonics::NUM_COEFFICIENTS; i++) { | |
| 532 | + batch._glUniform4fv(ambientSphereBufferUnit + i, 1, (const float*)(&sh) + i * 4); | |
| 533 | + } | |
| 534 | + }*/ | |
| 535 | + | |
| 536 | + if (useSkyboxCubemap && (skyboxCubemapUnit >= 0)) { | |
| 537 | + batch.setResourceTexture(skyboxCubemapUnit, _skybox->getCubemap()); | |
| 538 | + } | |
| 518 | 539 | } |
| 519 | 540 | |
| 520 | 541 | static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { |
| @@ -593,6 +614,11 @@ void DeferredLightingEffect::setGlobalLight(const glm::vec3& direction, const gl · 72 unmodified lines | ||
| 593 | 614 | |
| 594 | 615 | void DeferredLightingEffect::setGlobalSkybox(const model::SkyboxPointer& skybox) { |
| 595 | 616 | _skybox = skybox; |
| 617 | + auto light = _allocatedLights.front(); | |
| 618 | + | |
| 619 | + if (_skybox && _skybox->getCubemap() && _skybox->getCubemap()->isDefined() && _skybox->getCubemap()->getIrradiance()) { | |
| 620 | + light->setAmbientSphere( (*_skybox->getCubemap()->getIrradiance()) ); | |
| 621 | + } | |
| 596 | 622 | } |
| 597 | 623 | |
| 598 | 624 | model::MeshPointer DeferredLightingEffect::getSpotLightMesh() { |