mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 20:54:25 +02:00
INtroducing the unlit mode for fragments
This commit is contained in:
parent
f1b236f3be
commit
e306a24a1b
14 changed files with 106 additions and 23 deletions
|
@ -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{
|
||||
"vec4 getFragmentColor() {"
|
||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||
|
@ -184,6 +192,8 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
|
|||
return DEFAULT_DEPTH_SHADER;
|
||||
case EmissiveMode:
|
||||
return DEFAULT_EMISSIVE_SHADER;
|
||||
case UnlitMode:
|
||||
return DEFAULT_UNLIT_SHADER;
|
||||
case OcclusionMode:
|
||||
return DEFAULT_OCCLUSION_SHADER;
|
||||
case LightmapMode:
|
||||
|
|
|
@ -53,6 +53,7 @@ protected:
|
|||
RoughnessMode,
|
||||
MetallicMode,
|
||||
EmissiveMode,
|
||||
UnlitMode,
|
||||
OcclusionMode,
|
||||
LightmapMode,
|
||||
LightingMode,
|
||||
|
|
|
@ -12,39 +12,43 @@
|
|||
<@def DEFERRED_BUFFER_SLH@>
|
||||
|
||||
// Unpack the metallic-mode value
|
||||
const float FRAG_TYPE_UNLIT = 0.0;
|
||||
const float FRAG_TYPE_SHADED_NON_METALLIC = 0.1;
|
||||
const float FRAG_TYPE_SHADED_METALLIC = 0.2;
|
||||
const float FRAG_TYPE_SHADED_RANGE_INV = 1.0 / (FRAG_TYPE_SHADED_METALLIC - FRAG_TYPE_SHADED_NON_METALLIC);
|
||||
const float FRAG_PACK_SHADED_NON_METALLIC = 0.0;
|
||||
const float FRAG_PACK_SHADED_METALLIC = 0.1;
|
||||
const float FRAG_PACK_SHADED_RANGE_INV = 1.0 / (FRAG_PACK_SHADED_METALLIC - FRAG_PACK_SHADED_NON_METALLIC);
|
||||
|
||||
const float FRAG_TYPE_LIGHTMAPPED_NON_METALLIC = 0.3;
|
||||
const float FRAG_TYPE_LIGHTMAPPED_METALLIC = 0.4;
|
||||
const float FRAG_TYPE_LIGHTMAPPED_RANGE_INV = 1.0 / (FRAG_TYPE_LIGHTMAPPED_METALLIC - FRAG_TYPE_LIGHTMAPPED_NON_METALLIC);
|
||||
const float FRAG_PACK_LIGHTMAPPED_NON_METALLIC = 0.2;
|
||||
const float FRAG_PACK_LIGHTMAPPED_METALLIC = 0.3;
|
||||
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_SHADED = 1;
|
||||
const int FRAG_MODE_LIGHTMAPPED = 2;
|
||||
|
||||
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;
|
||||
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) {
|
||||
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) {
|
||||
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@>
|
||||
|
|
|
@ -73,7 +73,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
|
|||
if (alpha != 1.0) {
|
||||
discard;
|
||||
}
|
||||
_fragColor0 = vec4(color, FRAG_TYPE_UNLIT);
|
||||
_fragColor0 = vec4(color, packUnlit());
|
||||
_fragColor1 = vec4(bestFitNormal(normal), 1.0);
|
||||
//_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target
|
||||
}
|
||||
|
|
|
@ -414,6 +414,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
|||
bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty();
|
||||
bool hasSpecular = drawMaterialKey.isMetallicMap();
|
||||
bool hasLightmap = drawMaterialKey.isLightmapMap();
|
||||
bool isUnlit = drawMaterialKey.isUnlit();
|
||||
|
||||
bool isSkinned = _isSkinned;
|
||||
bool wireframe = _model->isWireframe();
|
||||
|
@ -435,6 +436,9 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
|||
if (hasLightmap) {
|
||||
builder.withLightmap();
|
||||
}
|
||||
if (isUnlit) {
|
||||
builder.withUnlit();
|
||||
}
|
||||
if (isSkinned) {
|
||||
builder.withSkinned();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#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"
|
||||
#include "model_normal_specular_map_frag.h"
|
||||
|
@ -202,6 +203,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
// Pixel shaders
|
||||
auto modelPixel = gpu::Shader::createPixel(std::string(model_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 modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_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(
|
||||
Key::Builder().withEmissive(),
|
||||
modelVertex, modelEmissivePixel);
|
||||
addPipeline(
|
||||
Key::Builder().withUnlit(),
|
||||
modelVertex, modelUnlitPixel);
|
||||
addPipeline(
|
||||
Key::Builder().withTangents(),
|
||||
modelNormalMapVertex, modelNormalMapPixel);
|
||||
|
@ -237,6 +242,9 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
addPipeline(
|
||||
Key::Builder().withTranslucent().withEmissive(),
|
||||
modelVertex, modelTranslucentEmissivePixel);
|
||||
addPipeline(
|
||||
Key::Builder().withTranslucent().withUnlit(),
|
||||
modelVertex, modelTranslucentEmissivePixel);
|
||||
addPipeline(
|
||||
Key::Builder().withTranslucent().withTangents(),
|
||||
modelNormalMapVertex, modelTranslucentPixel);
|
||||
|
@ -296,4 +304,5 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
addPipeline(
|
||||
Key::Builder().withSkinned().withDepthOnly(),
|
||||
skinModelShadowVertex, modelShadowPixel);
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ void main(void) {
|
|||
|
||||
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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -29,7 +29,9 @@ void main(void) {
|
|||
vec4 worldPos = deferredTransform.viewInverse * vec4(frag.position.xyz, 1.0);
|
||||
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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -28,7 +28,9 @@ void main(void) {
|
|||
float shadowAttenuation = 1.0;
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -30,7 +30,9 @@ void main(void) {
|
|||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -28,7 +28,9 @@ void main(void) {
|
|||
float shadowAttenuation = 1.0;
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -30,7 +30,9 @@ void main(void) {
|
|||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
36
libraries/render-utils/src/model_unlit.slf
Normal file
36
libraries/render-utils/src/model_unlit.slf
Normal 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);
|
||||
}
|
|
@ -25,6 +25,7 @@ public:
|
|||
TANGENTS,
|
||||
SPECULAR,
|
||||
EMISSIVE,
|
||||
UNLIT,
|
||||
SKINNED,
|
||||
STEREO,
|
||||
DEPTH_ONLY,
|
||||
|
@ -56,6 +57,7 @@ public:
|
|||
Builder& withTangents() { _flags.set(TANGENTS); return (*this); }
|
||||
Builder& withSpecular() { _flags.set(SPECULAR); return (*this); }
|
||||
Builder& withEmissive() { _flags.set(EMISSIVE); return (*this); }
|
||||
Builder& withUnlit() { _flags.set(UNLIT); return (*this); }
|
||||
Builder& withSkinned() { _flags.set(SKINNED); return (*this); }
|
||||
Builder& withStereo() { _flags.set(STEREO); 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& 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& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); }
|
||||
|
||||
|
@ -136,6 +141,7 @@ public:
|
|||
bool hasTangents() const { return _flags[TANGENTS]; }
|
||||
bool hasSpecular() const { return _flags[SPECULAR]; }
|
||||
bool hasEmissive() const { return _flags[EMISSIVE]; }
|
||||
bool isUnlit() const { return _flags[UNLIT]; }
|
||||
bool isTranslucent() const { return _flags[TRANSLUCENT]; }
|
||||
bool isSkinned() const { return _flags[SKINNED]; }
|
||||
bool isStereo() const { return _flags[STEREO]; }
|
||||
|
@ -172,6 +178,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) {
|
|||
<< "hasTangents:" << key.hasTangents()
|
||||
<< "hasSpecular:" << key.hasSpecular()
|
||||
<< "hasEmissive:" << key.hasEmissive()
|
||||
<< "isUnlit:" << key.isUnlit()
|
||||
<< "isTranslucent:" << key.isTranslucent()
|
||||
<< "isSkinned:" << key.isSkinned()
|
||||
<< "isStereo:" << key.isStereo()
|
||||
|
|
Loading…
Reference in a new issue