History

Fixing differing highlights between left and right eyes in stereo modes

Brad Davis committed 11 years ago

Commit 1bb15e21 parent d189fb95 files · +107 −73Browse files

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

Unified · Split

libraries/render-utils/src/DeferredLightingEffect.cpp+77−42
@@ -50,6 +50,26 @@ · 49 unmodified lines
5050
5151 static const std::string glowIntensityShaderHandle = "glowIntensity";
5252
53+struct LightLocations {
54+ int shadowDistances;
55+ int shadowScale;
56+ int nearLocation;
57+ int depthScale;
58+ int depthTexCoordOffset;
59+ int depthTexCoordScale;
60+ int radius;
61+ int ambientSphere;
62+ int lightBufferUnit;
63+ int atmosphereBufferUnit;
64+ int invViewMat;
65+ int texcoordMat;
66+ int coneParam;
67+ int stereo;
68+};
69+
70+static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations);
71+
72+
5373 gpu::PipelinePointer DeferredLightingEffect::getPipeline(SimpleProgramKey config) {
5474 auto it = _simplePrograms.find(config);
5575 if (it != _simplePrograms.end()) {
@@ -91,6 +111,18 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { · 35 unmodified lines
91111 gpu::Shader::makeProgram(*_emissiveShader, slotBindings);
92112
93113 _viewState = viewState;
114+ _directionalLightLocations = std::make_shared<LightLocations>();
115+ _directionalLightShadowMapLocations = std::make_shared<LightLocations>();
116+ _directionalLightCascadedShadowMapLocations = std::make_shared<LightLocations>();
117+ _directionalAmbientSphereLightLocations = std::make_shared<LightLocations>();
118+ _directionalAmbientSphereLightShadowMapLocations = std::make_shared<LightLocations>();
119+ _directionalAmbientSphereLightCascadedShadowMapLocations = std::make_shared<LightLocations>();
120+ _directionalSkyboxLightLocations = std::make_shared<LightLocations>();
121+ _directionalSkyboxLightShadowMapLocations = std::make_shared<LightLocations>();
122+ _directionalSkyboxLightCascadedShadowMapLocations = std::make_shared<LightLocations>();
123+ _pointLightLocations = std::make_shared<LightLocations>();
124+ _spotLightLocations = std::make_shared<LightLocations>();
125+
94126 loadLightProgram(deferred_light_vert, directional_light_frag, false, _directionalLight, _directionalLightLocations);
95127 loadLightProgram(deferred_light_vert, directional_light_shadow_map_frag, false, _directionalLightShadowMap,
96128 _directionalLightShadowMapLocations);
@@ -282,7 +314,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 185 unmodified lines
282314 invViewMat = args->_viewFrustum->getView();
283315
284316 auto& program = _directionalLight;
285− const LightLocations* locations = &_directionalLightLocations;
317+ LightLocationsPtr locations = _directionalLightLocations;
286318
287319 // FIXME: Note: we've removed the menu items to enable shadows, so this will always be false for now.
288320 // When we add back shadow support, this old approach may likely be removed and completely replaced
@@ -294,16 +326,16 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 5 unmodified lines
294326 batch.setResourceTexture(4, framebufferCache->getShadowFramebuffer()->getDepthStencilBuffer());
295327
296328 program = _directionalLightShadowMap;
297− locations = &_directionalLightShadowMapLocations;
329+ locations = _directionalLightShadowMapLocations;
298330 if (cascadeShadowsEnabled) {
299331 program = _directionalLightCascadedShadowMap;
300− locations = &_directionalLightCascadedShadowMapLocations;
332+ locations = _directionalLightCascadedShadowMapLocations;
301333 if (useSkyboxCubemap) {
302334 program = _directionalSkyboxLightCascadedShadowMap;
303− locations = &_directionalSkyboxLightCascadedShadowMapLocations;
335+ locations = _directionalSkyboxLightCascadedShadowMapLocations;
304336 } else if (_ambientLightMode > -1) {
305337 program = _directionalAmbientSphereLightCascadedShadowMap;
306− locations = &_directionalAmbientSphereLightCascadedShadowMapLocations;
338+ locations = _directionalAmbientSphereLightCascadedShadowMapLocations;
307339 }
308340 batch.setPipeline(program);
309341 batch._glUniform3fv(locations->shadowDistances, 1, (const float*) &_viewState->getShadowDistances());
@@ -311,10 +343,10 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 1 unmodified line
311343 } else {
312344 if (useSkyboxCubemap) {
313345 program = _directionalSkyboxLightShadowMap;
314− locations = &_directionalSkyboxLightShadowMapLocations;
346+ locations = _directionalSkyboxLightShadowMapLocations;
315347 } else if (_ambientLightMode > -1) {
316348 program = _directionalAmbientSphereLightShadowMap;
317− locations = &_directionalAmbientSphereLightShadowMapLocations;
349+ locations = _directionalAmbientSphereLightShadowMapLocations;
318350 }
319351 batch.setPipeline(program);
320352 }
@@ -323,10 +355,10 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 2 unmodified lines
323355 } else {
324356 if (useSkyboxCubemap) {
325357 program = _directionalSkyboxLight;
326− locations = &_directionalSkyboxLightLocations;
358+ locations = _directionalSkyboxLightLocations;
327359 } else if (_ambientLightMode > -1) {
328360 program = _directionalAmbientSphereLight;
329− locations = &_directionalAmbientSphereLightLocations;
361+ locations = _directionalAmbientSphereLightLocations;
330362 }
331363 batch.setPipeline(program);
332364 }
@@ -374,7 +406,9 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 41 unmodified lines
374406 float depthTexCoordOffsetT = bottom * nearScale - tMin * depthTexCoordScaleT;
375407 batch._glUniform2f(locations->depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
376408 batch._glUniform2f(locations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
377−
409+ bool stereo = args->_context->isStereo();
410+ batch._glUniform1f(locations->stereo, stereo ? 1 : 0);
411+
378412 {
379413 Transform model;
380414 model.setTranslation(glm::vec3(sMin, tMin, 0.0));
@@ -427,20 +461,20 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 46 unmodified lines
427461
428462 if (!_pointLights.empty()) {
429463 batch.setPipeline(_pointLight);
430− batch._glUniform1f(_pointLightLocations.nearLocation, nearVal);
431− batch._glUniform1f(_pointLightLocations.depthScale, depthScale);
432− batch._glUniform2f(_pointLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
433− batch._glUniform2f(_pointLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
464+ batch._glUniform1f(_pointLightLocations->nearLocation, nearVal);
465+ batch._glUniform1f(_pointLightLocations->depthScale, depthScale);
466+ batch._glUniform2f(_pointLightLocations->depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
467+ batch._glUniform2f(_pointLightLocations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
434468
435− batch._glUniformMatrix4fv(_pointLightLocations.invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
469+ batch._glUniformMatrix4fv(_pointLightLocations->invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
436470
437− batch._glUniformMatrix4fv(_pointLightLocations.texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
471+ batch._glUniformMatrix4fv(_pointLightLocations->texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
438472
439473 for (auto lightID : _pointLights) {
440474 auto& light = _allocatedLights[lightID];
441475 // IN DEBUG: light->setShowContour(true);
442− if (_pointLightLocations.lightBufferUnit >= 0) {
443− batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer());
476+ if (_pointLightLocations->lightBufferUnit >= 0) {
477+ batch.setUniformBuffer(_pointLightLocations->lightBufferUnit, light->getSchemaBuffer());
444478 }
445479
446480 float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION);
@@ -475,20 +509,20 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 28 unmodified lines
475509
476510 if (!_spotLights.empty()) {
477511 batch.setPipeline(_spotLight);
478− batch._glUniform1f(_spotLightLocations.nearLocation, nearVal);
479− batch._glUniform1f(_spotLightLocations.depthScale, depthScale);
480− batch._glUniform2f(_spotLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
481− batch._glUniform2f(_spotLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
512+ batch._glUniform1f(_spotLightLocations->nearLocation, nearVal);
513+ batch._glUniform1f(_spotLightLocations->depthScale, depthScale);
514+ batch._glUniform2f(_spotLightLocations->depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
515+ batch._glUniform2f(_spotLightLocations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
482516
483− batch._glUniformMatrix4fv(_spotLightLocations.invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
517+ batch._glUniformMatrix4fv(_spotLightLocations->invViewMat, 1, false, reinterpret_cast< const float* >(&invViewMat));
484518
485− batch._glUniformMatrix4fv(_spotLightLocations.texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
519+ batch._glUniformMatrix4fv(_spotLightLocations->texcoordMat, 1, false, reinterpret_cast< const float* >(&texcoordMat));
486520
487521 for (auto lightID : _spotLights) {
488522 auto light = _allocatedLights[lightID];
489523 // IN DEBUG: light->setShowContour(true);
490524
491− batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer());
525+ batch.setUniformBuffer(_spotLightLocations->lightBufferUnit, light->getSchemaBuffer());
492526
493527 auto eyeLightPos = eyePoint - light->getPosition();
494528 auto eyeHalfPlaneDistance = glm::dot(eyeLightPos, light->getDirection());
@@ -502,7 +536,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 7 unmodified lines
502536 if ((eyeHalfPlaneDistance > -nearRadius) &&
503537 (glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius)) {
504538 coneParam.w = 0.0f;
505− batch._glUniform4fv(_spotLightLocations.coneParam, 1, reinterpret_cast< const float* >(&coneParam));
539+ batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam));
506540
507541 Transform model;
508542 model.setTranslation(glm::vec3(0.0f, 0.0f, -1.0f));
@@ -522,7 +556,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { · 13 unmodified lines
522556 batch.setViewTransform(viewMat);
523557 } else {
524558 coneParam.w = 1.0f;
525− batch._glUniform4fv(_spotLightLocations.coneParam, 1, reinterpret_cast< const float* >(&coneParam));
559+ batch._glUniform4fv(_spotLightLocations->coneParam, 1, reinterpret_cast< const float* >(&coneParam));
526560
527561 Transform model;
528562 model.setTranslation(light->getPosition());
@@ -596,7 +630,7 @@ void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferU · 67 unmodified lines
596630 args->_batch->setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer());
597631 }
598632
599−void DeferredLightingEffect::loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocations& locations) {
633+static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) {
600634 auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(vertSource)));
601635 auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(fragSource)));
602636
@@ -616,20 +650,21 @@ void DeferredLightingEffect::loadLightProgram(const char* vertSource, const char · 13 unmodified lines
616650
617651 gpu::Shader::makeProgram(*program, slotBindings);
618652
619− locations.shadowDistances = program->getUniforms().findLocation("shadowDistances");
620− locations.shadowScale = program->getUniforms().findLocation("shadowScale");
621− locations.nearLocation = program->getUniforms().findLocation("near");
622− locations.depthScale = program->getUniforms().findLocation("depthScale");
623− locations.depthTexCoordOffset = program->getUniforms().findLocation("depthTexCoordOffset");
624− locations.depthTexCoordScale = program->getUniforms().findLocation("depthTexCoordScale");
625− locations.radius = program->getUniforms().findLocation("radius");
626− locations.ambientSphere = program->getUniforms().findLocation("ambientSphere.L00");
627− locations.invViewMat = program->getUniforms().findLocation("invViewMat");
628− locations.texcoordMat = program->getUniforms().findLocation("texcoordMat");
629− locations.coneParam = program->getUniforms().findLocation("coneParam");
630−
631− locations.lightBufferUnit = program->getBuffers().findLocation("lightBuffer");
632− locations.atmosphereBufferUnit = program->getBuffers().findLocation("atmosphereBufferUnit");
653+ locations->stereo = program->getUniforms().findLocation("stereoMode");
654+ locations->shadowDistances = program->getUniforms().findLocation("shadowDistances");
655+ locations->shadowScale = program->getUniforms().findLocation("shadowScale");
656+ locations->nearLocation = program->getUniforms().findLocation("near");
657+ locations->depthScale = program->getUniforms().findLocation("depthScale");
658+ locations->depthTexCoordOffset = program->getUniforms().findLocation("depthTexCoordOffset");
659+ locations->depthTexCoordScale = program->getUniforms().findLocation("depthTexCoordScale");
660+ locations->radius = program->getUniforms().findLocation("radius");
661+ locations->ambientSphere = program->getUniforms().findLocation("ambientSphere.L00");
662+ locations->invViewMat = program->getUniforms().findLocation("invViewMat");
663+ locations->texcoordMat = program->getUniforms().findLocation("texcoordMat");
664+ locations->coneParam = program->getUniforms().findLocation("coneParam");
665+
666+ locations->lightBufferUnit = program->getBuffers().findLocation("lightBuffer");
667+ locations->atmosphereBufferUnit = program->getBuffers().findLocation("atmosphereBufferUnit");
633668
634669 auto state = std::make_shared<gpu::State>();
635670 if (lightVolume) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t