Showing the changes to libraries/render-utils/src/DeferredLightingEffect.cpp (1 of 1213 files). Show all
Unified · Split
| @@ -11,9 +11,12 @@ · 10 unmodified lines | |||
| 11 | 11 | ||
| 12 | #include "DeferredLightingEffect.h" | 12 | #include "DeferredLightingEffect.h" |
| 13 | 13 | ||
| 14 | #include <QtCore/QFileSelector> | ||
| 15 | |||
| 14 | #include <GLMHelpers.h> | 16 | #include <GLMHelpers.h> |
| 15 | #include <PathUtils.h> | 17 | #include <PathUtils.h> |
| 16 | #include <ViewFrustum.h> | 18 | #include <ViewFrustum.h> |
| 19 | #include <shared/FileUtils.h> | ||
| 17 | 20 | ||
| 18 | #include <gpu/Batch.h> | 21 | #include <gpu/Batch.h> |
| 19 | #include <gpu/Context.h> | 22 | #include <gpu/Context.h> |
| @@ -42,6 +45,7 @@ using namespace render; · 22 unmodified lines | |||
| 42 | 45 | ||
| 43 | struct LightLocations { | 46 | struct LightLocations { |
| 44 | int radius{ -1 }; | 47 | int radius{ -1 }; |
| 48 | int keyLightBufferUnit{ -1 }; | ||
| 45 | int lightBufferUnit{ -1 }; | 49 | int lightBufferUnit{ -1 }; |
| 46 | int ambientBufferUnit { -1 }; | 50 | int ambientBufferUnit { -1 }; |
| 47 | int lightIndexBufferUnit { -1 }; | 51 | int lightIndexBufferUnit { -1 }; |
| @@ -58,7 +62,7 @@ enum DeferredShader_MapSlot { · 10 unmodified lines | |||
| 58 | DEFERRED_BUFFER_DEPTH_UNIT = 3, | 62 | DEFERRED_BUFFER_DEPTH_UNIT = 3, |
| 59 | DEFERRED_BUFFER_OBSCURANCE_UNIT = 4, | 63 | DEFERRED_BUFFER_OBSCURANCE_UNIT = 4, |
| 60 | SHADOW_MAP_UNIT = 5, | 64 | SHADOW_MAP_UNIT = 5, |
| 61 | SKYBOX_MAP_UNIT = 6, | 65 | SKYBOX_MAP_UNIT = SHADOW_MAP_UNIT + SHADOW_CASCADE_MAX_COUNT, |
| 62 | DEFERRED_BUFFER_LINEAR_DEPTH_UNIT, | 66 | DEFERRED_BUFFER_LINEAR_DEPTH_UNIT, |
| 63 | DEFERRED_BUFFER_CURVATURE_UNIT, | 67 | DEFERRED_BUFFER_CURVATURE_UNIT, |
| 64 | DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT, | 68 | DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT, |
| @@ -71,15 +75,15 @@ enum DeferredShader_BufferSlot { · 6 unmodified lines | |||
| 71 | SCATTERING_PARAMETERS_BUFFER_SLOT, | 75 | SCATTERING_PARAMETERS_BUFFER_SLOT, |
| 72 | LIGHTING_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::LIGHTING_MODEL, | 76 | LIGHTING_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::LIGHTING_MODEL, |
| 73 | LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT, | 77 | LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT, |
| 74 | LIGHT_AMBIENT_SLOT, | 78 | LIGHT_AMBIENT_SLOT = render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER, |
| 79 | HAZE_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::HAZE_MODEL, | ||
| 75 | LIGHT_INDEX_GPU_SLOT, | 80 | LIGHT_INDEX_GPU_SLOT, |
| 76 | LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, | 81 | LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, |
| 77 | LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, | 82 | LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, |
| 78 | LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, | 83 | LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, |
| 79 | HAZE_MODEL_BUFFER_SLOT | ||
| 80 | }; | 84 | }; |
| 81 | 85 | ||
| 82 | static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); | 86 | static void loadLightProgram(const gpu::ShaderPointer& vertShader, const gpu::ShaderPointer& fragShader, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); |
| 83 | 87 | ||
| 84 | void DeferredLightingEffect::init() { | 88 | void DeferredLightingEffect::init() { |
| 85 | _directionalAmbientSphereLightLocations = std::make_shared<LightLocations>(); | 89 | _directionalAmbientSphereLightLocations = std::make_shared<LightLocations>(); |
| @@ -91,25 +95,25 @@ void DeferredLightingEffect::init() { · 5 unmodified lines | |||
| 91 | _localLightLocations = std::make_shared<LightLocations>(); | 95 | _localLightLocations = std::make_shared<LightLocations>(); |
| 92 | _localLightOutlineLocations = std::make_shared<LightLocations>(); | 96 | _localLightOutlineLocations = std::make_shared<LightLocations>(); |
| 93 | 97 | ||
| 94 | loadLightProgram(deferred_light_vert, directional_ambient_light_frag, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations); | 98 | loadLightProgram(deferred_light_vert::getShader(), directional_ambient_light_frag::getShader(), false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations); |
| 95 | loadLightProgram(deferred_light_vert, directional_skybox_light_frag, false, _directionalSkyboxLight, _directionalSkyboxLightLocations); | 99 | loadLightProgram(deferred_light_vert::getShader(), directional_skybox_light_frag::getShader(), false, _directionalSkyboxLight, _directionalSkyboxLightLocations); |
| 96 | 100 | ||
| 97 | loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_frag, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations); | 101 | loadLightProgram(deferred_light_vert::getShader(), directional_ambient_light_shadow_frag::getShader(), false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations); |
| 98 | loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); | 102 | loadLightProgram(deferred_light_vert::getShader(), directional_skybox_light_shadow_frag::getShader(), false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); |
| 99 | 103 | ||
| 100 | loadLightProgram(deferred_light_vert, local_lights_shading_frag, true, _localLight, _localLightLocations); | 104 | loadLightProgram(deferred_light_vert::getShader(), local_lights_shading_frag::getShader(), true, _localLight, _localLightLocations); |
| 101 | loadLightProgram(deferred_light_vert, local_lights_drawOutline_frag, true, _localLightOutline, _localLightOutlineLocations); | 105 | loadLightProgram(deferred_light_vert::getShader(), local_lights_drawOutline_frag::getShader(), true, _localLightOutline, _localLightOutlineLocations); |
| 102 | } | 106 | } |
| 103 | 107 | ||
| 104 | void DeferredLightingEffect::setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { | 108 | void DeferredLightingEffect::setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { |
| 105 | PerformanceTimer perfTimer("DLE->setupBatch()"); | 109 | PerformanceTimer perfTimer("DLE->setupBatch()"); |
| 106 | model::LightPointer keySunLight; | 110 | graphics::LightPointer keySunLight; |
| 107 | auto lightStage = args->_scene->getStage<LightStage>(); | 111 | auto lightStage = args->_scene->getStage<LightStage>(); |
| 108 | if (lightStage) { | 112 | if (lightStage) { |
| 109 | keySunLight = lightStage->getCurrentKeyLight(); | 113 | keySunLight = lightStage->getCurrentKeyLight(); |
| 110 | } | 114 | } |
| 111 | 115 | ||
| 112 | model::LightPointer keyAmbiLight; | 116 | graphics::LightPointer keyAmbiLight; |
| 113 | if (lightStage) { | 117 | if (lightStage) { |
| 114 | keyAmbiLight = lightStage->getCurrentAmbientLight(); | 118 | keyAmbiLight = lightStage->getCurrentAmbientLight(); |
| 115 | } | 119 | } |
| @@ -144,19 +148,38 @@ void DeferredLightingEffect::unsetKeyLightBatch(gpu::Batch& batch, int lightBuff · 28 unmodified lines | |||
| 144 | } | 148 | } |
| 145 | } | 149 | } |
| 146 | 150 | ||
| 147 | static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* fragSource, LightLocationsPtr& locations) { | 151 | void DeferredLightingEffect::setupLocalLightsBatch(gpu::Batch& batch, |
| 148 | auto VS = gpu::Shader::createVertex(std::string(vertSource)); | 152 | int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit, |
| 149 | auto PS = gpu::Shader::createPixel(std::string(fragSource)); | 153 | const LightClustersPointer& lightClusters) { |
| 150 | 154 | // Bind the global list of lights and the visible lights this frame | |
| 151 | gpu::ShaderPointer program = gpu::Shader::createProgram(VS, PS); | 155 | batch.setUniformBuffer(_localLightLocations->lightBufferUnit, lightClusters->_lightStage->getLightArrayBuffer()); |
| 156 | |||
| 157 | batch.setUniformBuffer(frustumGridBufferUnit, lightClusters->_frustumGridBuffer); | ||
| 158 | batch.setUniformBuffer(clusterGridBufferUnit, lightClusters->_clusterGridBuffer); | ||
| 159 | batch.setUniformBuffer(clusterContentBufferUnit, lightClusters->_clusterContentBuffer); | ||
| 160 | } | ||
| 152 | 161 | ||
| 162 | void DeferredLightingEffect::unsetLocalLightsBatch(gpu::Batch& batch, int clusterGridBufferUnit, int clusterContentBufferUnit, int frustumGridBufferUnit) { | ||
| 163 | if (clusterGridBufferUnit >= 0) { | ||
| 164 | batch.setUniformBuffer(clusterGridBufferUnit, nullptr); | ||
| 165 | } | ||
| 166 | if (clusterContentBufferUnit >= 0) { | ||
| 167 | batch.setUniformBuffer(clusterContentBufferUnit, nullptr); | ||
| 168 | } | ||
| 169 | if (frustumGridBufferUnit >= 0) { | ||
| 170 | batch.setUniformBuffer(frustumGridBufferUnit, nullptr); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | static gpu::ShaderPointer makeLightProgram(const gpu::ShaderPointer& vertShader, const gpu::ShaderPointer& fragShader, LightLocationsPtr& locations) { | ||
| 175 | gpu::ShaderPointer program = gpu::Shader::createProgram(vertShader, fragShader); | ||
| 153 | gpu::Shader::BindingSet slotBindings; | 176 | gpu::Shader::BindingSet slotBindings; |
| 154 | slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), DEFERRED_BUFFER_COLOR_UNIT)); | 177 | slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), DEFERRED_BUFFER_COLOR_UNIT)); |
| 155 | slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), DEFERRED_BUFFER_NORMAL_UNIT)); | 178 | slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), DEFERRED_BUFFER_NORMAL_UNIT)); |
| 156 | slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), DEFERRED_BUFFER_EMISSIVE_UNIT)); | 179 | slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), DEFERRED_BUFFER_EMISSIVE_UNIT)); |
| 157 | slotBindings.insert(gpu::Shader::Binding(std::string("depthMap"), DEFERRED_BUFFER_DEPTH_UNIT)); | 180 | slotBindings.insert(gpu::Shader::Binding(std::string("depthMap"), DEFERRED_BUFFER_DEPTH_UNIT)); |
| 158 | slotBindings.insert(gpu::Shader::Binding(std::string("obscuranceMap"), DEFERRED_BUFFER_OBSCURANCE_UNIT)); | 181 | slotBindings.insert(gpu::Shader::Binding(std::string("obscuranceMap"), DEFERRED_BUFFER_OBSCURANCE_UNIT)); |
| 159 | slotBindings.insert(gpu::Shader::Binding(std::string("shadowMap"), SHADOW_MAP_UNIT)); | 182 | slotBindings.insert(gpu::Shader::Binding(std::string("shadowMaps"), SHADOW_MAP_UNIT)); |
| 160 | slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), SKYBOX_MAP_UNIT)); | 183 | slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), SKYBOX_MAP_UNIT)); |
| 161 | 184 | ||
| 162 | slotBindings.insert(gpu::Shader::Binding(std::string("linearZeyeMap"), DEFERRED_BUFFER_LINEAR_DEPTH_UNIT)); | 185 | slotBindings.insert(gpu::Shader::Binding(std::string("linearZeyeMap"), DEFERRED_BUFFER_LINEAR_DEPTH_UNIT)); |
| @@ -186,6 +209,7 @@ static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* f · 23 unmodified lines | |||
| 186 | 209 | ||
| 187 | locations->texcoordFrameTransform = program->getUniforms().findLocation("texcoordFrameTransform"); | 210 | locations->texcoordFrameTransform = program->getUniforms().findLocation("texcoordFrameTransform"); |
| 188 | 211 | ||
| 212 | locations->keyLightBufferUnit = program->getUniformBuffers().findLocation("keyLightBuffer"); | ||
| 189 | locations->lightBufferUnit = program->getUniformBuffers().findLocation("lightBuffer"); | 213 | locations->lightBufferUnit = program->getUniformBuffers().findLocation("lightBuffer"); |
| 190 | locations->ambientBufferUnit = program->getUniformBuffers().findLocation("lightAmbientBuffer"); | 214 | locations->ambientBufferUnit = program->getUniformBuffers().findLocation("lightAmbientBuffer"); |
| 191 | locations->lightIndexBufferUnit = program->getUniformBuffers().findLocation("lightIndexBuffer"); | 215 | locations->lightIndexBufferUnit = program->getUniformBuffers().findLocation("lightIndexBuffer"); |
| @@ -196,9 +220,9 @@ static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* f · 4 unmodified lines | |||
| 196 | return program; | 220 | return program; |
| 197 | } | 221 | } |
| 198 | 222 | ||
| 199 | static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { | 223 | static void loadLightProgram(const gpu::ShaderPointer& vertShader, const gpu::ShaderPointer& fragShader, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { |
| 200 | 224 | ||
| 201 | gpu::ShaderPointer program = makeLightProgram(vertSource, fragSource, locations); | 225 | gpu::ShaderPointer program = makeLightProgram(vertShader, fragShader, locations); |
| 202 | 226 | ||
| 203 | auto state = std::make_shared<gpu::State>(); | 227 | auto state = std::make_shared<gpu::State>(); |
| 204 | state->setColorWriteMask(true, true, true, false); | 228 | state->setColorWriteMask(true, true, true, false); |
| @@ -229,9 +253,9 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo · 24 unmodified lines | |||
| 229 | 253 | ||
| 230 | #include <shared/Shapes.h> | 254 | #include <shared/Shapes.h> |
| 231 | 255 | ||
| 232 | model::MeshPointer DeferredLightingEffect::getPointLightMesh() { | 256 | graphics::MeshPointer DeferredLightingEffect::getPointLightMesh() { |
| 233 | if (!_pointLightMesh) { | 257 | if (!_pointLightMesh) { |
| 234 | _pointLightMesh = std::make_shared<model::Mesh>(); | 258 | _pointLightMesh = std::make_shared<graphics::Mesh>(); |
| 235 | 259 | ||
| 236 | // let's use a icosahedron | 260 | // let's use a icosahedron |
| 237 | auto solid = geometry::icosahedron(); | 261 | auto solid = geometry::icosahedron(); |
| @@ -256,19 +280,19 @@ model::MeshPointer DeferredLightingEffect::getPointLightMesh() { · 18 unmodified lines | |||
| 256 | delete[] indexData; | 280 | delete[] indexData; |
| 257 | 281 | ||
| 258 | 282 | ||
| 259 | std::vector<model::Mesh::Part> parts; | 283 | std::vector<graphics::Mesh::Part> parts; |
| 260 | parts.push_back(model::Mesh::Part(0, nbIndices, 0, model::Mesh::TRIANGLES)); | 284 | parts.push_back(graphics::Mesh::Part(0, nbIndices, 0, graphics::Mesh::TRIANGLES)); |
| 261 | parts.push_back(model::Mesh::Part(0, nbIndices, 0, model::Mesh::LINE_STRIP)); // outline version | 285 | parts.push_back(graphics::Mesh::Part(0, nbIndices, 0, graphics::Mesh::LINE_STRIP)); // outline version |
| 262 | 286 | ||
| 263 | 287 | ||
| 264 | _pointLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(model::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL)); | 288 | _pointLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(graphics::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL)); |
| 265 | } | 289 | } |
| 266 | return _pointLightMesh; | 290 | return _pointLightMesh; |
| 267 | } | 291 | } |
| 268 | 292 | ||
| 269 | model::MeshPointer DeferredLightingEffect::getSpotLightMesh() { | 293 | graphics::MeshPointer DeferredLightingEffect::getSpotLightMesh() { |
| 270 | if (!_spotLightMesh) { | 294 | if (!_spotLightMesh) { |
| 271 | _spotLightMesh = std::make_shared<model::Mesh>(); | 295 | _spotLightMesh = std::make_shared<graphics::Mesh>(); |
| 272 | 296 | ||
| 273 | int slices = 16; | 297 | int slices = 16; |
| 274 | int rings = 3; | 298 | int rings = 3; |
| @@ -353,12 +377,12 @@ model::MeshPointer DeferredLightingEffect::getSpotLightMesh() { · 78 unmodified lines | |||
| 353 | delete[] indexData; | 377 | delete[] indexData; |
| 354 | 378 | ||
| 355 | 379 | ||
| 356 | std::vector<model::Mesh::Part> parts; | 380 | std::vector<graphics::Mesh::Part> parts; |
| 357 | parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::TRIANGLES)); | 381 | parts.push_back(graphics::Mesh::Part(0, indices, 0, graphics::Mesh::TRIANGLES)); |
| 358 | parts.push_back(model::Mesh::Part(0, indices, 0, model::Mesh::LINE_STRIP)); // outline version | 382 | parts.push_back(graphics::Mesh::Part(0, indices, 0, graphics::Mesh::LINE_STRIP)); // outline version |
| 359 | 383 | ||
| 360 | 384 | ||
| 361 | _spotLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(model::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL)); | 385 | _spotLightMesh->setPartBuffer(gpu::BufferView(new gpu::Buffer(parts.size() * sizeof(graphics::Mesh::Part), (gpu::Byte*) parts.data()), gpu::Element::PART_DRAWCALL)); |
| 362 | } | 386 | } |
| 363 | return _spotLightMesh; | 387 | return _spotLightMesh; |
| 364 | } | 388 | } |
| @@ -439,7 +463,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, · 74 unmodified lines | |||
| 439 | const DeferredFrameTransformPointer& frameTransform, | 463 | const DeferredFrameTransformPointer& frameTransform, |
| 440 | const DeferredFramebufferPointer& deferredFramebuffer, | 464 | const DeferredFramebufferPointer& deferredFramebuffer, |
| 441 | const LightingModelPointer& lightingModel, | 465 | const LightingModelPointer& lightingModel, |
| 442 | const model::HazePointer& haze, | 466 | const graphics::HazePointer& haze, |
| 443 | const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer, | 467 | const SurfaceGeometryFramebufferPointer& surfaceGeometryFramebuffer, |
| 444 | const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer, | 468 | const AmbientOcclusionFramebufferPointer& ambientOcclusionFramebuffer, |
| 445 | const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource) { | 469 | const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource) { |
| @@ -501,9 +525,11 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, · 55 unmodified lines | |||
| 501 | auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow(); | 525 | auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow(); |
| 502 | const auto& globalShadow = lightAndShadow.second; | 526 | const auto& globalShadow = lightAndShadow.second; |
| 503 | 527 | ||
| 504 | // Bind the shadow buffer | 528 | // Bind the shadow buffers |
| 505 | if (globalShadow) { | 529 | if (globalShadow) { |
| 506 | batch.setResourceTexture(SHADOW_MAP_UNIT, globalShadow->map); | 530 | for (unsigned int i = 0; i < globalShadow->getCascadeCount(); i++) { |
| 531 | batch.setResourceTexture(SHADOW_MAP_UNIT+i, globalShadow->getCascade(i).map); | ||
| 532 | } | ||
| 507 | } | 533 | } |
| 508 | 534 | ||
| 509 | auto& program = deferredLightingEffect->_directionalSkyboxLight; | 535 | auto& program = deferredLightingEffect->_directionalSkyboxLight; |
| @@ -511,7 +537,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, · 1 unmodified line | |||
| 511 | 537 | ||
| 512 | auto keyLight = lightAndShadow.first; | 538 | auto keyLight = lightAndShadow.first; |
| 513 | 539 | ||
| 514 | model::LightPointer keyAmbientLight; | 540 | graphics::LightPointer keyAmbientLight; |
| 515 | if (lightStage && lightStage->_currentFrame._ambientLights.size()) { | 541 | if (lightStage && lightStage->_currentFrame._ambientLights.size()) { |
| 516 | keyAmbientLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front()); | 542 | keyAmbientLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front()); |
| 517 | } | 543 | } |
| @@ -556,19 +582,20 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, · 38 unmodified lines | |||
| 556 | batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); | 582 | batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); |
| 557 | 583 | ||
| 558 | // Setup the global lighting | 584 | // Setup the global lighting |
| 559 | deferredLightingEffect->setupKeyLightBatch(args, batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); | 585 | deferredLightingEffect->setupKeyLightBatch(args, batch, locations->keyLightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); |
| 560 | 586 | ||
| 561 | // Haze | 587 | // Haze |
| 562 | if (haze) { | 588 | if (haze) { |
| 563 | batch.setUniformBuffer(HAZE_MODEL_BUFFER_SLOT, haze->getHazeParametersBuffer()); | 589 | batch.setUniformBuffer(HAZE_MODEL_BUFFER_SLOT, haze->getHazeParametersBuffer()); |
| 564 | } | 590 | } |
| 565 | 591 | ||
| 566 | batch.draw(gpu::TRIANGLE_STRIP, 4); | 592 | batch.draw(gpu::TRIANGLE_STRIP, 4); |
| 567 | 593 | ||
| 568 | deferredLightingEffect->unsetKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); | 594 | deferredLightingEffect->unsetKeyLightBatch(batch, locations->keyLightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); |
| 569 | |||
| 570 | 595 | ||
| 571 | batch.setResourceTexture(SHADOW_MAP_UNIT, nullptr); | 596 | for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) { |
| 597 | batch.setResourceTexture(SHADOW_MAP_UNIT+i, nullptr); | ||
| 598 | } | ||
| 572 | } | 599 | } |
| 573 | } | 600 | } |
| 574 | 601 | ||
| @@ -619,12 +646,8 @@ void RenderDeferredLocals::run(const render::RenderContextPointer& renderContext · 44 unmodified lines | |||
| 619 | 646 | ||
| 620 | auto& lightIndices = lightClusters->_visibleLightIndices; | 647 | auto& lightIndices = lightClusters->_visibleLightIndices; |
| 621 | if (!lightIndices.empty() && lightIndices[0] > 0) { | 648 | if (!lightIndices.empty() && lightIndices[0] > 0) { |
| 622 | // Bind the global list of lights and the visible lights this frame | 649 | deferredLightingEffect->setupLocalLightsBatch(batch, LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, |
| 623 | batch.setUniformBuffer(deferredLightingEffect->_localLightLocations->lightBufferUnit, lightClusters->_lightStage->getLightArrayBuffer()); | 650 | lightClusters); |
| 624 | |||
| 625 | batch.setUniformBuffer(LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, lightClusters->_frustumGridBuffer); | ||
| 626 | batch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, lightClusters->_clusterGridBuffer); | ||
| 627 | batch.setUniformBuffer(LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, lightClusters->_clusterContentBuffer); | ||
| 628 | 651 | ||
| 629 | // Local light pipeline | 652 | // Local light pipeline |
| 630 | batch.setPipeline(deferredLightingEffect->_localLight); | 653 | batch.setPipeline(deferredLightingEffect->_localLight); |
| @@ -726,11 +749,11 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { · 95 unmodified lines | |||
| 726 | auto textureCache = DependencyManager::get<TextureCache>(); | 749 | auto textureCache = DependencyManager::get<TextureCache>(); |
| 727 | { | 750 | { |
| 728 | PROFILE_RANGE(render, "Process Default Skybox"); | 751 | PROFILE_RANGE(render, "Process Default Skybox"); |
| 729 | auto textureCache = DependencyManager::get<TextureCache>(); | 752 | QFileSelector fileSelector; |
| 730 | 753 | fileSelector.setExtraSelectors(FileUtils::getFileSelectors()); | |
| 731 | auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx"; | 754 | auto skyboxUrl = fileSelector.select(PathUtils::resourcesPath() + "images/Default-Sky-9-cubemap.ktx"); |
| 732 | 755 | ||
| 733 | _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl); | 756 | _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl.toStdString()); |
| 734 | _defaultSkyboxAmbientTexture = _defaultSkyboxTexture; | 757 | _defaultSkyboxAmbientTexture = _defaultSkyboxTexture; |
| 735 | 758 | ||
| 736 | _defaultSkybox->setCubemap(_defaultSkyboxTexture); | 759 | _defaultSkybox->setCubemap(_defaultSkyboxTexture); |
| @@ -741,12 +764,12 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { · 4 unmodified lines | |||
| 741 | if (lightStage) { | 764 | if (lightStage) { |
| 742 | 765 | ||
| 743 | // Allocate a default global light directional and ambient | 766 | // Allocate a default global light directional and ambient |
| 744 | auto lp = std::make_shared<model::Light>(); | 767 | auto lp = std::make_shared<graphics::Light>(); |
| 745 | lp->setType(model::Light::SUN); | 768 | lp->setType(graphics::Light::SUN); |
| 746 | lp->setDirection(glm::vec3(-1.0f)); | 769 | lp->setDirection(glm::vec3(-1.0f)); |
| 747 | lp->setColor(glm::vec3(1.0f)); | 770 | lp->setColor(glm::vec3(1.0f)); |
| 748 | lp->setIntensity(1.0f); | 771 | lp->setIntensity(1.0f); |
| 749 | lp->setType(model::Light::SUN); | 772 | lp->setType(graphics::Light::SUN); |
| 750 | lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE); | 773 | lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE); |
| 751 | 774 | ||
| 752 | lp->setAmbientIntensity(0.5f); | 775 | lp->setAmbientIntensity(0.5f); |
| @@ -760,14 +783,15 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { · 7 unmodified lines | |||
| 760 | _defaultLight = lp; | 783 | _defaultLight = lp; |
| 761 | 784 | ||
| 762 | // Add the global light to the light stage (for later shadow rendering) | 785 | // Add the global light to the light stage (for later shadow rendering) |
| 763 | _defaultLightID = lightStage->addLight(lp); | 786 | // Set this light to be the default |
| 787 | _defaultLightID = lightStage->addLight(lp, true); | ||
| 764 | lightStage->addShadow(_defaultLightID); | 788 | lightStage->addShadow(_defaultLightID); |
| 765 | } | 789 | } |
| 766 | 790 | ||
| 767 | auto backgroundStage = renderContext->_scene->getStage<BackgroundStage>(); | 791 | auto backgroundStage = renderContext->_scene->getStage<BackgroundStage>(); |
| 768 | if (backgroundStage) { | 792 | if (backgroundStage) { |
| 769 | 793 | ||
| 770 | auto background = std::make_shared<model::SunSkyStage>(); | 794 | auto background = std::make_shared<graphics::SunSkyStage>(); |
| 771 | background->setSkybox(_defaultSkybox); | 795 | background->setSkybox(_defaultSkybox); |
| 772 | 796 | ||
| 773 | // capture deault background | 797 | // capture deault background |
| @@ -782,7 +806,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { · 8 unmodified lines | |||
| 782 | auto hazeStage = renderContext->_scene->getStage<HazeStage>(); | 806 | auto hazeStage = renderContext->_scene->getStage<HazeStage>(); |
| 783 | if (hazeStage) { | 807 | if (hazeStage) { |
| 784 | 808 | ||
| 785 | auto haze = std::make_shared<model::Haze>(); | 809 | auto haze = std::make_shared<graphics::Haze>(); |
| 786 | 810 | ||
| 787 | _defaultHaze = haze; | 811 | _defaultHaze = haze; |
| 788 | _defaultHazeID = hazeStage->addHaze(_defaultHaze); | 812 | _defaultHazeID = hazeStage->addHaze(_defaultHaze); |