From 1ec9ef560e472462da07c30dda2a8f6f1126e122 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 11 May 2016 10:46:54 -0700 Subject: [PATCH] Fixing the srgb color format conversion for web entities --- .../src/RenderableWebEntityItem.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 28 ++++++------- libraries/render-utils/src/GeometryCache.h | 6 +-- .../render-utils/src/RenderPipelines.cpp | 2 - libraries/render-utils/src/model_emissive.slf | 39 ------------------- libraries/render-utils/src/simple.slv | 4 +- .../render-utils/src/simple_textured.slf | 8 ++-- ..._emisive.slf => simple_textured_unlit.slf} | 21 +++------- tests/shaders/src/main.cpp | 4 +- 9 files changed, 33 insertions(+), 81 deletions(-) delete mode 100644 libraries/render-utils/src/model_emissive.slf rename libraries/render-utils/src/{simple_textured_emisive.slf => simple_textured_unlit.slf} (70%) diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 891e1dca3b..f0244d0e3f 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -210,7 +210,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { } DependencyManager::get()->bindSimpleProgram(batch, textured, culled, emissive); - DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f)); + DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, 0.0f)); } void RenderableWebEntityItem::setSourceUrl(const QString& value) { diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 550baa6946..15bf44744c 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -31,7 +31,7 @@ #include "simple_vert.h" #include "simple_textured_frag.h" -#include "simple_textured_emisive_frag.h" +#include "simple_textured_unlit_frag.h" #include "grid_frag.h" @@ -1687,7 +1687,7 @@ public: enum FlagBit { IS_TEXTURED_FLAG = 0, IS_CULLED_FLAG, - IS_EMISSIVE_FLAG, + IS_UNLIT_FLAG, HAS_DEPTH_BIAS_FLAG, NUM_FLAGS, @@ -1696,7 +1696,7 @@ public: enum Flag { IS_TEXTURED = (1 << IS_TEXTURED_FLAG), IS_CULLED = (1 << IS_CULLED_FLAG), - IS_EMISSIVE = (1 << IS_EMISSIVE_FLAG), + IS_UNLIT = (1 << IS_UNLIT_FLAG), HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG), }; typedef unsigned short Flags; @@ -1705,7 +1705,7 @@ public: bool isTextured() const { return isFlag(IS_TEXTURED); } bool isCulled() const { return isFlag(IS_CULLED); } - bool isEmissive() const { return isFlag(IS_EMISSIVE); } + bool isUnlit() const { return isFlag(IS_UNLIT); } bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); } Flags _flags = 0; @@ -1715,9 +1715,9 @@ public: SimpleProgramKey(bool textured = false, bool culled = true, - bool emissive = false, bool depthBias = false) { + bool unlit = false, bool depthBias = false) { _flags = (textured ? IS_TEXTURED : 0) | (culled ? IS_CULLED : 0) | - (emissive ? IS_EMISSIVE : 0) | (depthBias ? HAS_DEPTH_BIAS : 0); + (unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0); } SimpleProgramKey(int bitmask) : _flags(bitmask) {} @@ -1731,8 +1731,8 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) { return a.getRaw() == b.getRaw(); } -void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool emissive, bool depthBiased) { - batch.setPipeline(getSimplePipeline(textured, culled, emissive, depthBiased)); +void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool unlit, bool depthBiased) { + batch.setPipeline(getSimplePipeline(textured, culled, unlit, depthBiased)); // If not textured, set a default albedo map if (!textured) { @@ -1744,23 +1744,23 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool cul DependencyManager::get()->getNormalFittingTexture()); } -gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool emissive, bool depthBiased) { - SimpleProgramKey config{textured, culled, emissive, depthBiased}; +gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool unlit, bool depthBiased) { + SimpleProgramKey config{ textured, culled, unlit, depthBiased }; // Compile the shaders static std::once_flag once; std::call_once(once, [&]() { auto VS = gpu::Shader::createVertex(std::string(simple_vert)); auto PS = gpu::Shader::createPixel(std::string(simple_textured_frag)); - auto PSEmissive = gpu::Shader::createPixel(std::string(simple_textured_emisive_frag)); + auto PSUnlit = gpu::Shader::createPixel(std::string(simple_textured_unlit_frag)); _simpleShader = gpu::Shader::createProgram(VS, PS); - _emissiveShader = gpu::Shader::createProgram(VS, PSEmissive); + _unlitShader = gpu::Shader::createProgram(VS, PSUnlit); gpu::Shader::BindingSet slotBindings; slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING)); gpu::Shader::makeProgram(*_simpleShader, slotBindings); - gpu::Shader::makeProgram(*_emissiveShader, slotBindings); + gpu::Shader::makeProgram(*_unlitShader, slotBindings); }); // If the pipeline already exists, return it @@ -1785,7 +1785,7 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader; + gpu::ShaderPointer program = (config.isUnlit()) ? _unlitShader : _simpleShader; gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state); _simplePrograms.insert(config, pipeline); return pipeline; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index b69ebf8531..c4531aa102 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -153,10 +153,10 @@ public: // Bind the pipeline and get the state to render static geometry void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true, - bool emissive = false, bool depthBias = false); + bool unlit = false, bool depthBias = false); // Get the pipeline to render static geometry gpu::PipelinePointer getSimplePipeline(bool textured = false, bool culled = true, - bool emissive = false, bool depthBias = false); + bool unlit = false, bool depthBias = false); render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; } // Static (instanced) geometry @@ -393,7 +393,7 @@ private: QHash > _networkGeometry; gpu::ShaderPointer _simpleShader; - gpu::ShaderPointer _emissiveShader; + gpu::ShaderPointer _unlitShader; static render::ShapePipelinePointer _simplePipeline; QHash _simplePrograms; }; diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index c6ae08cf9d..16681fd363 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -27,7 +27,6 @@ #include "skin_model_normal_map_vert.h" #include "model_frag.h" -#include "model_emissive_frag.h" #include "model_unlit_frag.h" #include "model_shadow_frag.h" #include "model_normal_map_frag.h" @@ -38,7 +37,6 @@ #include "model_lightmap_normal_specular_map_frag.h" #include "model_lightmap_specular_map_frag.h" #include "model_translucent_frag.h" -#include "model_translucent_emissive_frag.h" #include "model_translucent_unlit_frag.h" #include "overlay3D_vert.h" diff --git a/libraries/render-utils/src/model_emissive.slf b/libraries/render-utils/src/model_emissive.slf deleted file mode 100644 index 471e613eb4..0000000000 --- a/libraries/render-utils/src/model_emissive.slf +++ /dev/null @@ -1,39 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// model_emissive.frag -// fragment shader -// -// Created by Zach Pomerantz on 2/3/2016. -// Copyright 2016 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@> -<@include model/Material.slh@> - -uniform sampler2D albedoMap; - -in vec2 _texCoord0; -in vec3 _normal; -in vec3 _color; -in float _alpha; - -void main(void) { - vec4 texel = texture(albedoMap, _texCoord0); - - Material mat = getMaterial(); - vec3 fragColor = getMaterialAlbedo(mat) * texel.rgb * _color; - - packDeferredFragmentLightmap( - normalize(_normal), - texel.a, - vec3(1.0), - getMaterialRoughness(mat), - getMaterialMetallic(mat), - getMaterialFresnel(mat), - fragColor); -} diff --git a/libraries/render-utils/src/simple.slv b/libraries/render-utils/src/simple.slv index 46127d6752..d56d1cc8e2 100644 --- a/libraries/render-utils/src/simple.slv +++ b/libraries/render-utils/src/simple.slv @@ -20,12 +20,12 @@ // the interpolated normal out vec3 _normal; out vec3 _modelNormal; -out vec3 _color; +out vec4 _color; out vec2 _texCoord0; out vec4 _position; void main(void) { - _color = colorToLinearRGB(inColor.rgb); + _color = colorToLinearRGBA(inColor); _texCoord0 = inTexCoord0.st; _position = inPosition; _modelNormal = inNormal.xyz; diff --git a/libraries/render-utils/src/simple_textured.slf b/libraries/render-utils/src/simple_textured.slf index 0832b22214..062fb96f7d 100644 --- a/libraries/render-utils/src/simple_textured.slf +++ b/libraries/render-utils/src/simple_textured.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> <@include model/Material.slh@> @@ -20,13 +21,14 @@ uniform sampler2D originalTexture; // the interpolated normal in vec3 _normal; -in vec3 _color; +in vec4 _color; in vec2 _texCoord0; void main(void) { - Material material = getMaterial(); vec4 texel = texture(originalTexture, _texCoord0); - + if (_color.a <= 0.0) { + texel = colorToLinearRGBA(texel); + } packDeferredFragment( normalize(_normal.xyz), texel.a, diff --git a/libraries/render-utils/src/simple_textured_emisive.slf b/libraries/render-utils/src/simple_textured_unlit.slf similarity index 70% rename from libraries/render-utils/src/simple_textured_emisive.slf rename to libraries/render-utils/src/simple_textured_unlit.slf index 9c5ef08bd1..cbfc7d7768 100644 --- a/libraries/render-utils/src/simple_textured_emisive.slf +++ b/libraries/render-utils/src/simple_textured_unlit.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> // the albedo texture @@ -19,27 +20,17 @@ uniform sampler2D originalTexture; // the interpolated normal in vec3 _normal; -in vec3 _color; +in vec4 _color; in vec2 _texCoord0; void main(void) { vec4 texel = texture(originalTexture, _texCoord0.st); - + if (_color.a <= 0.0) { + texel = colorToLinearRGBA(texel); + } - packDeferredFragmentUnlit( normalize(_normal), texel.a, - texel.rgb); - - /* - packDeferredFragmentLightmap( - normalize(_normal), - texel.a, - _color.rgb, - DEFAULT_ROUGHNESS, - DEFAULT_METALLIC, - DEFAULT_SPECULAR, - texel.rgb); - */ + _color.rgb * texel.rgb); } \ No newline at end of file diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index 2bc957b2d1..c50f5769e6 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -160,7 +160,7 @@ void QTestWindow::draw() { testShaderBuild(skybox_vert, skybox_frag); testShaderBuild(simple_vert, simple_frag); testShaderBuild(simple_vert, simple_textured_frag); - testShaderBuild(simple_vert, simple_textured_emisive_frag); + testShaderBuild(simple_vert, simple_textured_unlit_frag); testShaderBuild(deferred_light_vert, directional_light_frag); testShaderBuild(deferred_light_vert, directional_ambient_light_frag); testShaderBuild(deferred_light_vert, directional_skybox_light_frag);