Showing the changes to libraries/render-utils/src/DeferredLightingEffect.cpp (1 of 5 files). Show all
Unified · Split
| @@ -97,7 +97,7 @@ void DeferredLightingEffect::init() { · 96 unmodified lines | ||
| 97 | 97 | loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); |
| 98 | 98 | |
| 99 | 99 | loadLightProgram(deferred_light_limited_vert, point_light_frag, true, _pointLight, _pointLightLocations); |
| 100 | − loadLightProgram(deferred_light_spot_vert, spot_light_frag, true, _spotLight, _spotLightLocations); | |
| 100 | + loadLightProgram(deferred_light_vert, spot_light_frag, false, _spotLight, _spotLightLocations); | |
| 101 | 101 | |
| 102 | 102 | // Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light |
| 103 | 103 | _allocatedLights.push_back(std::make_shared<model::Light>()); |
| @@ -571,6 +571,11 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c · 467 unmodified lines | ||
| 571 | 571 | |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | +RenderDeferredLocals::RenderDeferredLocals() : | |
| 575 | +_spotLightsBuffer(std::make_shared<gpu::Buffer>()) { | |
| 576 | + | |
| 577 | +} | |
| 578 | + | |
| 574 | 579 | void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, |
| 575 | 580 | const DeferredFrameTransformPointer& frameTransform, |
| 576 | 581 | const DeferredFramebufferPointer& deferredFramebuffer, |
| @@ -585,6 +590,8 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, · 8 unmodified lines | ||
| 585 | 590 | } |
| 586 | 591 | auto args = renderContext->args; |
| 587 | 592 | gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { |
| 593 | + // Framebuffer copy operations cannot function as multipass stereo operations. | |
| 594 | + batch.enableStereo(false); | |
| 588 | 595 | |
| 589 | 596 | // THe main viewport is assumed to be the mono viewport (or the 2 stereo faces side by side within that viewport) |
| 590 | 597 | auto viewport = args->_viewport; |
| @@ -609,9 +616,46 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, · 18 unmodified lines | ||
| 609 | 616 | |
| 610 | 617 | auto textureFrameTransform = gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(deferredFramebuffer->getFrameSize(), viewport); |
| 611 | 618 | |
| 612 | − batch.setProjectionTransform(projMat); | |
| 613 | − batch.setViewTransform(viewTransform, true); | |
| 619 | + // batch.setProjectionTransform(projMat); | |
| 620 | + // batch.setViewTransform(viewTransform, true); | |
| 621 | + | |
| 622 | + // gather lights | |
| 623 | + auto& srcPointLights = deferredLightingEffect->_pointLights; | |
| 624 | + auto& srcSpotLights = deferredLightingEffect->_spotLights; | |
| 625 | + std::vector<int> lightIndices(srcPointLights.size() + srcSpotLights.size() + 1); | |
| 626 | + lightIndices[0] = 0; | |
| 627 | + | |
| 628 | + if (points && !srcPointLights.empty()) { | |
| 629 | + memcpy(lightIndices.data() + (lightIndices[0] + 1), srcPointLights.data(), srcPointLights.size() * sizeof(int)); | |
| 630 | + lightIndices[0] += srcPointLights.size(); | |
| 631 | + } | |
| 632 | + if (spots && !srcSpotLights.empty()) { | |
| 633 | + memcpy(lightIndices.data() + (lightIndices[0] + 1), srcSpotLights.data(), srcSpotLights.size() * sizeof(int)); | |
| 634 | + lightIndices[0] += srcSpotLights.size(); | |
| 635 | + } | |
| 636 | + | |
| 637 | + if (lightIndices[0] > 0) { | |
| 638 | + _spotLightsBuffer._buffer->setData(lightIndices.size() * sizeof(int), (const gpu::Byte*) lightIndices.data()); | |
| 639 | + _spotLightsBuffer._size = lightIndices.size() * sizeof(int); | |
| 640 | + | |
| 641 | + // Spot light pipeline | |
| 642 | + batch.setPipeline(deferredLightingEffect->_spotLight); | |
| 643 | + batch._glUniform4fv(deferredLightingEffect->_spotLightLocations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); | |
| 644 | + | |
| 645 | + // Spot mesh | |
| 646 | + auto mesh = deferredLightingEffect->getSpotLightMesh(); | |
| 647 | + batch.setIndexBuffer(mesh->getIndexBuffer()); | |
| 648 | + batch.setInputBuffer(0, mesh->getVertexBuffer()); | |
| 649 | + batch.setInputFormat(mesh->getVertexFormat()); | |
| 650 | + auto& conePart = mesh->getPartBuffer().get<model::Mesh::Part>(0); | |
| 651 | + | |
| 652 | + | |
| 653 | + batch.setUniformBuffer(deferredLightingEffect->_spotLightLocations->lightBufferUnit, deferredLightingEffect->getLightStage()._lightArrayBuffer); | |
| 654 | + batch.setUniformBuffer(deferredLightingEffect->_spotLightLocations->lightIndexBufferUnit, _spotLightsBuffer); | |
| 655 | + // batch.drawIndexedInstanced(deferredLightingEffect->_spotLights.size(), model::Mesh::topologyToPrimitive(conePart._topology), conePart._numIndices, conePart._startIndex); | |
| 614 | 656 | |
| 657 | + batch.draw(gpu::TRIANGLE_STRIP, 4); | |
| 658 | + /* | |
| 615 | 659 | // Splat Point lights |
| 616 | 660 | if (points && !deferredLightingEffect->_pointLights.empty()) { |
| 617 | 661 | // POint light pipeline |
| @@ -645,9 +689,11 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, · 27 unmodified lines | ||
| 645 | 689 | |
| 646 | 690 | // Splat spot lights |
| 647 | 691 | if (spots && !deferredLightingEffect->_spotLights.empty()) { |
| 648 | − | |
| 649 | − | |
| 650 | − _spotLightsBuffer._buffer->setData(deferredLightingEffect->_spotLights.size() * sizeof(int), (const gpu::Byte*) deferredLightingEffect->_spotLights.data()); | |
| 692 | + std::vector<int> again(deferredLightingEffect->_spotLights.size() + 1); | |
| 693 | + again[0] = deferredLightingEffect->_spotLights.size(); | |
| 694 | + memcpy(again.data() + 1, deferredLightingEffect->_spotLights.data(), deferredLightingEffect->_spotLights.size() * sizeof(int)); | |
| 695 | + _spotLightsBuffer._buffer->setData(again.size() * sizeof(int), (const gpu::Byte*) again.data()); | |
| 696 | + _spotLightsBuffer._size = again.size() * sizeof(int); | |
| 651 | 697 | |
| 652 | 698 | // Spot light pipeline |
| 653 | 699 | batch.setPipeline(deferredLightingEffect->_spotLight); |
| @@ -663,7 +709,9 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, · 9 unmodified lines | ||
| 663 | 709 | |
| 664 | 710 | batch.setUniformBuffer(deferredLightingEffect->_spotLightLocations->lightBufferUnit, deferredLightingEffect->getLightStage()._lightArrayBuffer); |
| 665 | 711 | batch.setUniformBuffer(deferredLightingEffect->_spotLightLocations->lightIndexBufferUnit, _spotLightsBuffer); |
| 666 | − batch.drawIndexedInstanced(deferredLightingEffect->_spotLights.size(), model::Mesh::topologyToPrimitive(conePart._topology), conePart._numIndices, conePart._startIndex); | |
| 712 | + // batch.drawIndexedInstanced(deferredLightingEffect->_spotLights.size(), model::Mesh::topologyToPrimitive(conePart._topology), conePart._numIndices, conePart._startIndex); | |
| 713 | + | |
| 714 | + batch.draw(gpu::TRIANGLE_STRIP, 4); | |
| 667 | 715 | /* |
| 668 | 716 | for (auto lightID : deferredLightingEffect->_spotLights) { |
| 669 | 717 | auto light = deferredLightingEffect->getLightStage().getLight(lightID); |