INtroducing the unlit mode for fragments

This commit is contained in:
samcake 2016-05-05 17:08:52 -07:00
parent f1b236f3be
commit e306a24a1b
14 changed files with 106 additions and 23 deletions

View file

@ -94,6 +94,14 @@ static const std::string DEFAULT_EMISSIVE_SHADER{
" }" " }"
}; };
static const std::string DEFAULT_UNLIT_SHADER{
"vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(pow(vec3(frag.diffuseVal.w), vec3(1.0 / 2.2)), 1.0);"
// " return (frag.mode == FRAG_MODE_UNLIT ? vec4(pow(frag.diffuse, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
" }"
};
static const std::string DEFAULT_LIGHTMAP_SHADER{ static const std::string DEFAULT_LIGHTMAP_SHADER{
"vec4 getFragmentColor() {" "vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
@ -184,6 +192,8 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
return DEFAULT_DEPTH_SHADER; return DEFAULT_DEPTH_SHADER;
case EmissiveMode: case EmissiveMode:
return DEFAULT_EMISSIVE_SHADER; return DEFAULT_EMISSIVE_SHADER;
case UnlitMode:
return DEFAULT_UNLIT_SHADER;
case OcclusionMode: case OcclusionMode:
return DEFAULT_OCCLUSION_SHADER; return DEFAULT_OCCLUSION_SHADER;
case LightmapMode: case LightmapMode:

View file

@ -53,6 +53,7 @@ protected:
RoughnessMode, RoughnessMode,
MetallicMode, MetallicMode,
EmissiveMode, EmissiveMode,
UnlitMode,
OcclusionMode, OcclusionMode,
LightmapMode, LightmapMode,
LightingMode, LightingMode,

View file

@ -12,39 +12,43 @@
<@def DEFERRED_BUFFER_SLH@> <@def DEFERRED_BUFFER_SLH@>
// Unpack the metallic-mode value // Unpack the metallic-mode value
const float FRAG_TYPE_UNLIT = 0.0; const float FRAG_PACK_SHADED_NON_METALLIC = 0.0;
const float FRAG_TYPE_SHADED_NON_METALLIC = 0.1; const float FRAG_PACK_SHADED_METALLIC = 0.1;
const float FRAG_TYPE_SHADED_METALLIC = 0.2; const float FRAG_PACK_SHADED_RANGE_INV = 1.0 / (FRAG_PACK_SHADED_METALLIC - FRAG_PACK_SHADED_NON_METALLIC);
const float FRAG_TYPE_SHADED_RANGE_INV = 1.0 / (FRAG_TYPE_SHADED_METALLIC - FRAG_TYPE_SHADED_NON_METALLIC);
const float FRAG_TYPE_LIGHTMAPPED_NON_METALLIC = 0.3; const float FRAG_PACK_LIGHTMAPPED_NON_METALLIC = 0.2;
const float FRAG_TYPE_LIGHTMAPPED_METALLIC = 0.4; const float FRAG_PACK_LIGHTMAPPED_METALLIC = 0.3;
const float FRAG_TYPE_LIGHTMAPPED_RANGE_INV = 1.0 / (FRAG_TYPE_LIGHTMAPPED_METALLIC - FRAG_TYPE_LIGHTMAPPED_NON_METALLIC); const float FRAG_PACK_LIGHTMAPPED_RANGE_INV = 1.0 / (FRAG_PACK_LIGHTMAPPED_METALLIC - FRAG_PACK_LIGHTMAPPED_NON_METALLIC);
const float FRAG_PACK_UNLIT = 0.5;
const int FRAG_MODE_UNLIT = 0; const int FRAG_MODE_UNLIT = 0;
const int FRAG_MODE_SHADED = 1; const int FRAG_MODE_SHADED = 1;
const int FRAG_MODE_LIGHTMAPPED = 2; const int FRAG_MODE_LIGHTMAPPED = 2;
void unpackModeMetallic(float rawValue, out int mode, out float metallic) { void unpackModeMetallic(float rawValue, out int mode, out float metallic) {
if (rawValue < FRAG_TYPE_SHADED_NON_METALLIC) { if (rawValue <= FRAG_PACK_SHADED_METALLIC) {
mode = FRAG_MODE_SHADED;
metallic = clamp((rawValue - FRAG_PACK_SHADED_NON_METALLIC) * FRAG_PACK_SHADED_RANGE_INV, 0.0, 1.0);
} else if (rawValue <= FRAG_PACK_LIGHTMAPPED_METALLIC) {
mode = FRAG_MODE_LIGHTMAPPED;
metallic = clamp((rawValue - FRAG_PACK_LIGHTMAPPED_NON_METALLIC) * FRAG_PACK_SHADED_RANGE_INV, 0.0, 1.0);
} else if (rawValue >= FRAG_PACK_UNLIT) {
mode = FRAG_MODE_UNLIT; mode = FRAG_MODE_UNLIT;
metallic = 0.0; metallic = 0.0;
} else if (rawValue <= FRAG_TYPE_SHADED_METALLIC) {
mode = FRAG_MODE_SHADED;
metallic = clamp((rawValue - FRAG_TYPE_SHADED_NON_METALLIC) * FRAG_TYPE_SHADED_RANGE_INV, 0.0, 1.0);
} else if (rawValue <= FRAG_TYPE_LIGHTMAPPED_METALLIC) {
mode = FRAG_MODE_LIGHTMAPPED;
metallic = clamp((rawValue - FRAG_TYPE_LIGHTMAPPED_NON_METALLIC) * FRAG_TYPE_SHADED_RANGE_INV, 0.0, 1.0);
} }
} }
float packShadedMetallic(float metallic) { float packShadedMetallic(float metallic) {
return mix(FRAG_TYPE_SHADED_NON_METALLIC, FRAG_TYPE_SHADED_METALLIC, metallic); return mix(FRAG_PACK_SHADED_NON_METALLIC, FRAG_PACK_SHADED_METALLIC, metallic);
} }
float packLightmappedMetallic(float metallic) { float packLightmappedMetallic(float metallic) {
return mix(FRAG_TYPE_LIGHTMAPPED_NON_METALLIC, FRAG_TYPE_LIGHTMAPPED_METALLIC, metallic); return mix(FRAG_PACK_LIGHTMAPPED_NON_METALLIC, FRAG_PACK_LIGHTMAPPED_METALLIC, metallic);
} }
float packUnlit() {
return FRAG_PACK_UNLIT;
}
<@endif@> <@endif@>

View file

@ -73,7 +73,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
if (alpha != 1.0) { if (alpha != 1.0) {
discard; discard;
} }
_fragColor0 = vec4(color, FRAG_TYPE_UNLIT); _fragColor0 = vec4(color, packUnlit());
_fragColor1 = vec4(bestFitNormal(normal), 1.0); _fragColor1 = vec4(bestFitNormal(normal), 1.0);
//_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target //_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target
} }

