History

Trying to solve the ambient issue

samcake committed 10 years ago

Commit 4559e751 parent 9e3a1377 files · +89 −56Browse files

Showing the changes to libraries/render-utils/src/DeferredLightingEffect.cpp (1 of 7 files). Show all

Unified · Split

libraries/render-utils/src/DeferredLightingEffect.cpp+29−3
@@ -343,6 +343,8 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo · 342 unmodified lines
343343 }
344344
345345 { // Setup the global lighting
346+ setupKeyLightBatch(batch, locations->lightBufferUnit, SKYBOX_MAP_UNIT);
347+ /*
346348 auto globalLight = _allocatedLights[_globalLights.front()];
347349
348350 if (locations->ambientSphere >= 0) {
@@ -361,7 +363,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo · 12 unmodified lines
361363
362364 if (locations->lightBufferUnit >= 0) {
363365 batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer());
364− }
366+ }*/
365367
366368 }
367369
@@ -511,10 +513,29 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo · 143 unmodified lines
511513 }
512514 }
513515
514−void DeferredLightingEffect::setupBatch(gpu::Batch& batch, int lightBufferUnit) {
516+void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit) {
515517 PerformanceTimer perfTimer("DLE->setupBatch()");
516518 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+ }
518539 }
519540
520541 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
593614
594615 void DeferredLightingEffect::setGlobalSkybox(const model::SkyboxPointer& skybox) {
595616 _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+ }
596622 }
597623
598624 model::MeshPointer DeferredLightingEffect::getSpotLightMesh() {