diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 245cf00a3d..7603187e94 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -56,7 +56,8 @@ void RenderableTextEntityItem::render(RenderArgs* args) { batch.setModelTransform(transformToTopLeft); } - DependencyManager::get()->renderQuad(batch, minCorner, maxCorner, backgroundColor); + DependencyManager::get()->bindSimpleProgram(batch, false, false); + DependencyManager::get()->renderQuad(batch, minCorner, maxCorner, backgroundColor); float scale = _lineHeight / _textRenderer->getFontSize(); transformToTopLeft.setScale(scale); // Scale to have the correct line height diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 94f88b8390..cf602971c2 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -172,22 +172,20 @@ void RenderableWebEntityItem::render(RenderArgs* args) { Glower glow(0.0f); PerformanceTimer perfTimer("RenderableWebEntityItem::render"); Q_ASSERT(getType() == EntityTypes::Web); - static const glm::vec2 texMin(0.0f); - static const glm::vec2 texMax(1.0f); - glm::vec2 topLeft(-0.5f -0.5f); - glm::vec2 bottomRight(0.5f, 0.5f); + static const glm::vec2 texMin(0.0f), texMax(1.0f), topLeft(-0.5f), bottomRight(0.5f); Q_ASSERT(args->_batch); gpu::Batch& batch = *args->_batch; batch.setModelTransform(getTransformToCenter()); + bool textured = false, culled = false, emissive = false; if (_texture) { + batch._glActiveTexture(GL_TEXTURE0); batch._glBindTexture(GL_TEXTURE_2D, _texture); - batch._glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - batch._glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + textured = emissive = true; } - DependencyManager::get()->bindSimpleProgram(batch, true); + + DependencyManager::get()->bindSimpleProgram(batch, textured, culled, emissive); DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f)); - DependencyManager::get()->releaseSimpleProgram(batch); } void RenderableWebEntityItem::setSourceUrl(const QString& value) { diff --git a/libraries/gpu/src/gpu/GLBackendPipeline.cpp b/libraries/gpu/src/gpu/GLBackendPipeline.cpp index f4449e9ea1..06d9eadd87 100755 --- a/libraries/gpu/src/gpu/GLBackendPipeline.cpp +++ b/libraries/gpu/src/gpu/GLBackendPipeline.cpp @@ -160,6 +160,10 @@ void GLBackend::do_setUniformBuffer(Batch& batch, uint32 paramOffset) { GLuint bo = getBufferID(*uniformBuffer); glBindBufferRange(GL_UNIFORM_BUFFER, slot, bo, rangeStart, rangeSize); #else + // because we rely on the program uniform mechanism we need to have + // the program bound, thank you MacOSX Legacy profile. + updatePipeline(); + GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart); glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b49d1985bb..a44f1f053c 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -27,8 +27,8 @@ #include "gpu/GLBackend.h" #include "simple_vert.h" -#include "simple_frag.h" #include "simple_textured_frag.h" +#include "simple_textured_emisive_frag.h" #include "deferred_light_vert.h" #include "deferred_light_limited_vert.h" @@ -52,15 +52,15 @@ static const std::string glowIntensityShaderHandle = "glowIntensity"; void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { auto VS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert))); - auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag))); - auto PSTextured = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_frag))); + auto PS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_frag))); + auto PSEmissive = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_textured_emisive_frag))); gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PS)); - gpu::ShaderPointer programTextured = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PSTextured)); + gpu::ShaderPointer programEmissive = gpu::ShaderPointer(gpu::Shader::createProgram(VS, PSEmissive)); gpu::Shader::BindingSet slotBindings; gpu::Shader::makeProgram(*program, slotBindings); - gpu::Shader::makeProgram(*programTextured, slotBindings); + gpu::Shader::makeProgram(*programEmissive, slotBindings); gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setCullMode(gpu::State::CULL_BACK); @@ -79,8 +79,8 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { _simpleProgram = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); _simpleProgramCullNone = gpu::PipelinePointer(gpu::Pipeline::create(program, stateCullNone)); - _simpleProgramTextured = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, state)); - _simpleProgramTexturedCullNone = gpu::PipelinePointer(gpu::Pipeline::create(programTextured, stateCullNone)); + _simpleProgramEmissive = gpu::PipelinePointer(gpu::Pipeline::create(programEmissive, state)); + _simpleProgramEmissiveCullNone = gpu::PipelinePointer(gpu::Pipeline::create(programEmissive, stateCullNone)); _viewState = viewState; loadLightProgram(directional_light_frag, false, _directionalLight, _directionalLightLocations); @@ -117,14 +117,12 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(_ambientLightMode % gpu::SphericalHarmonics::NUM_PRESET)); } -void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled) { - // DependencyManager::get()->setPrimaryDrawBuffers(batch, true, true, true); - - if (textured) { +void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool emmisive) { + if (emmisive) { if (culled) { - batch.setPipeline(_simpleProgramTextured); + batch.setPipeline(_simpleProgramEmissive); } else { - batch.setPipeline(_simpleProgramTexturedCullNone); + batch.setPipeline(_simpleProgramEmissiveCullNone); } } else { if (culled) { @@ -133,48 +131,42 @@ void DeferredLightingEffect::bindSimpleProgram(gpu::Batch& batch, bool textured, batch.setPipeline(_simpleProgramCullNone); } } -} - -void DeferredLightingEffect::releaseSimpleProgram(gpu::Batch& batch) { - // DependencyManager::get()->setPrimaryDrawBuffers(batch, true, false, false); + if (!textured) { + // If it is not textured, bind white texture and keep using textured pipeline + batch.setUniformTexture(0, DependencyManager::get()->getWhiteTexture()); + } } void DeferredLightingEffect::renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(batch); DependencyManager::get()->renderSphere(batch, radius, slices, stacks, color); - releaseSimpleProgram(batch); } void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(batch); DependencyManager::get()->renderSphere(batch, radius, slices, stacks, color, false); - releaseSimpleProgram(batch); } void DeferredLightingEffect::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) { bindSimpleProgram(batch); DependencyManager::get()->renderSolidCube(batch, size, color); - releaseSimpleProgram(batch); } void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) { bindSimpleProgram(batch); DependencyManager::get()->renderWireCube(batch, size, color); - releaseSimpleProgram(batch); } void DeferredLightingEffect::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color) { bindSimpleProgram(batch); DependencyManager::get()->renderQuad(batch, minCorner, maxCorner, color); - releaseSimpleProgram(batch); } void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2) { bindSimpleProgram(batch); DependencyManager::get()->renderLine(batch, p1, p2, color1, color2); - releaseSimpleProgram(batch); } void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radius, const glm::vec3& color, diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 9d66bf08c0..d948f2c305 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -34,10 +34,7 @@ public: void init(AbstractViewStateInterface* viewState); /// Sets up the state necessary to render static untextured geometry with the simple program. - void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true); - - /// Tears down the state necessary to render static untextured geometry with the simple program. - void releaseSimpleProgram(gpu::Batch& batch); + void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, bool emmisive = false); //// Renders a solid sphere with the simple program. void renderSolidSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color); @@ -101,8 +98,8 @@ private: gpu::PipelinePointer _simpleProgram; gpu::PipelinePointer _simpleProgramCullNone; - gpu::PipelinePointer _simpleProgramTextured; - gpu::PipelinePointer _simpleProgramTexturedCullNone; + gpu::PipelinePointer _simpleProgramEmissive; + gpu::PipelinePointer _simpleProgramEmissiveCullNone; ProgramObject _directionalSkyboxLight; LightLocations _directionalSkyboxLightLocations; diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 361f8454ab..d9972417ba 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -44,9 +44,9 @@ void main() { if (a < 0.01) { discard; } - + // final color gl_FragData[0] = vec4(Color.rgb, Color.a * a); - gl_FragData[1] = vec4(interpolatedNormal.xyz, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(0.0); + gl_FragData[1] = vec4(normalize(interpolatedNormal.xyz), 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); + gl_FragData[2] = vec4(Color.rgb, gl_FrontMaterial.shininess / 128.0); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_textured_emisive.slf b/libraries/render-utils/src/simple_textured_emisive.slf new file mode 100644 index 0000000000..643dcde190 --- /dev/null +++ b/libraries/render-utils/src/simple_textured_emisive.slf @@ -0,0 +1,33 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple.frag +// fragment shader +// +// Created by Clément Brisset on 5/29/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include DeferredBufferWrite.slh@> + +// the diffuse texture +uniform sampler2D originalTexture; + +// the interpolated normal +varying vec4 interpolatedNormal; + +void main(void) { + vec4 texel = texture2D(originalTexture, gl_TexCoord[0].st); + + packDeferredFragmentLightmap( + normalize(interpolatedNormal.xyz), + glowIntensity * texel.a, + gl_Color.rgb, + gl_FrontMaterial.specular.rgb, + gl_FrontMaterial.shininess, + texel.rgb); +} \ No newline at end of file