From 5e351c032896b6b5d47c25925ebb732d9b860c58 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 8 Jun 2015 18:36:12 +0200 Subject: [PATCH] FIxing the transparent rendering on Mac --- libraries/gpu/src/gpu/GLBackend.h | 16 ++++++++++------ libraries/gpu/src/gpu/GLBackendPipeline.cpp | 3 +-- .../render-utils/src/DeferredLightingEffect.cpp | 4 ++-- .../render-utils/src/DeferredLightingEffect.h | 2 +- libraries/render-utils/src/Model.cpp | 8 ++++++++ libraries/render-utils/src/Model.h | 1 + .../render-utils/src/RenderDeferredTask.cpp | 2 +- libraries/render-utils/src/model_translucent.slf | 8 +++++--- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 48262c9fe4..e7a5e62df8 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -292,14 +292,18 @@ protected: _lastMode(GL_TEXTURE) {} } _transform; - // Pipeline Stage - void do_setPipeline(Batch& batch, uint32 paramOffset); - - void do_setStateBlendFactor(Batch& batch, uint32 paramOffset); - + // Uniform Stage void do_setUniformBuffer(Batch& batch, uint32 paramOffset); void do_setUniformTexture(Batch& batch, uint32 paramOffset); - + + struct UniformStageState { + + }; + + // Pipeline Stage + void do_setPipeline(Batch& batch, uint32 paramOffset); + void do_setStateBlendFactor(Batch& batch, uint32 paramOffset); + // Standard update pipeline check that the current Program and current State or good to go for a void updatePipeline(); // Force to reset all the state fields indicated by the 'toBeReset" signature diff --git a/libraries/gpu/src/gpu/GLBackendPipeline.cpp b/libraries/gpu/src/gpu/GLBackendPipeline.cpp index 5e8cb56d9e..f4449e9ea1 100755 --- a/libraries/gpu/src/gpu/GLBackendPipeline.cpp +++ b/libraries/gpu/src/gpu/GLBackendPipeline.cpp @@ -144,9 +144,8 @@ void GLBackend::updatePipeline() { #if (GPU_TRANSFORM_PROFILE == GPU_CORE) #else // If shader program needs the inverseView we need to provide it - // YES InverseView in the shade is called View on the Batch interface if (_pipeline._program_transformCamera_viewInverse >= 0) { - glUniformMatrix4fv(_pipeline._program_transformCamera_viewInverse, 1, false, (const GLfloat*) &_transform._view); + glUniformMatrix4fv(_pipeline._program_transformCamera_viewInverse, 1, false, (const GLfloat*) &_transform._transformCamera._viewInverse); } #endif } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index c953107b79..f0a52af086 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -555,9 +555,9 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { glPopMatrix(); } -void DeferredLightingEffect::setupTransparent(RenderArgs* args) { +void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferUnit) { auto globalLight = _allocatedLights[_globalLights.front()]; - args->_batch->setUniformBuffer(4, globalLight->getSchemaBuffer()); + args->_batch->setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer()); } void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations) { diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index e8e402f27a..bd7fcb286b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -70,7 +70,7 @@ public: void render(); void copyBack(RenderArgs* args); - void setupTransparent(RenderArgs* args); + void setupTransparent(RenderArgs* args, int lightBufferUnit); // update global lighting void setAmbientLightMode(int preset); diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 4fc8c6a1f4..aadc4bffbe 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -197,13 +197,17 @@ void Model::RenderPipelineLib::initLocations(gpu::ShaderPointer& program, Model: #if (GPU_FEATURE_PROFILE == GPU_CORE) locations.materialBufferUnit = program->getBuffers().findLocation("materialBuffer"); + locations.lightBufferUnit = program->getBuffers().findLocation("lightBuffer"); #else locations.materialBufferUnit = program->getUniforms().findLocation("materialBuffer"); + locations.lightBufferUnit = program->getUniforms().findLocation("lightBuffer"); #endif locations.clusterMatrices = program->getUniforms().findLocation("clusterMatrices"); locations.clusterIndices = program->getInputs().findLocation("clusterIndices");; locations.clusterWeights = program->getInputs().findLocation("clusterWeights");; + + } @@ -2251,6 +2255,10 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap ? textureCache->getWhiteTexture() : emissiveMap->getGPUTexture()); } + + if (translucent && locations->lightBufferUnit >= 0) { + DependencyManager::get()->setupTransparent(args, locations->lightBufferUnit); + } } } diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index b2b6e0dc7d..0367ad8d32 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -374,6 +374,7 @@ private: int clusterMatrices; int clusterIndices; int clusterWeights; + int lightBufferUnit; }; QHash, AABox> _calculatedMeshPartBoxes; // world coordinate AABoxes for all sub mesh part boxes diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 94a89488b0..2892120632 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -115,7 +115,7 @@ template <> void render::jobRun(const DrawTransparentDeferred& job, const SceneC gpu::Batch batch; args->_batch = &batch; - DependencyManager::get()->setupTransparent(renderContext->args); + glm::mat4 projMat; diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 806b77dc15..179b7b9e28 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -44,8 +44,8 @@ void main(void) { // Everything about global lighting <@include DeferredLighting.slh@> -<@include gpu/Transform.slh@> -<$declareStandardTransform()$> +<@include gpu/Transform.slh@> +<$declareStandardTransform()$> // Everything about light @@ -78,7 +78,6 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d // Need the light now Light light = getLight(); TransformCamera cam = getTransformCamera(); - // mat4 viewMat = cam._viewInverse; vec3 fragNormal; <$transformEyeToWorldDir(cam, normal, fragNormal)$> vec3 fragEyeVectorView = normalize(-position); @@ -91,7 +90,10 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 d color += vec3(opacity * diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); + //return vec4(color, opacity); return vec4(color, opacity); + //return vec4(diffuse.rgb, opacity); + //return evalNormalColor(fragEyeDir, opacity); } // the diffuse texture