Fixing the srgb color format conversion for web entities

This commit is contained in:
samcake 2016-05-11 10:46:54 -07:00
parent e40a795a27
commit 1ec9ef560e
9 changed files with 33 additions and 81 deletions

View file

@ -210,7 +210,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
}
DependencyManager::get<GeometryCache>()->bindSimpleProgram(batch, textured, culled, emissive);
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f));
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, 0.0f));
}
void RenderableWebEntityItem::setSourceUrl(const QString& value) {

View file

@ -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<TextureCache>()->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;

View file

@ -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<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
gpu::ShaderPointer _simpleShader;
gpu::ShaderPointer _emissiveShader;
gpu::ShaderPointer _unlitShader;
static render::ShapePipelinePointer _simplePipeline;
QHash<SimpleProgramKey, gpu::PipelinePointer> _simplePrograms;
};

View file

@ -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"

View file

@ -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);
}

View file

@ -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;

View file

@ -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,

View file

@ -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);
}

View file

@ -26,7 +26,7 @@
#include <render-utils/simple_vert.h>
#include <render-utils/simple_frag.h>
#include <render-utils/simple_textured_frag.h>
#include <render-utils/simple_textured_emisive_frag.h>
#include <render-utils/simple_textured_unlit_frag.h>
#include <render-utils/deferred_light_vert.h>
#include <render-utils/deferred_light_limited_vert.h>
@ -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);