View file

@ -414,6 +414,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty(); bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty();
bool hasSpecular = drawMaterialKey.isMetallicMap(); bool hasSpecular = drawMaterialKey.isMetallicMap();
bool hasLightmap = drawMaterialKey.isLightmapMap(); bool hasLightmap = drawMaterialKey.isLightmapMap();
bool isUnlit = drawMaterialKey.isUnlit();
bool isSkinned = _isSkinned; bool isSkinned = _isSkinned;
bool wireframe = _model->isWireframe(); bool wireframe = _model->isWireframe();
@ -435,6 +436,9 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
if (hasLightmap) { if (hasLightmap) {
builder.withLightmap(); builder.withLightmap();
} }
if (isUnlit) {
builder.withUnlit();
}
if (isSkinned) { if (isSkinned) {
builder.withSkinned(); builder.withSkinned();
} }

View file

@ -28,6 +28,7 @@
#include "model_frag.h" #include "model_frag.h"
#include "model_emissive_frag.h" #include "model_emissive_frag.h"
#include "model_unlit_frag.h"
#include "model_shadow_frag.h" #include "model_shadow_frag.h"
#include "model_normal_map_frag.h" #include "model_normal_map_frag.h"
#include "model_normal_specular_map_frag.h" #include "model_normal_specular_map_frag.h"
@ -202,6 +203,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
// Pixel shaders // Pixel shaders
auto modelPixel = gpu::Shader::createPixel(std::string(model_frag)); auto modelPixel = gpu::Shader::createPixel(std::string(model_frag));
auto modelEmissivePixel = gpu::Shader::createPixel(std::string(model_emissive_frag)); auto modelEmissivePixel = gpu::Shader::createPixel(std::string(model_emissive_frag));
auto modelUnlitPixel = gpu::Shader::createPixel(std::string(model_unlit_frag));
auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag)); auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag));
auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag)); auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag));
auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag)); auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag));
@ -221,6 +223,9 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
addPipeline( addPipeline(
Key::Builder().withEmissive(), Key::Builder().withEmissive(),
modelVertex, modelEmissivePixel); modelVertex, modelEmissivePixel);
addPipeline(
Key::Builder().withUnlit(),
modelVertex, modelUnlitPixel);
addPipeline( addPipeline(
Key::Builder().withTangents(), Key::Builder().withTangents(),
modelNormalMapVertex, modelNormalMapPixel); modelNormalMapVertex, modelNormalMapPixel);
@ -237,6 +242,9 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
addPipeline( addPipeline(
Key::Builder().withTranslucent().withEmissive(), Key::Builder().withTranslucent().withEmissive(),
modelVertex, modelTranslucentEmissivePixel); modelVertex, modelTranslucentEmissivePixel);
addPipeline(
Key::Builder().withTranslucent().withUnlit(),
modelVertex, modelTranslucentEmissivePixel);
addPipeline( addPipeline(
Key::Builder().withTranslucent().withTangents(), Key::Builder().withTranslucent().withTangents(),
modelNormalMapVertex, modelTranslucentPixel); modelNormalMapVertex, modelTranslucentPixel);
@ -296,4 +304,5 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
addPipeline( addPipeline(
Key::Builder().withSkinned().withDepthOnly(), Key::Builder().withSkinned().withDepthOnly(),
skinModelShadowVertex, modelShadowPixel); skinModelShadowVertex, modelShadowPixel);
} }

View file

@ -27,7 +27,9 @@ void main(void) {
float shadowAttenuation = 1.0; float shadowAttenuation = 1.0;
if (frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( vec3 color = evalLightmappedColor(
deferredTransform.viewInverse, deferredTransform.viewInverse,
shadowAttenuation, shadowAttenuation,

View file

@ -29,7 +29,9 @@ void main(void) {
vec4 worldPos = deferredTransform.viewInverse * vec4(frag.position.xyz, 1.0); vec4 worldPos = deferredTransform.viewInverse * vec4(frag.position.xyz, 1.0);
float shadowAttenuation = evalShadowAttenuation(worldPos); float shadowAttenuation = evalShadowAttenuation(worldPos);
if (frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( vec3 color = evalLightmappedColor(
deferredTransform.viewInverse, deferredTransform.viewInverse,
shadowAttenuation, shadowAttenuation,

View file

@ -28,7 +28,9 @@ void main(void) {
float shadowAttenuation = 1.0; float shadowAttenuation = 1.0;
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( vec3 color = evalLightmappedColor(
deferredTransform.viewInverse, deferredTransform.viewInverse,
shadowAttenuation, shadowAttenuation,

View file

@ -30,7 +30,9 @@ void main(void) {
float shadowAttenuation = evalShadowAttenuation(worldPos); float shadowAttenuation = evalShadowAttenuation(worldPos);
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( vec3 color = evalLightmappedColor(
deferredTransform.viewInverse, deferredTransform.viewInverse,
shadowAttenuation, shadowAttenuation,

View file

@ -28,7 +28,9 @@ void main(void) {
float shadowAttenuation = 1.0; float shadowAttenuation = 1.0;
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( vec3 color = evalLightmappedColor(
deferredTransform.viewInverse, deferredTransform.viewInverse,
shadowAttenuation, shadowAttenuation,

View file

@ -30,7 +30,9 @@ void main(void) {
float shadowAttenuation = evalShadowAttenuation(worldPos); float shadowAttenuation = evalShadowAttenuation(worldPos);
// Light mapped or not ? // Light mapped or not ?
if (frag.mode == FRAG_MODE_LIGHTMAPPED) { if (frag.mode == FRAG_MODE_UNLIT) {
_fragColor = vec4(frag.diffuse, 1.0);
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
vec3 color = evalLightmappedColor( vec3 color = evalLightmappedColor(
deferredTransform.viewInverse, deferredTransform.viewInverse,
shadowAttenuation, shadowAttenuation,

View file

@ -0,0 +1,36 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// material_opaque_unlit.frag
// fragment shader
//
// Created by Sam Gateau on 5/5/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 = getMaterialEmissive(mat) * texel.rgb * _color;
vec3 fragColor = vec3(1.0, 0.5, 0.0);
packDeferredFragmentUnlit(
normalize(_normal),
1.0,
fragColor);
}

View file

@ -25,6 +25,7 @@ public:
TANGENTS, TANGENTS,
SPECULAR, SPECULAR,
EMISSIVE, EMISSIVE,
UNLIT,
SKINNED, SKINNED,
STEREO, STEREO,
DEPTH_ONLY, DEPTH_ONLY,
@ -56,6 +57,7 @@ public:
Builder& withTangents() { _flags.set(TANGENTS); return (*this); } Builder& withTangents() { _flags.set(TANGENTS); return (*this); }
Builder& withSpecular() { _flags.set(SPECULAR); return (*this); } Builder& withSpecular() { _flags.set(SPECULAR); return (*this); }
Builder& withEmissive() { _flags.set(EMISSIVE); return (*this); } Builder& withEmissive() { _flags.set(EMISSIVE); return (*this); }
Builder& withUnlit() { _flags.set(UNLIT); return (*this); }
Builder& withSkinned() { _flags.set(SKINNED); return (*this); } Builder& withSkinned() { _flags.set(SKINNED); return (*this); }
Builder& withStereo() { _flags.set(STEREO); return (*this); } Builder& withStereo() { _flags.set(STEREO); return (*this); }
Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); } Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); }
@ -102,6 +104,9 @@ public:
Builder& withEmissive() { _flags.set(EMISSIVE); _mask.set(EMISSIVE); return (*this); } Builder& withEmissive() { _flags.set(EMISSIVE); _mask.set(EMISSIVE); return (*this); }
Builder& withoutEmissive() { _flags.reset(EMISSIVE); _mask.set(EMISSIVE); return (*this); } Builder& withoutEmissive() { _flags.reset(EMISSIVE); _mask.set(EMISSIVE); return (*this); }
Builder& withUnlit() { _flags.set(UNLIT); _mask.set(UNLIT); return (*this); }
Builder& withoutUnlit() { _flags.reset(UNLIT); _mask.set(UNLIT); return (*this); }
Builder& withSkinned() { _flags.set(SKINNED); _mask.set(SKINNED); return (*this); } Builder& withSkinned() { _flags.set(SKINNED); _mask.set(SKINNED); return (*this); }
Builder& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); } Builder& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); }
@ -136,6 +141,7 @@ public:
bool hasTangents() const { return _flags[TANGENTS]; } bool hasTangents() const { return _flags[TANGENTS]; }
bool hasSpecular() const { return _flags[SPECULAR]; } bool hasSpecular() const { return _flags[SPECULAR]; }
bool hasEmissive() const { return _flags[EMISSIVE]; } bool hasEmissive() const { return _flags[EMISSIVE]; }
bool isUnlit() const { return _flags[UNLIT]; }
bool isTranslucent() const { return _flags[TRANSLUCENT]; } bool isTranslucent() const { return _flags[TRANSLUCENT]; }
bool isSkinned() const { return _flags[SKINNED]; } bool isSkinned() const { return _flags[SKINNED]; }
bool isStereo() const { return _flags[STEREO]; } bool isStereo() const { return _flags[STEREO]; }
@ -172,6 +178,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) {
<< "hasTangents:" << key.hasTangents() << "hasTangents:" << key.hasTangents()
<< "hasSpecular:" << key.hasSpecular() << "hasSpecular:" << key.hasSpecular()
<< "hasEmissive:" << key.hasEmissive() << "hasEmissive:" << key.hasEmissive()
<< "isUnlit:" << key.isUnlit()
<< "isTranslucent:" << key.isTranslucent() << "isTranslucent:" << key.isTranslucent()
<< "isSkinned:" << key.isSkinned() << "isSkinned:" << key.isSkinned()
<< "isStereo:" << key.isStereo() << "isStereo:" << key.isStereo()